I am using a Logitech C920S webcam with my Jetson Nano. Getting errors using the latest (2019/12/17) SD card image. The errors do NOT occur using the 2019/07/19 SD card image.
Simple source program. (Based on a program in the “AI on the Jetson Nano” youtube series at toptechboy.com.)
import cv2
print(cv2.__version__)
dispW=640
dispH=480
flip=2
cam=cv2.VideoCapture(0)
width=cam.get(cv2.CAP_PROP_FRAME_WIDTH)
height=cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
print("size:",width,height) # opencv 4.1.1 displays 2304.0 1536.0
cam.set(cv2.CAP_PROP_FRAME_WIDTH, dispW)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, dispH)
width=cam.get(cv2.CAP_PROP_FRAME_WIDTH)
height=cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
print("size:",width,height) # same as above; however, does change in the loop
d=cam.get(cv2.CAP_PROP_FPS)
print("frame rate",d) # opencv 4.1.1 displays 2.0
firstIterations=1
while True:
ret, frame=cam.read()
if firstIterations<=2:
firstIterations=firstIterations+1
width=cam.get(cv2.CAP_PROP_FRAME_WIDTH)
height=cam.get(cv2.CAP_PROP_FRAME_HEIGHT)
print("size:",width,height) # opencv 4.1.1 displays 640.0 480.0
print("frame rate",cam.get(cv2.CAP_PROP_FPS)) # opencv 4.1.1 displays 2.0
cv2.imshow('webCam',frame)
cv2.moveWindow('webCam',0,0)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
Output from the program follows for both SD cards. Comments continue below the output.
SD card 2019/07/19 output.
john@jetsonnano:~/pyProg/openCV$ python3 openCVbase.py
3.3.1
size: 640.0 480.0
size: 640.0 480.0
frame rate 30.0
size: 640.0 480.0
frame rate 30.0
size: 640.0 480.0
frame rate 30.0
john@jetsonnano:~/pyProg/openCV$
SD card 2019/12/17 output.
john@jetsonnano:~/pyProg/openCV$ python3 openCVbase.py
4.1.1
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
size: 2304.0 1536.0
size: 2304.0 1536.0
frame rate 2.0
size: 640.0 480.0
frame rate 2.0
size: 640.0 480.0
frame rate 2.0
john@jetsonnano:~/pyProg/openCV$
Comments about the program.
- The program displays a window at the upper left corner. Size: 640 x 480.
- The first three print statements show the initial width and height of the frame and the frame rate before the loop. The width and height are shown twice – once before setting the values and once after setting the values. (Setting the values was added for a reason. Continue reading to see why.)
- The three values are printed within the loop two more times.
- The program is gracefully ended by pressing the “q” key.
Comments about the output produced by the program.
- The 2019/07/19 print output shows that the initial frame width and height are 640.0 and 480.0, respectively; the initial frame rate is 30.0. No error messages appear in the output. The displayed window behaves correctly.
- The 2019/12/17 output contains a warning message (issued by gstreamer?). The print output shows that the initial frame width and height are 2304.0 and 1536.0, respectively; the initial frame rate is 2.0. The print statements executed within the loop show that the frame width and height were changed to 640.0 and 480.0, respectively.
2.1. Because of these initial values, without the “cv2.set” statements, the displayed window fills the screen.
2.2. The 2.0 value for the frame rate is obviously incorrect.
2.3. The displayed frame does appear to work correctly, even with these errors, although one should not have to explicitly set the frame size; the frame rate value is certainly suspect.
Summary.
- The 2019/07/19 SD card image, which uses OpenCV 3.3.1, works correctly. Good initial values for the frame width and height, good value for the frame rate. No errors displayed. Setting the frame width and height is not necessary.
- The 2019/12/17 SD card image, which uses OpenCV 4.1.1, does not work correctly. A warning message appears, followed by invalid values for the frame width, height and frame rate. In order to get a displayed frame having size 640 x 480 it is necessary to explicitly set the size.