2014-01-11 62 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