1 |
pip install opencv-python==4.6.0.66 |
Then the following code will allow you to grab a frame and show a frame in a window. Looking this sequence creates a live video preview on your Raspberry Pi Screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import cv2 from picamera2 import Picamera2 picam2 = Picamera2() picam2.preview_configuration.main.size = (1280,720) picam2.preview_configuration.main.format = "RGB888" picam2.preview_configuration.align() picam2.configure("preview") picam2.start() while True: im= picam2.capture_array() cv2.imshow("Camera", im) if cv2.waitKey(1)==ord('q'): break cv2.destroyAllWindows() |