您的位置:首页 > 运维架构

opencv 设置摄像头分辨率

2015-08-22 19:32 344 查看
使用函数cv::VideoCapture::set()函数设置摄像头的分辨率

#include "cartoon.h"

int main()
{
VideoCapture capture(0);
if (!capture.isOpened()) { //判断能够打开摄像头
cout<<"can not open the camera"<<endl;
cin.get();
exit(1);
}

capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

int count=0;

while (1) {
Mat frame;
capture>>frame; //载入图像

if (frame.empty()) { //判断图像是否载入
cout<<"can not load the frame"<<endl;
} else {
count++;
if (count == 1) {
cout<<frame.cols<<"  "<<frame.rows<<endl;
}

imshow("camera", frame);
char c=waitKey(30); //延时30毫秒
if (c == 27) //按ESC键退出
break;
}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: