summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-05-05 15:59:56 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-05-05 15:59:56 +0530
commitf2d823d4693e6fba30a339a11996ab5fbc6c56d0 (patch)
tree8c8aa86500b1d944749a421753a87aba2725db0b
parente26c29facfc79725532205938520837d324f4ce2 (diff)
CamTest: Adding comments+q to exit window
-rw-r--r--CamTest.py22
-rw-r--r--README.md2
2 files changed, 18 insertions, 6 deletions
diff --git a/CamTest.py b/CamTest.py
index 0a3fdaf..3b197e5 100644
--- a/CamTest.py
+++ b/CamTest.py
@@ -1,17 +1,29 @@
import cv2
+# Setting the video capture source to default (0)
cap = cv2.VideoCapture(0)
-cap.set(3,640) # set Width
-cap.set(4,480) # set Height
+# Setting the resolution of the video capture
+cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
+cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
+
+# 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
+ # Convert frame from BGR to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- cv2.imshow('frame', frame)
- cv2.imshow('gray', gray)
+ # Display the original frame and grayscale frame
+ cv2.imshow('OriginalBGR', frame)
+ cv2.imshow('Grayscale', gray)
+ # Wait for 30 milliseconds for a key event (extract sigfigs) and exit if 'ESC' or 'q' is pressed
k = cv2.waitKey(30) & 0xff
- if k == 27: # press 'ESC' to quit
+ if key == 27: # ESCAPE key
break
+ elif key == 113 # q key
+ break
+
+# Release the camera and close all windows
cap.release()
cv2.destroyAllWindows()
diff --git a/README.md b/README.md
index 772d577..bc238b8 100644
--- a/README.md
+++ b/README.md
@@ -117,7 +117,7 @@ libcamera-jpeg -o ~/Desktop/test.jpg
```
The command **libcamera-jpeg** will capture a still image using the camera module and save it to a specified location as a JPEG file.
-<img src="media/test.jpg" alt="Test image of capy" width="450" height="337.5">
+<img src="media/test.jpg" alt="Test image of capy" width="300" height="225">
**Test image taken by Raspberry Pi Camera Module**