问题描述
你知道如何使用OpenCV-DirectShow(没有VFW)从网络摄像头获取原始YUY2 图像吗?
Do you know how to get raw YUY2 image from webcam, using OpenCV-DirectShow (no VFW) ?
:我成功获得IPL图像(英特尔处理库图像)使用示例。
http://opencv.willowgarage.com/wiki/CameraCapture : I succeed getting IPL image (Intel Processing Library image) using the example.
在代码中使用函数cvShowImage(),图像在屏幕上很好用。但我不想在屏幕上显示图像,也不想在IPL格式中显示图像,我只想要YUYV原始数据...
Using the function cvShowImage() in the code, the image is nice on the screen. But I don't want to show image on the screen, nor IPL format, I just want YUYV raw data...
维基页面的第二部分将是我想要什么,但是在OpenCV 2.4中似乎不存在deviceSetupWithSubtype()(甚至谷歌也不知道)。
The second part of the wiki page would be what I want, but deviceSetupWithSubtype() does not seem to exist any longer in OpenCV 2.4 (even Google does not know it).
编辑:我发现:它在页面上链接的rar文件!谷歌没有看到rar文件。以下是链接:。我打算研究这个。
EDIT : I found : it is in the rar file linked on the page ! Google does not "see" in rar files. Here is the link : http://opencv.willowgarage.com/wiki/CameraCapture?action=AttachFile&do=get&target=Camera+property+Settings.rar . I am going to study this.
推荐答案
通常,opencv使用directshow从windows中的网络摄像头获取RGB帧。 Opencv VideoCapture类获取CV_CAP_PROP_CONVERT_RGB属性(布尔标志指示图像将转换为RGB),但它在我的所有网络摄像头中都不起作用。
typically, opencv use directshow to get RGB frame from webcam in windows. Opencv VideoCapture class get CV_CAP_PROP_CONVERT_RGB property(boolean flag indicating whehter images shoule be converted to RGB), but it's not working in all my webcams.
而不是编写DirectShow代码并使你自己的样本抓取和回调,以获得YUY2数据desribe (他们hava made简化directshow开发的精彩工具。)我修改和()类(网页为中文)获取YUY2数据。
Instead of writing DirectShow codes and make your own sample grabber and callback to get the YUY2 data desribe here (they hava made wonderful tools to simplify directshow development.) I modify CameraDs and the (setup Doc) class(the web pages are in Chinese) to get YUY2 data.
在CameraDs中。 cpp将 mt.subtype = MEDIASUBTYPE_RGB24;
更改为 mt.subtype = MEDIASUBTYPE_YUY2;
(检查您的网络摄像头是否支持此项)
In CameraDs.cpp change mt.subtype = MEDIASUBTYPE_RGB24;
to mt.subtype = MEDIASUBTYPE_YUY2;
(check whether your webcam support this )
并制作2频道YUY2图像而不是RGB 3通道。
and makes a 2 channel YUY2 image instead of RGB 3 channel.
m_pFrame = cvCreateImage(cvSize(m_nWidth, m_nHeight), IPL_DEPTH_8U, 2);
并获取YUY2数据,并使用opencv界面将其更改为RGB:
and gets the YUY2 data outside and change it to RGB with opencv interface like:
{
//query frame
IplImage * pFrame = camera. QueryFrame();
//change them to rgb
Mat yuv (480, 640,CV_8UC2 ,pFrame-> imageData);
Mat rgb (480, 640,CV_8UC3 );
cvtColor(yuv ,rgb, CV_YUV2BGRA_YUY2);
//show image
//cvShowImage("camera", rgb);
imshow("camera" ,rgb);
if ( cvWaitKey(20 ) == 'q')
break;
}
这篇关于OpenCV:如何从网络摄像头获取原始YUY2图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!