Multiple camera with multiple thread in Python

I tried to display camera preview with OpenCV VideoCapture in Python.
Two cameras are connected and these are running with threads. (One VideoCapture and one thread)
When first camera is connected this display is going well.
As soon as second camera is connected, second display works well.
But, the first camera gets stuck.(read while loop stuck)
Could you advise for me?

Please verify by argus_camera you can select sensor by --device=

I use sensor_id=0 and sensor_id=1. I can get one frame from the first camera. But it got stuck after second camera was activated.

Please verify by v4l2-ctl to confirm the sensor driver.

v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video0
v4l2-ctl --stream-mmap -c byapss_mode=0 -d /dev/video1

It works like these.

$ v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video0
<<<<<<<<<<<<<<<< 14.65 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 22.82 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 25.60 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 27.03 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 27.87 fps
<^C
$ v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video1
<<<<<<<<<<<<<<<< 14.65 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 22.82 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 25.60 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 27.00 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 27.87 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 28.42 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 28.82 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 29.12 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 31.25 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 31.25 fps

Could you confirm below to confirm two cam working simultaneously,

v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video0&
v4l2-ctl --stream-mmap -c byapss_mode=0 -d /dev/video1&

Also boost the clocks to try.

echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee  /sys/kernel/debug/bpmp/debug/clk/isp/rate
cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate

I can confitm two cameras work well.

astre@orin-1:~$ v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video0&
[1] 2877
astre@orin-1:~$ v4l2-ctl --stream-mmap -c bypass_mode=0 -d /dev/video1&<<<<<
[2] 2880
astre@orin-1:~$ <<<<<<<<<<<< 15.63 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 23.31 fps
<<<<<<<<<<< 14.65 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 25.93 fps
<<<<<<<<<<< 22.82 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 27.28 fps
<<<<<<<<< 25.60 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 28.07 fps
<<<<<<<<< 27.00 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 28.59 fps
<<<<<<<<<<< 27.87 fps
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<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<<<<<< 31.25 fps
<<<<<<<<< 31.25 fps

I got the followings.

astre@orin-1:~$ echo 1 > sudo /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
astre@orin-1:~$ echo 1 > sudo /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
astre@orin-1:~$ echo 1 > sudo /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
astre@orin-1:~$ echo 1 > sudo /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
astre@orin-1:~$ sudo cat sudo /sys/kernel/debug/bpmp/debug/clk/vi/max_rate | sudo tee sudo /sys/kernel/debug/bpmp/debug/clk/vi/rate
1 /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
832000000
astre@orin-1:~$ sudo cat sudo /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | sudo tee sudo /sys/kernel/debug/bpmp/debug/clk/isp/rate
1 /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
832000000
1011200000
astre@orin-1:~$ sudo cat sudo /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | sudo tee sudo /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
1 /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
832000000
1011200000
642900000
astre@orin-1:~$ sudo cat sudo /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | sudo tee sudo /sys/kernel/debug/bpm
tee: /sys/kernel/debug/bpm: Permission denied
1 /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
832000000
1011200000
642900000
3199000000

Try below command to boost the clocks.

sudo su

echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee  /sys/kernel/debug/bpmp/debug/clk/isp/rate
cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate

echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/isp/rate
cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate
root@orin-1:/home/astre#
root@orin-1:/home/astre# echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
root@orin-1:/home/astre# echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
root@orin-1:/home/astre# echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
root@orin-1:/home/astre# echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
root@orin-1:/home/astre# cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
832000000
root@orin-1:/home/astre# cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/isp/rate
1011200000
root@orin-1:/home/astre# cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
642900000
root@orin-1:/home/astre# cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate
3199000000

After that command to boost the clocks, you can try the cameras.

After that, the first camera does not work and the second one works well.
When I try to display with nvarguscamerasrc, two cameras work well without boost.

root@orin-1:/home/astre/work/Diagnosis# python Diagnosis.py
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to ‘/tmp/runtime-root’
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1536 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.122018, max 6.309574; Exposure Range min 16000, max 660000000;

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 0
Output Stream W = 1920 H = 1536
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
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, threadExecute:694 NvBufSurfaceFromFd Failed.
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, threadFunction:247 (propagating)
[ WARN:0] global /home/ubuntu/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (1100) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 1920 x 1536 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.122018, max 6.309574; Exposure Range min 16000, max 660000000;

GST_ARGUS: Running with following settings:
Camera index = 1
Camera mode = 0
Output Stream W = 1920 H = 1536
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.
[ WARN:0] global /home/ubuntu/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (1100) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

Could you try MMAPI sample argus_camera.

Multi-session of “argus_camera” works well.

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