C++ OpenCV读取mipi摄像头图像数据

环境:Linux + OpenCV

OpenCV必须是支持有Gstreamer支持的,没有的话需要重新编译,添加WITH_GSTREAMER参数进行编译
可以在程序中通过 cout<<cv::getBuildInformation()<<endl;输出OpenCV信息查看是否支持Gstreamer

1、查看设备信息

  • 列出所有设备(接口)v4l2-ctl --list-devices
  • 查看某一个设备的具体信息,数据接口格式 v4l2-ctl -d /dev/video0 -all
Driver Info:
	Driver name      : rkcif
	Card type        : rkcif
	Bus info         : platform:rkcif-mipi-lvds2
	Driver version   : 5.10.110
	Capabilities     : 0x84201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps      : 0x04201000
		Video Capture Multiplanar
		Streaming
		Extended Pix Format
Media Driver Info:
	Driver name      : rkcif
	Model            : rkcif-mipi-lvds2
	Serial           : 
	Bus info         : 
	Media version    : 5.10.110
	Hardware revision: 0x00000000 (0)
	Driver version   : 5.10.110
Interface Info:
	ID               : 0x03000002
	Type             : V4L Video
Entity Info:
	ID               : 0x00000001 (1)
	Name             : stream_cif_mipi_id0
	Function         : V4L2 I/O
	Pad 0x01000004   : 0: Sink
...
Priority: 2
Format Video Capture Multiplanar:
	Width/Height      : 1920/1080  # 后续读取摄像头的时候用的上
	Pixel Format      : 'NV12' (Y/CbCr 4:2:0) # 后续读取摄像头的时候用的上
	Field             : None
	Number of planes  : 1
	Flags             : 
	Colorspace        : Rec. 709
	Transfer Function : Rec. 709
	YCbCr/HSV Encoding: Rec. 709
	Quantization      : Default
	Plane 0           :
	   Bytes per Line : 1920
	   Size Image     : 3110400
Selection Video Capture: crop, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Selection Video Capture: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Selection Video Output: crop, Left 0, Top 0, Width 1920, Height 1080, Flags: 
Selection Video Output: crop_bounds, Left 0, Top 0, Width 1920, Height 1080, Flags: 

2、读图
普通读取视频文件的OpenCV代码

cv::VideoCapture cap;
cap.open("xxx.mp4");

Mat frame;
while(cap.read(frame))
{
	//处理图像 frame
}
cap.release();

通过Gstreamer读取mipi摄像头时需要改open里的参数如下:
其中摄像头的参数需要自己根据摄像头参数修改(设备信息中看到的format等等)

cv::VideoCapture cap;
cap.open("v4l2src device=/dev/video0 ! video/x-raw, format=NV12, width=640, height=480, framerate=30/1 ! videoconvert ! appsink",cv::CAP_GSTREAMER);

在系统终端中调用摄像头看图像可以直接使用下面的命令:
gst-launch-1.0 v4l2src device=/dev/video0 io-mode=4 ! queue ! video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1 ! glimagesink
也可以预先测试gstreamer和摄像头是否正常运行,不过在代码中需要使用cpp代码中给出的形式

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值