0

I'm trying to open 3 cameras at the same time on a Jetson Nano 2GB with python 3.6.9 and opencv 4.5.4

import cv2

Camera1 = cv2.VideoCapture(0)
Camera2 = cv2.VideoCapture(1)
Camera3 = cv2.VideoCapture(2)

Largeur = 640
Hauteur = 480
Camera1.set(3, Largeur)
Camera1.set(4, Hauteur)
Camera2.set(3, Largeur)
Camera2.set(4, Hauteur)
Camera3.set(3, Largeur)
Camera3.set(4, Hauteur)

while True:
  ret1, IMG1 = Camera1.read()
  ret2, IMG2 = Camera2.read()
  ret3, IMG3 = Camera3.read()

  cv2.imshow("Webcam1", IMG1)
  cv2.imshow("Webcam2", IMG2)
  cv2.imshow("Webcam3", IMG3)

  if cv2.waitKey(1) % 0xFF == ord("q"):
    break
  
Camera1.release()
Camera2.release()
Camera3.release()
cv2.destroyAllWindows()

But, if I try to open the 3 at the same time i get this error:

GStreamer warning: Embedded video playback halted; module v4l2src2 reported: Failed to 
allocate required memory
    cv2.imshow("Webcam3", IMG3)
cv2.error: OpenCV(4.5.4) error: (-206:Bad flag (parameter or structure field)) 
Unrecognized or unsupported array type in function 'cvGetMat'

I'm able to use all 3 cameras by group of 2 at the time but not the 3. I think it's because of the low 2GB of ram, but i want to have someone else opinion before doing anything.

P.S. all the cameras are Logitech C925e

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Vi Peeters
  • 21
  • 4
  • you gotta check `if not ret1 or not ret2 or not ret3: break` and before the loop you gotta `assert Camera1.isOpened()` etc -- perhaps use `CAP_PROP_FRAME_WIDTH` instead of those magic numbers – Christoph Rackwitz Mar 11 '22 at 17:05
  • Try checking if camera 3 (with nothing else) works. Also, please post the output of `ls -al /dev/video*` – zurgeg Mar 11 '22 at 17:34
  • After trying things, I found out it's only the last Camera called who can't be opened EX: if i call cam1 then cam2 then cam3, cam3 won't opened, but if i call cam3 cam2 and cam1 then it's cam1 who won't opened – Vi Peeters Mar 11 '22 at 21:32
  • I have no experience with C925e cameras, so you may post the available modes from `v4l2-ctl -d0 --list-formats-ext` for better advice. Are you using these in RAW mode or encoded such as MJPG or H264 ? Be sure with `lsusb -t` that they are connected as USB3. Be aware that USB3 ports are sharing a single USB3 link in Nano. Furthermore with MJPG and USB2 there may be a uvc driver issue (for this case you may try https://developer.ridgerun.com/wiki/index.php?title=Birds_Eye_View/Getting_the_Code/Building_and_Installation_Guide#Patch_to_support_4_USB_cameras) – SeB Mar 12 '22 at 00:50

0 Answers0