Ask Your Question

Revision history [back]

Try lower resolution

VideoCapture capture = new VideoCapture(0);
if (capture.isOpened())
{
    // to get the actual width of the camera
    System.out.print("Width: " + capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
    // to get the actual height of the camera
    System.out.println(", Height: " + capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));

    boolean wset = capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, WIDTH);
    boolean hset = capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
    if (!hset || !wset)
    {
        System.out.println("Width Changed: "+wset);
        System.out.println("Height Changed: "+hset);

        // to get the actual width of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
        // to get the actual height of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));
    }
}
click to hide/show revision 2
complete code added

Try lower resolution

VideoCapture capture = new VideoCapture(0);
int WIDTH = 320;
int HEIGHT = 240;
if (capture.isOpened())
{
    // to get the actual width of the camera
    System.out.print("Width: " + capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
    // to get the actual height of the camera
    System.out.println(", Height: " + capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));

    boolean wset = capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, WIDTH);
    boolean hset = capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, HEIGHT);
    if (!hset || !wset)
    {
        System.out.println("Width Changed: "+wset);
        System.out.println("Height Changed: "+hset);

        // to get the actual width of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_WIDTH));
        // to get the actual height of the camera
        System.out.println(capture.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT));
    }
}