From 67201b046b3febb1ec0d5dd732eda0126ee51eaa Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Sun, 7 May 2023 16:03:11 +0530 Subject: CamTest: Update camtest to use PiCamera for newer 64-bit OS release and latest camera-stack --- CamTest.py | 17 ++++++++------- README.md | 71 ++++++++++++++++++++++++++++++++------------------------------ 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/CamTest.py b/CamTest.py index 8544116..01d159c 100644 --- a/CamTest.py +++ b/CamTest.py @@ -1,17 +1,20 @@ import cv2 - +from picamera2 import Picamera2 # Setting the video capture source to default (0) -cap = cv2.VideoCapture(0) +cam = Picamera2() # Setting the resolution of the video capture -cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) -cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480) +cam.preview_configuration.main.size = (1280,720) +cam.preview_configuration.main.format = "RGB888" +cam.preview_configuration.align() +cam.configure("preview") +cam.start() # While loop to continuously capture frames from camera while True: # Read a frame from the camera - ret, frame = cap.read() - #frame = cv2.flip(frame, -1) # Flip camera vertically + frame=cam.capture_array() + # Convert frame from BGR to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) @@ -27,5 +30,5 @@ while True: break # Release the camera and close all windows -cap.release() +cam.release() cv2.destroyAllWindows() diff --git a/README.md b/README.md index 85edbb0..c78f415 100644 --- a/README.md +++ b/README.md @@ -121,35 +121,7 @@ The command **libcamera-jpeg** will capture a still image using the camera modul **Test image taken by Raspberry Pi Camera Module** (Click on it for full-size) -## 5. Install dependencies and test the LCD1602 LCD Display with I2C - -1. Install the libraries and i2cctools package -```bash -sudo apt install i2c-tools libi2c-dev -``` -2. Enter the lcd-ipaddress-display subdirectory in this project -```bash -cd lcd-ipaddress-display -``` -3. Install python modules `smbus` and `RPi.GPIO` to communicate with I2C devices using python scripts -```bash -pip install smbus RPi.GPIO -``` -OR -```bash -pip install -r requirements.txt -``` -4. Execute the python script to display Local IP Address: -```bash -python dispip.py -``` -**Note:** The python script will only work correctly when it is located in the lcd-ipaddress-display directory, as the drivers directory is imported in the code as a library. - -Test image of LCD display showing the Local IP Address - -**Test image of LCD display in the setup showing the Local IP Address** - -## 6. Testing the Face-Recognition Application +## 5. Testing the Face-Recognition Application To test the camera for the application, follow these steps: @@ -179,7 +151,11 @@ source .venv/bin/activate ``` bash pip install -r requirements.txt ``` - +*Note!* Picamera2 is recommended to install using apt. Hence, till it's stable version is not released it won't be included in requirements.txt. Read more [here](https://pypi.org/project/picamera2/) +Use the following command to install Picamera2 +``` bash +sudo apt install -y python3-picamera2 +``` 6. Change to the parent directory of opencv-face-recognition. ``` bash cd .. @@ -187,13 +163,40 @@ cd .. 7. Run the "CamTest.py" script. ``` bash -python opencv-face-recognition/CamTest.py +python CamTest.py +``` +Once the script starts running, it will use the Camera Module to show the captured frames. + +8. Press 'Esc' or 'q' to quit the script. +Press Escape key or qto stop the script when you are done. + +## 6. Install dependencies and test the LCD1602 LCD Display with I2C + +1. Install the libraries and i2cctools package +```bash +sudo apt install i2c-tools libi2c-dev +``` +2. Enter the lcd-ipaddress-display subdirectory in this project +```bash +cd lcd-ipaddress-display +``` +3. Install python modules `smbus` and `RPi.GPIO` to communicate with I2C devices using python scripts +```bash +pip install smbus RPi.GPIO +``` +OR +```bash +pip install -r requirements.txt ``` -Once the script starts running, it will use your webcam to detect faces in the video feed. +4. Execute the python script to display Local IP Address: +```bash +python dispip.py +``` +**Note:** The python script will only work correctly when it is located in the lcd-ipaddress-display directory, as the drivers directory is imported in the code as a library. -8. Press 'Esc' to quit the script. -Press Escape key to stop the script when you are done. +Test image of LCD display showing the Local IP Address +**Test image of LCD display in the setup showing the Local IP Address** ## Wireless Adapter -- cgit v1.2.3