网络摄像头支持的图片尺寸

10

我正在尝试使用OpenCV库检索我的网络摄像头支持的可用图片大小分辨率。我已经尝试了类似于Android问题/答案的方法,但没有成功。(例如:Android camera supported picture sizes)。以下是我的代码:

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();
    }
}

堆栈跟踪如下:

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.


你可以提供异常的堆栈跟踪吗? - Eugene Evdokimov
@Eugene Evdokimov - 专门为您翻译的:)) - Koffy
1
看起来这是OpenCV中的一个错误,最近已经修复:http://code.opencv.org/issues/3387 - Eugene Evdokimov
3
很遗憾,这个500声望值的赏金没能获得 :) - BConic
嗯,我想如果您使用主干版本,应该可以避免这个问题。 - scap3y
显示剩余4条评论
1个回答

9

正如评论中所指出的,这是一个已报告的错误,已经被列为2.4.9版本的修复内容:

话虽如此,该项目是开源的,查看修正此错误的代码更改后,它只需要进行简单的修复。您可以实现该错误修复并自行构建使用,直到2.4.9发布。相关修订在此处:

第332-335行:

替换为:

return env->NewStringUTF(u.name);

使用:

// 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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接