驱动一款淘宝购买的130万像素的USB双目摄像头-记录

Joy ·
更新时间:2024-09-20
· 730 次阅读

文章目录巴拉巴拉一下1. 参数2. 使用3. 效果4. 需要注意的5. 其他参考 巴拉巴拉一下 前几天购买了一个USB双目相机如下,然后研究了一下怎么使用,简要记录一下自己的使用过程; 相机的链接如下:https://item.taobao.com/item.htm?spm=a1z09.2.0.0.76522e8dAWEjef&id=556150206198&_u=q2nok360f3af

在这里插入图片描述

1. 参数

0、购买的相机焦距f=6mm(定焦镜头,手动对焦);
1、双目相机基线距离:B=35mm-169mm
在这里插入图片描述
2、主要参数如下:像素尺寸3.75um;UVC协议摄像头(免驱);图像压缩输出格式:MJPG或YUY2可选,MJPG支持最大帧率60,YUY2支持最大帧率10,图像分辨率可自选
在这里插入图片描述

2. 使用 这里使用opencvsharp来做驱动测试,设置属性如下: 1、Width设置为480,Height设置为1280(选1280×480分辨率); 2、采集图像压缩格式设置为MJPG; 3、图像采集帧率设置为60;

按照如上思路,测试程序如下:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenCvSharp; namespace cvsharptest { class Program { static void Main(string[] args) { Mat frame = new Mat(); VideoCapture cap = new VideoCapture(1); cap.Set(CaptureProperty.Fps, 60); //相机采集帧率设置60fps cap.Set(CaptureProperty.FrameHeight, 480); //图像高度设置为480 cap.Set(CaptureProperty.FrameWidth, 1280); //图像宽度设置为1280 string fourcc_start = cap.Get(CaptureProperty.FourCC).ToString(); Console.WriteLine("fourcc_start: " + fourcc_start); //获取默认设置的图像采集格式 cap.Set(CaptureProperty.FourCC, 1196444237); //设置图像采集格式为MJPG string fourcc_last = cap.Get(CaptureProperty.FourCC).ToString(); double height = cap.Get(CaptureProperty.FrameHeight); double width = cap.Get(CaptureProperty.FrameWidth); double fps = cap.Get(CaptureProperty.Fps); int delay = (int)(1000 / fps); Console.WriteLine("fourcc_last: " + fourcc_last); Console.WriteLine("height: " + height.ToString()); Console.WriteLine("width: " + width.ToString()); Console.WriteLine("fps: " + fps.ToString()); while (true) { cap.Read(frame); Cv2.ImShow("video", frame); Cv2.WaitKey(delay); } } } } 3. 效果 MJPG采集的图像:帧率60,采集的图像足够快,没有延迟:
在这里插入图片描述 YUY2格式采集的图像:10fps,延时特别明显,用的很难受:
在这里插入图片描述 4. 需要注意的

1、如下图(opencvsharp使用videocapture类所有参数默认没有值,使用时需要自己赋值来设定相机参数);
fourcc是编解码器的四字符代码的意思,相机打开后默认设置为YUY2图像格式,如fourcc_start;刚开始一直没注意到图像输出格式的问题

fourcc_start = 844715353; //十进制数 fourcc_start = 0x32595559; //十六进制 //对应的ASCII码表值为: fourcc_start = "2YUY" ; //即默认格式为YUY2 //根据如上分析,设置图像为MJPG格式 cap.Set(CaptureProperty.FourCC, 1196444237); //设置图像采集格式为MJPG //fourcc应该设置为: fourcc_last = "GPJM"; //转换成16进制ASCII码 fourcc_last = 0x4750 4A4D //转换为十进制数,即可写入参数: fourcc_last = 1196444237; //十进制数

在这里插入图片描述

2、使用过程中,发现fps参数也需要设置,默认为0,可以设置采样频率为60,才能正常采集图像,默认图像大小为640×240,需要更改为自己想要的图像尺寸;

5. 其他

1、另一种方法: 商家提供的参考资料里使用的是Windows SDK中的Direct Show组件实现图像的采集与显示,Direct Show组件是Direct X的组件之一,是用来开发高性能图形,声音,输入,输出,网络游戏的编程接口,DirectShow是基于COM组件的,DirectShow组件使用C++实现,C#的话也有对应的封装,C#封装的DirectShow链接如下:http://directshownet.sourceforge.net/,MSDN中关于DirectShow组件描述链接:https://docs.microsoft.com/zh-cn/windows/win32/directshow/directshow?redirectedfrom=MSDN
2、考虑了方便快捷性,还是使用opencv/emgucv/opencvsharp中自带的VideoCapture类来操作设置摄像头参数速度比较快;
3、前面也使用了opencv的一段程序来测试摄像头工作模式,发现默认是MJPG输出,而不是YUY2,但是在opencvsharp/emgucv中却是默认YUY2输出,暂时不知道为什么不同;
4、摄像头正常驱动后,便可以进一步编写图像处理程序了,O(∩_∩)O哈哈~;

参考

1、https://blog.csdn.net/weicao1990/article/details/53379881
2、https://blog.csdn.net/aolveyu0182/article/details/101891794?depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-2&utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-2
3、https://blog.csdn.net/kyjl888/article/details/69367912


作者:hellohake



淘宝 摄像 摄像头 像素

需要 登录 后方可回复, 如果你还没有账号请 注册新账号