Java – image size supported by webcam

I am trying to retrieve the available picture size resolution supported by my webcam; Use opencv library I have tried to use similar Android questions / answers, but to no avail (for example, Android camera supported picture sizes) This 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();
    }
}

Stack traces are:

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 the help will be sincerely appreciated

Solution

As pointed out in the comments, this is a reported error listed for 2.4 9. Amendments:

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

In other words, the project is open source, and view the code that modifies the code, which is a simple fix You can implement this bug fix directly and build it yourself until 2.4.0 9 release The relevant amendments are as follows:

>In videocapture Cpp file: revision 5f88e2b4

Line 332 - > 335:

Replacement:

return env->NewStringUTF(u.name);

Attached:

// 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);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>