![]() |
LifeCam USBCamera changing settings from Java
We are trying to use the LifeCam and the USBCamera class for our vision processing. One thing we need is the ability to control exposure and brightness so we get a good image going into our image processing pipeline.
So far I have been able to get an image on the SmartDashboard, provide a way to enter Exposure and Brightness values on the SmartDashboard and send them to the USBCamera class. The problem is, when I change the values, the image doesn't change brightness or exposure. I know the image is updating because I see the motion in new frames. Here is what we're currently doing: Startup: Code:
USBCamera targetCam = new USBCamera("cam0"); // create connection to cameraCode:
targetCam.getImage(frame); // retrieve a frame from the USBCamera classNow adding the brightness/exposure control to the loop Loop: Code:
int exposure = Preferences.getInstance.getInt("camExposure", 50);Does anyone have any experience on getting this to work? Any hints, tips or suggestions? We may have to punt with the USBCam and switch to the Axis Cam, which would be a shame since the LifeCam is so compact and "simple" |
Re: LifeCam USBCamera changing settings from Java
Quote:
Assuming I don't have any fires to be putting out at our teams meeting tonight, this was actually going to be my priority to troubleshoot. First year back on the programming subteam for awhile and and first year ever using Java, but hopefully I'll have something to report back tomorrow to help you out. |
Re: LifeCam USBCamera changing settings from Java
Robert,
I was actually able to get almost exactly what you have to work. The only difference is I made sure to update the camera before opening the camera and starting the capture. Code:
public class Robot extends IterativeRobot {Now if you find anyway to turn off the autofocus...that'd be handy. |
Re: LifeCam USBCamera changing settings from Java
THANK YOU THANK YOU THANK YOU!!! So frustrated with grip and this code might actually help us!
|
Re: LifeCam USBCamera changing settings from Java
I spent more time on it last night and discovered a few things. I looked at the source code for the USBCamera class - it's just a wrapper for the NIVision.IMAQ functions - that's not a bad thing, but it is good to know.
Info:
It's good to know what the functions are actually doing ;) Bottom line - I removed the openCamera() call and removed my calls to updateSettings() and relied on the USBCamera class to manage it. This works better, but not perfectly. I can adjust the brightness and see things change, but exposure seems to have no effect. I took it a step further. I created my own USBCamera class and added a getExposure() and modified the getBrightness() to get the values from the camera/driver using the NIVision.IMAQ calls. This proved to me that the exposure and brightness ARE getting changed, AND I validated that I am NOT in AutoExposure mode. Unfortunately, I still cannot get the exposure changes to show any appreciable effect on the LifeCam image. Brightness goes from a decent image with Brightness = 0, to a white image with Brightness = 100. Exposure changes seem to have no effect. Has ANYONE been able to get images out of the life cam, using ANY method, that comes anywhere close to being as dark as the sample images for the FRC vision processing? I'm beginning to think that the LifeCam is simply not adjustable to that low of an exposure. |
Re: LifeCam USBCamera changing settings from Java
Quote:
Were you able to get a good DARK image, or just an image that is good for a driver to look at? I want a DARK image that a driver would find unusable, but the image processing will be very happy about (because the retro-reflectors will show up nicely). |
Re: LifeCam USBCamera changing settings from Java
I just confirmed it is possible - I'm running on a Mac and I just installed "Webcam Settings Panel" from the app store. It allowed me to adjust the exposure to a BLACK image. It also seems to confirm that it is not doing any of this in software, but is actually querying the camera for it's capabilities. The setting options are different between the LifeCam, my laptop iSight and my monitor's iSight, for example, the LifeCam has a backlight compensation slider while the iSights show up as simply on/off options.
I also confirmed that the settings are saved in the camera (or at least in the driver) - quit the settings panel (so I know it wasn't restoring the values) and unplugged the cam and plugged it back in and the image was the same as when I had unplugged it. This is all good news, now if I can just figure out how to use the USBCamera, NIVision.IMAQ or something on the RoboRIO to make these same adjustments, I would be happy. |
Re: LifeCam USBCamera changing settings from Java
CORRECTION - I THOUGHT I had closed "Web Cam Settings" - I hadn't. IT was storing and re-storing the settings. I made sure I quit it and tested again. When I replugged the camera, it reverted to Autoexposure
|
Re: LifeCam USBCamera changing settings from Java
Quote:
Using the microsoft software linked to in the other thread, it was very obvious that the camera can be set up to change a lot more than we have access to with the class. I could turn the autofocus off, mess with the white balance, and all sorts of things that were useful in making the retroreflective tape pop even more. Unfortunately, I think we'll be limited to creating a good vision processing filter with just the brightness modified, though I'm going to keep messing with the exposure. But I am seeing the same thing you are - changing the exposure doesn't seem to have any affect, in fact at one point that camera stopped updating and I had no idea until I waved my hand in front of it to test something else. Good to know it's just a wrapper...might be more investigating to do with the IMAQ functions. |
Re: LifeCam USBCamera changing settings from Java
Quote:
|
Re: LifeCam USBCamera changing settings from Java
https://www.microsoft.com/hardware/e...ifecam-hd-3000 was the software - with the camera plugged into the laptop. The settings did not appear to get saved to the camera much as you saw from the webcam settings panel.
|
Re: LifeCam USBCamera changing settings from Java
Thanks for posting this code. One question that I have is how can you use GRIP when you have this code running in the robot. We have included similar code to turn off auto white balance and to turn off auto exposure in Java using the USB camera class. However, we have found that GRIP will not run if we have opened the USB camera in our java robot code. So then we tried closing the camera when we were done setting up the camera, but it seems like it does not retain the settings in this case. Is there some way to change the settings in the USB camera and then run GRIP without losing your changes?
|
Re: LifeCam USBCamera changing settings from Java
Quote:
|
Re: LifeCam USBCamera changing settings from Java
Quote:
|
Re: LifeCam USBCamera changing settings from Java
Using the NIVision IMAQ commands, the min/max values returned are 5 and 20,000 respectively. I duplicated the USB Camera class (too bad they made all the variable private instead of protected) and replaced the setExposureManual() with code that allowed me to set the value explicitly. It turns out that anything above about 40 or 50 will give you quite a bright image. I'm actually using 10 I think for the exposure and 10 for the brightness.
As for losing the settings - as long as you don't power the camera off, you will not lose the settings. It's tricky, but you can use Robot code to configure the camera, then disconnect, then run GRIP and it will have the setting you just set. There are some real caveats in all this and I think I finally have all the cases worked out. I'm probably going to post the code when I get it working. Caveat #1 - The robot code cannot use CameraServer - if it does, GRIP will not be able to publish a stream. Unfortunately, while you CAN disconnect from the USBCamera, you CANNOT kill the CameraServer stream without rebooting the robot or manually killing the robot code. Caveat #2 - don't forget that during development, if you use your robot code to set the settings, then launch GRIP, if you reload robot code, GRIP is still running and your robot code will throw an exception trying to connect to the USBCamera - you have to either reboot your roborio or kill the GRIP process. I've written code to kill the GRIP process if the USBCamera open() method throws and exception. |
| All times are GMT -5. The time now is 23:59. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi