1

I'm trying to set the camera parameters using the following codeand it is not working at all.

using namespace cv;

    int main(int argc,char *argv[])
    {
        VideoCapture cap(0); // open the default camera 
        if(!cap.isOpened())  // check if we succeeded
            return -1;
        bool value = cap.set(CV_CAP_PROP_FRAME_WIDTH,10);
        for(;;)
        {
            Mat frame;
            cap >> frame;   // get a new frame from camera
            imshow("frame", frame);
            unsigned char *dad = (unsigned char*)frame.data;
            if(waitKey(30) >= 0) break;
        }
        // the camera will be deinitialized automatically in VideoCapture destructor
        return 0;
    }
surya
  • 287
  • 1
  • 6
  • 14
Andre
  • 43
  • 2
  • 4
  • 13
  • Please explain what "is not working at all" means. Does it compile? Does it throw an error? I could imagine your camera and or driver don't support changing the frame width parameter. In Linux for example it is not possible to change parameters of cameras that use V4L. – Herr von Wurst May 23 '12 at 12:35
  • Also, if you want to display the image you should add this line `cvNamedWindow( "frame", CV_WINDOW_AUTOSIZE );` somewhere before the endless for loop. – Herr von Wurst May 23 '12 at 12:38
  • I mean I can't change any of the camera parameters. – Andre May 23 '12 at 13:27

3 Answers3

2

OpenCV tries to set this size directly in the camera, so it doesn't need to resize the frame.

The problem with this approach is that if your camera doesn't support this size natively, OpenCV will fail setting the value, leaving you the task to resize the frame after it is retrieved.

cap.set() seems to return the success of the function, I suggest you check it.

I recommend taking a look at another thread: how to change the capture resolution in OpenCV.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
0

from opencv is using directshow for video capture. however, your camera only support a few of the resolution settings like, 480*320, 640*480, 720p, 1080p. if you set something else, it would not work at all. if you want to check what kinds of resolution your camera support. download the graphedt and check in the capture pin property.

flankechen
  • 1,225
  • 16
  • 31
-1

the above code is not using for changing the camera parameters. I think it usu full for showing the video in your machine. May be this link is useful to you http://opencv.willowgarage.com/wiki/CameraCapture

surya
  • 287
  • 1
  • 6
  • 14
  • You are wrong, this line `bool value = cap.set(CV_CAP_PROP_FRAME_WIDTH,10);` is supposed to change the frame width parameter. – Herr von Wurst May 23 '12 at 12:36