jetson上使用opencv的gstreamer进行MIPI和USB摄像头的连接以及udp推流
文章目录
- 1. 连接MIPI相机(IMX219-A(接到CSI0) )
-
- 1.1 使用nvgstcapture-1.0
- 1.2 gst命令行连接
- 1.3 在opencv中使用VideoCapture连接
- 1.4 直接udp推流
- 2. 连接USB相机
-
- 2.1 gst命令行连接
- 2.2 在opencv中使用VideoCapture连接
- 2.3 直接udp推流
- 3. 使用opencv对处理完成的图像使用VideoWriter进行UDP推流
- 4. 推流结果查看
-
- 4.1 gst命令行连接
-
- 4.1.1 jetson设备
- 4.1.2 非jetson设备:
- 4.2 在opencv中使用VideoCapture获取推流结果
-
- 4.2.1 jetson设备
- 4.2.2 非 jetson设备
- 5. 所有源码
1. 连接MIPI相机(IMX219-A(接到CSI0) )
1.1 使用nvgstcapture-1.0
使用nvgstcapture-1.0可以直接打开相机。
1.2 gst命令行连接
用于复制:
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1'! nvvidconv ! autovideosink sync=false
用于查看:
gst-launch-1.0 \
nvarguscamerasrc sensor-id=0 ! \
'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1'! \
nvvidconv ! \
autovideosink sync=false
1.3 在opencv中使用VideoCapture连接
opencv需要带gstreamer编译。
std::string pipeline = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1 ! nvvidconv ! video/x-raw,format=BGRx ! appsink drop=true";
cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
这个获取到的是4通道图像,如果要进一步转为3通道,使用如下:
std::string pipeline = "nvarguscamerasrc sensor-id=0 ! video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=true";
1.4 直接udp推流
用于复制:
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1' ! nvvidconv ! video/x-raw,format=I420 ! x264enc tune=zerolatency bitrate=5000 speed-preset=superfast ! rtph264pay config-interval=1 pt=96 ! udpsink host=192.168.1.135 port=5000 sync=false
用于查看:
gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! \
'video/x-raw(memory:NVMM),format=NV12,width=1280,height=720,framerate=30/1' ! \