Java - Change a WebCam resolution.

General information about Neurotechnology and its software

Java - Change a WebCam resolution.

Postby almelo » Jul 25, 2018 16:38

Greetings,

Is there a way in the Java SDK to change the resolution of a webcam using its NDevice, NCamera or even NFace object?

Thank you very much in advance.
almelo
 
Posts: 2
Joined: Jul 25, 2018 16:34

Re: Java - Change a WebCam resolution.

Postby MartynasV » Jul 26, 2018 11:09

almelo wrote:Greetings,

Is there a way in the Java SDK to change the resolution of a webcam using its NDevice, NCamera or even NFace object?

Thank you very much in advance.

Hello Almelo,

Yes, just run "SDK\Bin\Java\devices-sample.jar", then select detected camera, then on the right you will be able to change capturing format(including resolution). Source code: "SDK\Samples\Devices\Java\devices-sample".
Code: Select all
NCamera camera;
camera.getFormats(); // Returns supported formats by that camera.
camera.getCurrentFormat(); // Returns current format of camera.
camera.setCurrentFormat(format); // Set new format to camera.
Martynas V
Neurotechnology
MartynasV
Neurotechnology
 
Posts: 398
Joined: Feb 27, 2015 11:24
Location: Vilnius, Lithuania

Re: Java - Change a WebCam resolution.

Postby almelo » Jul 26, 2018 21:03

Thanks for the answer.

I just found out that the returned object (NMediaFormat) can be converted to (NVideoFormat) and the attributes can be accessed, my problem comes when I need to modify the configuration ".setFrameRate()" which asks for a n"NRational" object which I try to set to 30 (the fps supported by my camera) but gives me the error "Value pValue points to be invalid", so far I have the following code:

Code: Select all
NVideoFormat videoFormat = new NVideoFormat();
videoFormat.setFlags(0);
videoFormat.setFrameRate(new NRational(30,0));
videoFormat.setHeight(480);
videoFormat.setInterlaceMode(NVideoInterlaceMode.PROGRESSIVE);
videoFormat.setMediaSubtype(844715353);
videoFormat.setPixelAspectRatio(new NRational(1,1));
videoFormat.setStride(0);
videoFormat.setWidth(640);


Thanks in advance.
almelo
 
Posts: 2
Joined: Jul 25, 2018 16:34

Re: Java - Change a WebCam resolution.

Postby MartynasV » Jul 27, 2018 11:05

almelo wrote:Thanks for the answer.

I just found out that the returned object (NMediaFormat) can be converted to (NVideoFormat) and the attributes can be accessed, my problem comes when I need to modify the configuration ".setFrameRate()" which asks for a n"NRational" object which I try to set to 30 (the fps supported by my camera) but gives me the error "Value pValue points to be invalid", so far I have the following code:

Code: Select all
NVideoFormat videoFormat = new NVideoFormat();
videoFormat.setFlags(0);
videoFormat.setFrameRate(new NRational(30,0));
videoFormat.setHeight(480);
videoFormat.setInterlaceMode(NVideoInterlaceMode.PROGRESSIVE);
videoFormat.setMediaSubtype(844715353);
videoFormat.setPixelAspectRatio(new NRational(1,1));
videoFormat.setStride(0);
videoFormat.setWidth(640);


Thanks in advance.

Hello almelo,

Set second value non zero e.g. new NRational(30,30), then you won't get that error.

You shound't try making your own format, instead you should use "camera.getFormats()" and then use one of those returned formats. That method returns all camera's supported formats, so they will work, when you set them.
Martynas V
Neurotechnology
MartynasV
Neurotechnology
 
Posts: 398
Joined: Feb 27, 2015 11:24
Location: Vilnius, Lithuania


Return to Public

Who is online

Users browsing this forum: No registered users and 2 guests