我正在尝试检索我的网络摄像头支持的可用图片尺寸分辨率;使用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)
所有的帮助将得到真诚的赞赏.
解决方法
正如评论中所指出的,这是一个报告的错误,列出了对于2.4.9的修正:
> http://code.opencv.org/issues/3387
> http://code.opencv.org/issues/3477
也就是说,这个项目是开放源代码,并且查看修改代码的代码,这是一个简单的修复.您可以直接实现该错误修复并自行构建,直到2.4.9发布.相关修订如下:
>在VideoCapture.cpp文件中:REVISION 5f88e2b4
线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);