Opencv相机分辨率问题

时间:2014-07-21 14:24:23

标签: c++ opencv camera

您正在开发基于模板匹配的项目。我需要一个相机接口。 我的代码所面临的问题与相机分辨率有关。我需要使用Logitech HD C270网络摄像头获得最大分辨率。我有可能获得640x480或更高的分辨率吗?

这是我的代码,我试图获得640x480分辨率,但我收到一些错误。 请帮忙。     #包括     #包括     #包括     #include

using namespace cv;
using namespace std;
int n = 0;
static char cam_image[200];


int capture_image(cv::Mat& frame_in) {

VideoCapture capture(-1); //try to open string, this will attempt to open it as a video file or image sequence
        if (!capture.isOpened()) //if this fails, try to open as a video camera,     through the use of an integer param
    capture.open(-1);
    capture = cvCreateCameraCapture(-1);
            cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 );
            cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 );
            //videoFrame = cvQueryFrame(capture);
        if (!capture.isOpened()) {
    cerr << "Failed to open the video device, video file or image sequence!\n" << endl;
    //help(av);
    return 1;
         }

    string window_name = "Reference Image";
        namedWindow(window_name, CV_WINDOW_KEEPRATIO); //resizable window;
    Mat frame;

    capture >> frame;
        if (frame.empty());
    frame_in= frame;
    imshow(window_name, frame);
    waitKey(30);
    sprintf(cam_image,"filename%.3d.jpg",n++);
    imwrite(cam_image,frame);
    cout << "Saved " << cam_image << endl;

    return 0;

}





camera.h: In function ‘int capture_image(cv::Mat&)’:
camera.h:17:43: error: invalid conversion from ‘CvCapture*’ to ‘int’ [-fpermissive]
/usr/local/include/opencv2/highgui/highgui.hpp:209:13: error:   initializing argument 1 of ‘cv::VideoCapture::VideoCapture(int)’ [-fpermissive]
camera.h:18:65: error: cannot convert ‘cv::VideoCapture’ to ‘CvCapture*’ for argument ‘1’ to ‘int cvSetCaptureProperty(CvCapture*, int, double)’
camera.h:19:66: error: cannot convert ‘cv::VideoCapture’ to ‘CvCapture*’ for argument ‘1’ to ‘int cvSetCaptureProperty(CvCapture*, int, double)’

1 个答案:

答案 0 :(得分:2)

我认为您正在混合CC++代码示例。 cvXXX()个函数适用于C API,应该是C++中的方法。 我试过这个,它对我有用:

cv::VideoCapture cap(opts.device);
cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
cap >> frame;

就这么简单,没有过多的open() s。