I have a simple demo to show the disparity map, using a Jetson Nano 4GB B01:
import numpy as np
import cv2
left_camera = cv2.VideoCapture("nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM), width=(int)1024, height=(int)768,format=(string)NV12, framerate=(fraction)20/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
right_camera = cv2.VideoCapture("nvarguscamerasrc sensor-id=1 ! video/x-raw(memory:NVMM), width=(int)1024, height=(int)768,format=(string)NV12, framerate=(fraction)20/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
stereo = cv2.StereoBM_create(numDisparities=80, blockSize=25)
while(True):
ret, left_frame = left_camera.read()
ret, right_frame = right_camera.read()
left_frame = cv2.cvtColor(left_frame, cv2.COLOR_BGR2GRAY)
right_frame = cv2.cvtColor(right_frame, cv2.COLOR_BGR2GRAY)
disparity = stereo.compute(left_frame, right_frame)
disparity = cv2.normalize(disparity, None, 0, 255, cv2.NORM_MINMAX, cv2.CV_8U)
cv2.imshow('disparity', disparity)
cv2.imshow('left', left_frame)
cv2.imshow('right', right_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
right_camera.release()
left_camera.release()
cv2.destroyAllWindows()
It works until I exit (Keyboard q), when it gives a segmentation fault. Here is the end of the log + stack trace:
GST_ARGUS: Cleaning up
[Thread 0x7f90ff91f0 (LWP 22846) exited]
[Thread 0x7f737fe1f0 (LWP 22848) exited]
Thread 14 "argus_thread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f73fff1f0 (LWP 22847)]
0x0000007faeb34508 in ?? () from /usr/lib/aarch64-linux-gnu/tegra/libnvargus_socketclient.so
(gdb) bt
#0 0x0000007faeb34508 in () at /usr/lib/aarch64-linux-gnu/tegra/libnvargus_socketclient.so
#1 0x0000007faebb64a0 in () at /usr/lib/aarch64-linux-gnu/tegra/libnvargus_socketclient.so
#2 0x0000007fb2e887f0 in () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvarguscamerasrc.so
#3 0x0000007fb2e883d4 in () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvarguscamerasrc.so
#4 0x0000007fb2e88570 in () at /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvarguscamerasrc.so
#5 0x0000007fb7e17088 in start_thread (arg=0x7f917f97bf) at pthread_create.c:463
#6 0x0000007fb7f0bffc in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78
I am using the following Waveshare stereo camera: https://www.waveshare.com/wiki/IMX219-83_Stereo_Camera
I am using JetPack SDK version 4.5.
cat /etc/nv_tegra_release
# R32 (release), REVISION: 5.0, GCID: 25531747, BOARD: t210ref, EABI: aarch64, DATE: Fri Jan 15 22:55:35 UTC 2021