2014-01-11 57 views
3

似乎在Java opencv中设置网络摄像头的分辨率的标准方法不起作用。我做到以下几点:OpenCV - 更改Java中的摄像头分辨率

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

它打印:

> false 
> false 

...并不会改变相机的分辨率。它似乎停留在640x480。我知道相机没有故障,因为我可以使用C++绑定将分辨率成功设置为1280x800。

另外 - v.getSupportedPreviewSizes()不起作用。它返回一个错误:

HIGHGUI ERROR: V4L2: getting property #1025 is not supported 

有什么想法?

回答

1

如果你希望你的相机运行,您首先需要打开您的捕获设备:

VideoCapture v = new VideoCapture(0); 

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

而且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 
+0

哦,我已经能够看到视频 - 我只是没有标出这一步。我会编辑它。问题仍然存在。另外,每次我执行'v.get(...)'时,它会返回640和480,而不管我设置了什么。 – mayhewsw

4

您需要先打开相机然后进行设置。我在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); 
+0

我也试过这个,它对我没有用。 – mayhewsw

+0

+1它的工作伙计,并感谢很多.... – Gopal00005

1

只是通过与构造摄像机编号,并设置宽度和高度...

webCamera = new VideoCapture(0); 
webCamera.set(Highgui.CV_CAP_PROP_FRAME_WIDTH,1280); 
webCamera.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 720); 

你去那里....

0

相反,使用Highgui设置分辨率,使用属性ID,其中3是宽度,4是高度,因此您的代码将如下所示:

VideoCapture v = new VideoCapture(); 
boolean wset = v.set(3, RESOLUTION_WIDTH); 
boolean hset = v.set(4, RESOLUTION_HEIGHT); 

System.out.println(wset); 
System.out.println(hset); 

v.open(cameraID); 

其他属性id,你可以找到在Setting Camera Parameters in OpenCV/Python