Go to Post "The rio has a boulder sized hole though it? *shrug* Just duct tape it. That doesn't let the code out, right?" - Bkeeneykid [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-01-2016, 08:59
robert1356 robert1356 is offline
Registered User
AKA: Robert Palmer
FRC #3824 (RoHAWKtics)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2012
Location: Knoxville, TN
Posts: 47
robert1356 is an unknown quantity at this point
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:
  • The USBCamera constructors call 'openCamera' internally. You don't need to explicitly call openCamera unless you explicitly call closeCamera.
  • UpdateSetting is automatically called by getImage() and getImageData() if one of the settings (exposure, brightness, fps, etc) had previously been changed. There is no need to call updateSettings() explicitly unless you are not using getImage() or getImageData().
  • The setBrightness() and setExposure() functions do nothing but set a USBCamera member variable. The settings are not sent to the camera/driver until the updateSettings is called (which will be the next time you call getImage() or getImageData())
    • The getBrightness() does nothing but return that member variable.

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.
  #2   Spotlight this post!  
Unread 06-02-2016, 23:36
Justin Buist Justin Buist is offline
Registered User
FRC #4003 (TriSonics)
Team Role: Mentor
 
Join Date: Feb 2015
Rookie Year: 2015
Location: Allendale, MI
Posts: 22
Justin Buist is an unknown quantity at this point
Re: LifeCam USBCamera changing settings from Java

Quote:
Originally Posted by robert1356 View Post
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.
The Javadoc notes that exposure and brightness go from 0 - 100 are completely wrong. I forget what the actual range is but this issue frustrated a room of students and mentors for most of a Saturday until we played with the MS software for the LifeCam which actually presents sane values for the 3 different settings. Brightness is something like -15 to 4 (don't trust that number, I'm going from rough memory) but not 0-100 at all. None of them documented to be 0-100 actually are.
  #3   Spotlight this post!  
Unread 08-02-2016, 09:23
1024Programming 1024Programming is offline
Registered User
FRC #1024
 
Join Date: Jan 2014
Location: Indiana
Posts: 43
1024Programming is an unknown quantity at this point
Re: LifeCam USBCamera changing settings from Java

Quote:
Originally Posted by Justin Buist View Post
The Javadoc notes that exposure and brightness go from 0 - 100 are completely wrong. I forget what the actual range is but this issue frustrated a room of students and mentors for most of a Saturday until we played with the MS software for the LifeCam which actually presents sane values for the 3 different settings. Brightness is something like -15 to 4 (don't trust that number, I'm going from rough memory) but not 0-100 at all. None of them documented to be 0-100 actually are.
I think it was mentioned in another post that the values actually go from 0-20,000. if that is the case, then using command will only max the value at 100/20,000.
  #4   Spotlight this post!  
Unread 08-02-2016, 11:11
robert1356 robert1356 is offline
Registered User
AKA: Robert Palmer
FRC #3824 (RoHAWKtics)
Team Role: Mentor
 
Join Date: Jan 2015
Rookie Year: 2012
Location: Knoxville, TN
Posts: 47
robert1356 is an unknown quantity at this point
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.
  #5   Spotlight this post!  
Unread 08-02-2016, 16:02
ahartnet's Avatar
ahartnet ahartnet is offline
Registered User
AKA: Andrew Hartnett
FRC #5414 (Pearadox)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2005
Location: Houston, Texas
Posts: 194
ahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant futureahartnet has a brilliant future
Re: LifeCam USBCamera changing settings from Java

Just wanted to say thanks for reporting your findings on all of this. I've been busy taking care of some other mentor duties, and this is a life saver in allowing some students still get some help in trouble shooting what is going on with limited software experience
__________________
Team 451 The Cat Attack, Student Alumni (2005)
Team 1646 Precision Guessworks, Mentor (2006-2008)
Team 2936 Gatorzillas, Mentor (2011-2014)
Team 5414 Pearadox, Mentor (2015-Present)
  #6   Spotlight this post!  
Unread 13-02-2016, 15:03
medofbr medofbr is offline
Registered User
FRC #5404
 
Join Date: Jan 2016
Location: Pennsylvania
Posts: 12
medofbr is an unknown quantity at this point
Re: LifeCam USBCamera changing settings from Java

Quote:
Originally Posted by robert1356 View Post
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.
When you say you can use the Robot code to configure the camera, then disconnect, then run GRIP, what do you mean by "then disconnect"? Does the mean calling the CloseCamera() function?
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 23:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi