I have 4 mipi cameras connected to jetson board. I can stream the cameras using gstreamer but i want to use opencv for further processing. I tried several code but i cant seem to get the strem from nvargus in opencv, this is the code ive tried
import cv2
import numpy as np
import time
print(cv2.__version__)
dispW = 1200
dispH = 700
flip=2
font = cv2.FONT_HERSHEY_SIMPLEX
dtav=0
camSet0='nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)500, height=(int)320, framerate=(fraction)30/1, format=(string)NV12 ! nvvidconv ! video/x-raw, width=(int)500, height=(int)320 '
cam1 = cv2.VideoCapture(camSet0)
camSet1='nvarguscamerasrc sensor-id=1 ! video/x-raw(memory:NVMM), width=(int)500, height=(int)320, framerate=(fraction)30/1, format=(string)NV12 ! nvvidconv ! video/x-raw, width=(int)500, height=(int)320 '
cam2 = cv2.VideoCapture(camSet1)
camSet2='nvarguscamerasrc sensor-id=2 ! video/x-raw(memory:NVMM), width=(int)500, height=(int)320, framerate=(fraction)30/1, format=(string)NV12 ! nvvidconv ! video/x-raw, width=(int)500, height=(int)320 '
cam3 = cv2.VideoCapture(camSet2)
camSet3='nvarguscamerasrc sensor-id=3 ! video/x-raw(memory:NVMM), width=(int)500, height=(int)320, framerate=(fraction)30/1, format=(string)NV12 ! nvvidconv ! video/x-raw, width=(int)500, height=(int)320 '
cam4 = cv2.VideoCapture(camSet3)
startTime=time.time()
while True:
ret, frame1 =cam1.read()
ret, frame2 = cam2.read()
ret, frame3 =cam3.read()
ret, frame4 = cam4.read()
# Ensure frames are not None before combining them
if frame1 is None or frame2 is None or frame3 is None or frame4 is None:
print("Error: One or more frames is None.")
break
framecombined = np.hstack((frame1, frame2, frame3, frame4))
# Check if framecombined is not empty
if framecombined.size == 0:
print("Error: Combined frame is empty.")
break
cv2.imshow('Combo', framecombined)
cv2.moveWindow('Combo', 0, 0)
if cv2.waitKey(1) == ord('q'):
break
cam1.release()
cam2.release()
cam3.release()
cam4.release()
cv2.destroyAllWindows()
the error is always that the frames are empty, i also tried just one camera and get the same error: File “panz1.py”, line 33, in
cv2.imshow(‘Combo’, frame1)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/highgui/src/window.cpp:971: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’
which means that its not getting any frames.
Please help.
1