我正在寻找,如果我可以运行Raspi和Lepton相机,同时在蟒蛇代码和OpenCV的jetson。我可以通过这个命令从终端运行两个摄像头。
gst-launch-1.0 nvarguscamerasrc sensor_mode=0 ! 'video/x-raw(memory:NVMM),width=3264, height=2464, framerate=21/1, format=NV12' ! nvvidconv flip-method=2 ! 'video/x-raw,width=800, height=600' ! videoconvert ! ximagesink & gst-launch-1.0 v4l2src device=/dev/video1 ! video/x-raw,format=UYVY ! videoscale ! video/x-raw,width=800,height=600 ! videoconvert ! ximagesink我正在寻找能否在这个python / opencv代码中实现上面的命令
import cv2
print(cv2.__version__)
dispW=640
dispH=480
flip=2
camSet='nvarguscamerasrc ! video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam= cv2.VideoCapture(camSet)
while True:
ret, frame = cam.read()
cv2.imshow('nanoCam',frame)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()发布于 2021-12-09 19:17:25
虽然我理解您的示例提供了一些灵活性,但以比处理所需的分辨率更高的分辨率捕获是没有什么意义的,而且可能会花费资源时间。
nvarguscamerasrc应该(在某种程度上)能够管理缩放。
假设你的FLIR相机可以达到30 fps,你可以尝试:
import cv2
print(cv2.__version__)
cam0= cv2.VideoCapture('nvarguscamerasrc ! video/x-raw(memory:NVMM), width=800, height=600, format=NV12, framerate=30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink drop=1', cv2.CAP_GSTREAMER)
if not cam0.isOpened():
print 'Failed to open cam0'
exit
cam1= cv2.VideoCapture('v4l2src device=/dev/video1 ! video/x-raw,format=UYVY,framerate=30/1 ! videoscale ! video/x-raw,width=800,height=600 ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1', cv2.CAP_GSTREAMER)
if not cam1.isOpened():
print 'Failed to open cam1'
exit
while True:
ret, frame0 = cam0.read()
ret, frame1 = cam1.read()
cv2.imshow('Cam0',frame0)
cv2.imshow('Cam1',frame1)
if cv2.waitKey(1)==ord('q'):
break
cam.release()
cv2.destroyAllWindows()编辑:不确定以下内容是否适用于USB摄像机
由于您的FLIR相机提供UYVY,您可以尝试使用nvv4l2camerasrc插件,而不是v4l2src。确保传感器处于UYVY模式,并尝试利用HW中的缩放和颜色转换:
cam1= cv2.VideoCapture('nvv4l2camerasrc device=/dev/video1 ! video/x-raw(memory:NVMM),format=UYVY,framerate=30/1 ! nvvidconv ! video/x-raw,format=BGRx,width=800,height=600 ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1', cv2.CAP_GSTREAMER)https://stackoverflow.com/questions/70267292
复制相似问题