I am trying to use a Raspberry Pi Camera, v2.1 with my Jetson Nano and I’ve had some success, but it’s limited.
What I’ve done which has worked:
- Follow instructions on setting up the Jetson Nano.
- Run this script, replacing version with “4.6.0” to get a CUDA-enabled, updated version of OpenCV.
- Power off, plug in Raspberry Pi Camera v2.1, and power back on.
- Capture a video to confirm functionality:
nvgstcapture-1.0 --mode=2 --automate --capture-auto
- Make a C++ Project to test everything so far.
A. MakeCMakeLists.txt
which creates an executable based onmain.cpp
, and targets OpenCV.
B. Makemain.cpp
which contains this example code for Background Subtraction mkdir build && cd build && cmake .. && make
- Run built executable, providing it
--input=../video.mp4
wherevideo.mp4
is the output from step 2.
Success! The Background Subtraction worked and I was able to watch both panes created by imshow
. Next, I wanted to use the live camera feed.
At first I tried the change below:
--VideoCapture capture( samples::findFile( parser.get<String>("input") ) );
++VideoCapture capture(0);
This resulted in a solid green frame which also ran incredibly slow.
After reading this forum post, I tried changing the line to:
VideoCapture capture("nvarguscamerasrc ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink", CAP_GSTREAMER);
As I was writing this forum post, I ran the code as stated above so I could copy the error and paste it here. However, it worked… Once. I closed the executable and re-ran it and it didn’t work the second time. Eventually I rebooted and here’s the current state:
After a fresh reboot, I can run nvgstcapture-1.0 --mode=2 --automate --capture-auto
as many times as I want, and I will get a successful recording. But if I run the executable which has identical source code to that linked in Step 5B, except for the line of code that now reads VideoCapture capture("nvarguscamerasrc ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink", CAP_GSTREAMER);
, I get the following output:
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1640 x 1232 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 2
Output Stream W = 1920 H = 1080
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
nvbuf_utils: dmabuf_fd -1 mapped entry NOT found
nvbuf_utils: Can not get HW buffer from FD... Exiting...
CONSUMER: ERROR OCCURRED
[ WARN:0@4.217] global /home/codydg/opencv/workspace/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (2402) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module nvarguscamerasrc0 reported: CANCELLED
GST_ARGUS: Cleaning up
(Argus) Error Timeout: (propagating from src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 137)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 91)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 137)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 91)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 137)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 91)
[ WARN:0@124.921] global /home/codydg/opencv/workspace/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@124.922] global /home/codydg/opencv/workspace/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Unable to open camera!
(Argus) Error Timeout: (propagating from src/rpc/socket/client/ClientSocketManager.cpp, function send(), line 137)
(Argus) Error Timeout: (propagating from src/rpc/socket/client/SocketClientDispatch.cpp, function dispatch(), line 91)
(Argus) Error InvalidState: Argus client is exiting with 4 outstanding client threads (in src/rpc/socket/client/ClientSocketManager.cpp, function recvThreadCore(), line 357)
Note that there is a significant amount of time after it says “Cleaning up” where I was simply waiting for output. From then, if I keep running it, I get the following output:
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:751 Failed to create CaptureSession
[ WARN:0@0.890] global /home/codydg/opencv/workspace/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (1405) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
And any attempt to run will now result in the following output:
Encoder null, cannot set bitrate!
Encoder Profile = High
bitrate = 4000000
Encoder Profile = High
Encoder control-rate = 1
Encoder EnableTwopassCBR = 0
Opening in BLOCKING MODE
** Message: 19:39:13.727: <main:4674> iterating capture loop ....
NvMMLiteOpen : Block : BlockType = 4
===== NVMEDIA: NVENC =====
NvMMLiteBlockCreate : Block : BlockType = 4
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:751 Failed to create CaptureSession
It will still generate an MP4 file, but all programs just say the MP4 is corrupted.
I’m very confused about this. I especially don’t understand why attempting to run the executable results in the camera being seemingly inoperable until I reboot again!