OpenCV videostream doesn't work with imx219 on Jetson Nano

Hi,
I want to use an ArduCam Camarray Hat with four imx219 Cameras with a Jetson Nano. Because I want to “analyze” the video-stream and run some code for object detection and stuff like that, I tried to get the video-stream with OpenCV (I installed it via “sudo apt install python3-opencv”).
First, I tested the cameras with “nvgstcapture-1.0” and it ran without problems.
“gst-launch-1.0 nvarguscamerasrc ! ‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1’ ! nvoverlaysink” runs without problems too, but the code: OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL says, “camera open failed”. Then I found this Python-code for OpenCV:

import cv2

cap = cv2.VideoCapture(0)

if (cap.isOpened()== False): 
  print("Error opening video stream or file")

while(cap.isOpened()):
  ret, frame = cap.read()
  if ret == True:

    cv2.imshow('Frame',frame)

    if cv2.waitKey(25) & 0xFF == ord('q'):
      break

  else: 
    break

cap.release()

cv2.destroyAllWindows()

But I get this Error:

select timeout
select timeout
OpenCV Error: Assertion failed (total() == 0 || data != NULL) in Mat, file /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/core/include/opencv2/core/mat.inl.hpp, line 431
Traceback (most recent call last):
  File "/home/konrad/Documents/Folder/Cameratest2.py", line 15, in <module>
    ret, frame = cap.read()
cv2.error: /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/core/include/opencv2/core/mat.inl.hpp:431: error: (-215) total() == 0 || data != NULL in function Mat

Because I thought the Camarray Hat may cause the issue, I tried the same code with a Raspberry Pi v2.1 imx219 camera. With it, I don’t get the error, but the output is just green (what is maybe the standard output of gstreamer).
Do you know how I can solve my problem?
Thanks in advance, Konrad

Hi,
You would need to run a gstreamer pipeline in cv2.VideoCapture() to use nvarguscamerasrc plugin. Please try this sample:
OpenCV Video Capture with GStreamer doesn't work on ROS-melodic - #3 by DaneLLL

Thank you for the fast response. I’ll try it tomorrow.
Konrad

Hi,
I tried it and it looks like OpenCV is causing the problem, because gst-launch runns but in the program something must go wrong at “cap = cv2.VideoCapture…”. So it can’t open the camera. But I think it’s a topic for the Opencv forum isn’t it?

Hi,
Seems like you don’t use the OpenCV 4.1.1 package installed through SDKManager. The log shows 3.2 and it probably doesn’t enable gstreamer. Please check if you can re-install the 4.1.1 one.

Hi,
thank you for your answer. I installed Opencv 4.5 and now your code works fine. I needed so long for the response because I had some problems with the installing.
Best regards,
Konrad

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.