我正在尝试检索网络摄像头支持的可用图片大小分辨率;使用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)
真诚地感谢所有帮助。
答案 0 :(得分: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);