may*_*wsw 5 java camera opencv resolution
似乎在 Java opencv 中设置网络摄像头分辨率的标准方法不起作用。我执行以下操作:
VideoCapture v = new VideoCapture();
boolean wset = v.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1280);
boolean hset = v.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 800);
System.out.println(wset);
System.out.println(hset);
v.open(1);
Run Code Online (Sandbox Code Playgroud)
哪个打印:
> false
> false
Run Code Online (Sandbox Code Playgroud)
...并且不会改变相机分辨率。它似乎停留在 640x480。我知道相机没有问题,因为我可以使用 C++ 绑定成功地将分辨率设置为 1280x800。
另外 -v.getSupportedPreviewSizes()
不起作用。它返回一个错误:
HIGHGUI ERROR: V4L2: getting property #1025 is not supported
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
小智 5
您需要先打开相机然后进行设置。我在 camera.open(0) 之前尝试过它,它只是返回到标准设置,但是在 camera.open(0) 之后尝试设置时它可以工作。
所以在你的代码中这样做
v.open(1)
boolean wset = v.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1280);
boolean hset = v.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 800);
Run Code Online (Sandbox Code Playgroud)
小智 2
如果你想让你的相机运行,你首先需要打开你的捕获设备:
VideoCapture v = new VideoCapture(0);
Run Code Online (Sandbox Code Playgroud)
//add 0 as paramater in the constructor.This is the index of your capture device.
boolean wset = v.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1280);
boolean hset = v.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 800);
System.out.println(wset);
System.out.println(hset);
Run Code Online (Sandbox Code Playgroud)
v.getSupportedPreviewSizes() 不起作用,请改用它:
v.get(Highgui.CV_CAP_PROP_FRAME_WIDTH); //to get the actual width of the camera
v.get(Highgui.CV_CAP_PROP_FRAME_HEIGHT);//to get the actual height of the camera
Run Code Online (Sandbox Code Playgroud)