【问题标题】:Opencv Camera Resolution IssueOpencv 相机分辨率问题
【发布时间】:2014-09-12 02:27:37
【问题描述】:

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

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

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)’

【问题讨论】:

    标签: c++ opencv camera


    【解决方案1】:

    我认为您正在混合使用 C 和 C++ 代码示例。 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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多