UVC & Mono Camera
cv2.VideoCapture(), native camera apps, and more.How It Works:
Similar samples:
Setup
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.pyCode used for testing
Python
1import cv2
2
3# Initialize the VideoCapture object to use the default camera (camera index 0 is webcam)
4cap = cv2.VideoCapture(1)
5
6# Check if the camera opened successfully
7if not cap.isOpened():
8 print("Error: Could not open camera.")
9 exit()
10
11# Loop to continuously get frames from the camera
12while True:
13 ret, frame = cap.read()
14
15 if not ret:
16 print("Error: Could not read frame.")
17 break
18
19 cv2.imshow('Video Feed', frame)
20
21 if cv2.waitKey(1) & 0xFF == ord('q'):
22 break
23
24cap.release()
25cv2.destroyAllWindows()Source code
Python
Python
PythonGitHub
1#!/usr/bin/env python3
2
3import time
4
5import depthai as dai
6
7pipeline = dai.Pipeline()
8
9# Define a source - left mono (grayscale) camera
10mono_left = pipeline.createMonoCamera()
11
12mono_left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
13mono_left.setBoardSocket(dai.CameraBoardSocket.CAM_B)
14
15# Create an UVC (USB Video Class) output node
16uvc = pipeline.createUVC()
17
18# Manip for frame type conversion
19manip = pipeline.createImageManip()
20manip.initialConfig.setResize(1280, 720)
21manip.initialConfig.setFrameType(dai.RawImgFrame.Type.NV12)
22manip.setMaxOutputFrameSize(int(1280*720*1.5))
23
24# Linking
25manip.out.link(uvc.input)
26mono_left.out.link(manip.inputImage)
27
28# Note: if the pipeline is sent later to device (using startPipeline()),
29# it is important to pass the device config separately when creating the device
30config = dai.Device.Config()
31config.board.uvc = dai.BoardConfig.UVC(1280, 720)
32config.board.uvc.frameType = dai.ImgFrame.Type.NV12
33# config.board.uvc.cameraName = "My Custom Cam"
34pipeline.setBoardConfig(config.board)
35
36
37# Standard UVC load with depthai
38with dai.Device(pipeline) as device:
39 # Dot projector
40 device.setIrLaserDotProjectorBrightness(765)
41 print("\nDevice started, please keep this process running")
42 print("and open an UVC viewer to check the camera stream.")
43 print("\nTo close: Ctrl+C")
44
45 # Doing nothing here, just keeping the host feeding the watchdog
46 while True:
47 try:
48 time.sleep(0.1)
49 except KeyboardInterrupt:
50 breakPipeline
Need assistance?
Head over to Discussion Forum for technical support or any other questions you might have.