jetson上使用opencv的gstreamer进行MIPI和USB摄像头的连接以及udp推流

发布于:2025-08-08 ⋅ 阅读:(11) ⋅ 点赞:(0)

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' ! \

网站公告

今日签到

点亮在社区的每一天
去签到