import cv2 # GStreamer pipeline to read from CSI camera pipeline = ( "nvarguscamerasrc ! " "video/x-raw(memory:NVMM), width=1280, height=720, format=NV12, framerate=30/1 ! " "nvvidconv flip-method=2 ! " "video/x-raw, width=1280, height=720, format=BGRx ! " "videoconvert ! " "video/x-raw, format=BGR ! appsink" ) cap = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER) if not cap.isOpened(): print("Failed to open camera") exit() while True: ret, frame = cap.read() if not ret: print("Failed to capture image") break cv2.imshow("CSI Camera", frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()