Reputation: 1
The CSI camera works in the terminal, but it doesn’t work with Python in Visual Studio. I’m using a Jetson Orin Nano. The camera works when I run the following command in the terminal:
gst-launch-1.0 nvarguscamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1' ! nvvidconv ! nvegltransform ! nveglglessink -e
However, the camera does not work in the following Python script:
import cv2
cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=1280, height=720, framerate=30/1 ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink")
while True:
ret, frame = cap.read()
if not ret:
print("Unable to capture camera image")
break
cv2.imshow("CSI Camera", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I receive the following output when I run the script:
onur@ubuntu:~/Desktop/Project$ /bin/python /home/onur/Desktop/Project/simple_camera.py
nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)960, height=(int)540, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
Error: Unable to open camera
Upon researching, I was advised to run the following code:
import cv2
print(cv2.getBuildInformation())
In the output, I saw:
Video I/O:
DC1394: NO
FFMPEG: YES
avcodec: YES (59.37.100)
avformat: YES (59.27.100)
avutil: YES (57.28.100)
swscale: YES (6.7.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)
It seems that the GStreamer: NO
line indicates a problem. How can I solve this?
Upvotes: 0
Views: 236
Reputation: 1
You have to build opencv with gstreamer enabled.
https://qengineering.eu/install-opencv-on-orin-nano.html follow this one and read script there's lots of options to select(like cuda, cudnn something like this)
Upvotes: 0