Created
November 16, 2025 17:18
-
-
Save maxpromer/3cdf718647b16d0dfc009ffa1f15add6 to your computer and use it in GitHub Desktop.
Raspberry Pi Camera Module 3 image preview with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from picamera2 import Picamera2 | |
| import cv2 | |
| # Initialize the camera | |
| picam2 = Picamera2() | |
| picam2.start() | |
| try: | |
| while True: | |
| # Capture frame from the camera | |
| frame = picam2.capture_array() | |
| # Convert color from RGB to BGR for OpenCV | |
| frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) | |
| # Display the frame | |
| cv2.imshow("Camera Feed", frame) | |
| # Press 'q' to exit | |
| if cv2.waitKey(1) & 0xFF == ord('q'): | |
| break | |
| finally: | |
| # Close all OpenCV windows | |
| cv2.destroyAllWindows() | |
| # Stop the camera | |
| picam2.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment