Kunal Sonone
Kunal Sonone

Reputation: 43

Opencv Camera Resolution Issue

Hi am working on a project based on template matching. I need one camera interface for. The problem I am facing with my code is related to the Camera Resolution. I need the maximum resolution using my Logitech HD C270 Webcam. Is it possible that I could get the 640x480 or higher resolution?

Here is my code which I am trying to get 640x480 resolution but I am getting some error. please help. #include #include #include #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)’

Upvotes: 0

Views: 2682

Answers (1)

Victor Sergienko
Victor Sergienko

Reputation: 13475

I think you're mixing C and C++ code samples. cvXXX() functions are for C API and should be methods in C++. I tried this, it worked for me:

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

As simple as that, without the excessive open()s.

Upvotes: 2

Related Questions