justadudewhohacks / opencv4nodejs

Nodejs bindings to OpenCV 3 and OpenCV 4
MIT License
4.95k stars 825 forks source link

Can't set specific width and height on capture #444

Open erenaud3 opened 5 years ago

erenaud3 commented 5 years ago

Hi,

I can't manage to set width and height for capture. Here's my code:

cap = new cv.VideoCapture(options.videoDeviceId);

console.log(cap.get(cv.CAP_PROP_FRAME_WIDTH));
console.log(cap.get(cv.CAP_PROP_FRAME_HEIGHT));

# Apply new camera size
cap.set(cv.CAP_PROP_FRAME_WIDTH, 1280);
cap.set(cv.CAP_PROP_FRAME_HEIGHT, 720);

console.log(cap.get(cv.CAP_PROP_FRAME_WIDTH));
console.log(cap.get(cv.CAP_PROP_FRAME_HEIGHT));

Which gives me the following output:

640
480
640
480

Am I doing something wrong ?

PS: Normally, my webcam should support the resolution 1280x720:

lsusb -s 001:003 -v | egrep "Width|Height"
Couldn't open device, some information will be missing
        wWidth                            640
        wHeight                           360
        wWidth                            640
        wHeight                           480
        wWidth                            176
        wHeight                           144
        wWidth                            320
        wHeight                           240
        wWidth                            352
        wHeight                           288
        wWidth                           1280
        wHeight                           720
        wWidth                            640
        wHeight                           360
        wWidth                            640
        wHeight                           480
        wWidth                            176
        wHeight                           144
        wWidth                            320
        wHeight                           240
        wWidth                            352
        wHeight                           288

EDIT: I initially put a Coffeescript snippet, I changed it to Javascript.

oyyd commented 5 years ago

You can log the return value of cap.set() to see if it's accepted.

I guess it's not accepted by the capture device (see the document).

erenaud3 commented 5 years ago

Thanks for your answer.

I checked, and the return value is "true" as expected.

hscspring commented 5 years ago

that doesn't work for me ... i got false when vCap.set(cv.CAP_PROP_FRAME_WIDTH, 640);

erenaud3 commented 5 years ago

that doesn't work for me ... i got false when vCap.set(cv.CAP_PROP_FRAME_WIDTH, 640);

Are you sure that your webcam can handle this resolution ? You can use this command to check it : lsusb -s 001:003 -v | egrep "Width|Height"

wbern commented 5 years ago

This is really tricky because some cameras don't work as intended.

My advice is to set the value CAP_PROP_SETTINGS to something positive. Hopefully you'll get a dialog window appearing allowing you to set all the possible values for the camera non-programmatically.

If you cannot set some property values there, you might be able to draw some conclusions from that.

Nick-lab commented 5 years ago

this is also happening to me as well

vCap = new cv.VideoCapture(0);
console.log('width', vCap.set(cv.CAP_PROP_FRAME_WIDTH, 720));
console.log('height',vCap.set(cv.CAP_PROP_FRAME_HEIGHT, 480));

and console of

width true
height true