Welcome to Jetson Orin NX Developer Kit repository
当製品の日本語版マニュアル資料は、こちらからご取得ください。
17.Preview USB camera image
Preview USB camera image
1. Implementation principle
Use the cv2.VideoCapture() function to capture video frames from a USB camera or a video file.
2. Implementation effect
xxxxxxxxxxcd ~/opencv
xxxxxxxxxxpython3 17.camera_preview_usb.py # The program opens video0 by default; modify the device number yourself to open another camera
Note: Select the camera image and press q to exit the program!

3. Implementation code
ximport cv2def preview_usb_camera():cap = cv2.VideoCapture(0)cap.set(6, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)if not cap.isOpened():print("Error: Could not open USB camera.")returnwhile True:ret, frame = cap.read()if not ret:breakcv2.imshow('USB Camera Preview', cv2.resize(frame, (640, 480)))if cv2.waitKey(1) & 0xFF == ord('q'):breakcap.release()cv2.destroyAllWindows()preview_usb_camera()