通过重新编译Opencv修改摄像头分辨率

由于要实时修改摄像头分辨率,发现普通摄像头很难满足,所以对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;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值