Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webcam supported picture sizes

I am attempting to retrieve the available picture-size resolutions supported by my webcam; using the OpenCV library. I have tried working with similar Android question/answers but to no avail. (e.g. Android camera supported picture sizes). Here is my code:

import org.opencv.highgui.VideoCapture;
import org.opencv.core.Size;

public class MyCameraCaptureClass {

public static void main(String[] args) {
    System.out.println("Hello, OpenCV");
    System.out.println("This program will display the webcam's supported sizes");

    System.loadLibrary("opencv_java248"); //load .dll for the jar

    VideoCapture vidCap0 = new VideoCapture(0);

    if (vidCap0.isOpened()) {
        System.out.println("Camera found, and it works so far...");

        for (Size aSize : vidCap0.getSupportedPreviewSizes()) {
            System.out.println("Doesn't print this at all");
            System.out.println("Height:" + aSize.height + "Width:" + aSize.width);
        }
    }
    vidCap0.release();
    }
}

And the stack trace is:

Exception in thread "main" java.lang.Exception: unknown exception
at org.opencv.highgui.VideoCapture.getSupportedPreviewSizes_0(Native Method)
at org.opencv.highgui.VideoCapture.getSupportedPreviewSizes(VideoCapture.java:478)
at webcam.MyCameraCaptureClass.main(MyCameraCaptureClass.java:19)

All help will be sincerely appreciated.

like image 430
Koffy Avatar asked Mar 03 '14 07:03

Koffy


People also ask

How many pixels is good for a webcam?

Look for a webcam that takes still images that are at least two megapixels. Most current models take images much higher, and 15-megapixel captures are common.

Is 640x480 a good resolution for webcam?

VGA is a descriptor that usually refers to 640x480 resolution, which is the same resolution of a standard definition television. Webcams that are VGA are not considered high-definition webcams.

How do I change the picture size on my webcam?

Click the Start button, type camera, and select the app from the results. Select the cogwheel button to open Settings. Now, from the panel on the left, you can do a lot of adjustments like the resolution for photos and videos, time lapse settings, framing grid, and more.

What is webcam field of view?

Field of View (FOV) is amount that can be seen from the camera lens. It is represented as an angle as the further back from the camera a wider distance can be seen. Some vendors will quote horizontal (HFOV), vertical (VFOV) or diagonal field of view (DFOV).


1 Answers

As noted in the comments this is a reported bug that has been listed as corrected for 2.4.9:

  • http://code.opencv.org/issues/3387
  • http://code.opencv.org/issues/3477

That said, the project is open source, and looking at the code change that corrects this, it is a simple fix. You could just implement that bug fix and build it yourself to use until 2.4.9 is released. The associated revision is here:

  • In the VideoCapture.cpp file: REVISION 5f88e2b4

Lines 332->335:

Replace:

return env->NewStringUTF(u.name);

With:

// VideoCapture::get can return 0.0 or -1.0 if it doesn't support
// CV_CAP_PROP_SUPPORTED_PREVIEW_SIZES_STRING
if (u.prop != 0.0 && u.prop != -1.0)
    return env->NewStringUTF(u.name);
like image 169
Matthew Avatar answered Sep 23 '22 00:09

Matthew