Dev/video0 doesn't work for cv2.VideoCapture(0)

• Hardware Platform (Jetson / GPU) AGX Xavier
• DeepStream Version 5.0
• JetPack Version (valid for Jetson only) 4.2/4.4

I had four cameras installed. And it works fine if I using following gstreamer pipeline:

gst-launch-1.0 nvarguscamerasrc sensor-id=$1 !
“video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080” ! nvvideoconvert ! nvegltransform ! nveglglessink

where $1 could be 0,1,2,3

And I also

ls /dev/video*

and got:

/dev/video0 /dev/video1 /dev/video2 /dev/video3

But when I try to use the following opencv and python to open /dev/video0, the system got stuck at ret, frame = cap.read() and no video show up:

    import cv2
    cap=cv2.VideoCapture(0)
    if not (cap.isOpened()):
    	print "Could not open video device"

    #To set the resolution
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

    while(True):
    	# Capture frame-by-frame
    	ret, frame = cap.read()
    	# Display the resulting frame
    	cv2.imshow('preview',frame)
    	#Waits for a user input to quit the application
    	if cv2.waitKey(1) & 0xFF == ord('q'):
    		break

I did check the /dev/vidoe0 format by:

v4l2-ctl -d /dev/video0 --list-formats-ext

and it reports:

ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'GB10'
	Name        : 10-bit Bayer GBGB/RGRG
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1952x2364
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1952x2364
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1312x1478
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1312x1478
			Interval: Discrete 0.008s (120.000 fps)

	Index       : 1
	Type        : Video Capture
	Pixel Format: 'GB12'
	Name        : 12-bit Bayer GBGB/RGRG
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1952x2364
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1952x2364
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1312x1478
			Interval: Discrete 0.008s (120.000 fps)
		Size: Discrete 1312x1478
			Interval: Discrete 0.008s (120.000 fps)

So what should I do to get opencv/python code running to show /dev/video0 video in AGX Xavier? Thanks a lot for your help.

Hi,
You need to run a gstream pipeline in cv2.VideoCapture(). Please refer to

1 Like

@DaneLLL

It works!!! Thanks a lot!

2 Likes