由于要实时修改摄像头分辨率,发现普通摄像头很难满足,所以对Opencv源码进行修改,如下
1. 打开源码/modules/highgui/include/opencv2/highgui/highgui_c.h文件,找到CV_CAP_PROP_FRAME_WIDTH= 3的枚举结构体,在该结构体后面加上CV_CAP_PROP_FRAME_WIDTHHEIGHT = 6666
2. 打开源码/modules/highgui/src/cap_dshow.cpp,找到函数:bool CvCaptureCAM_DShow::setProperty(int property_id,double value)在该函数中
switch( property_id )
{
case CV_CAP_PROP_FRAME_WIDTH:
width = cvRound(value);
handled = true;
break;
case CV_CAP_PROP_FRAME_HEIGHT:
height = cvRound(value);
handled = true;
break;
case CV_CAP_PROP_FRAME_WIDTHHEIGHT:
width = floor(value/1000);
height = value-floor(value/1000)*1000;
VI.stopDevice(index);
VI.setupDevice(index, width, height);
VI.restartDevice(index);
handled = true;
break;
case CV_CAP_PROP_FOURCC:
fourcc = (int)(unsigned long)(value);
if ( fourcc == -1 ) {
// following cvCreateVideo usage will pop up caprturepindialog here if fourcc=-1
// TODO - how to create a capture pin dialog
}
handled = true;
break;
case CV_CAP_PROP_FPS:
int fps = cvRound(value);
if (fps != VI.getFPS(index))
{
VI.stopDevice(index);
VI.setIdealFramerate(index,fps);
if (widthSet > 0 && heightSet > 0)
VI.setupDevice(index, widthSet, heightSet);
else
VI.setupDevice(index);
}
return VI.isDeviceSetup(index);
}
添加下面代码,保存,这样子就修改成功,然后重新编译就可以
case CV_CAP_PROP_FRAME_WIDTHHEIGHT: width = floor(value/1000); height = value-floor(value/1000)*1000; VI.stopDevice(index); VI.setupDevice(index, width, height); VI.restartDevice(index); handled = true; break;