Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Red, Green and Blue Gains in NI-IMAQ 1394

Hi,
 
I am using a SONY XCD-X710CR camera. I am trying to set the Red, Green, and Blue Gains programatically using LabWindows. I was able to setup a Bayer filter and it worked, but when tried to set the RGB Gains before stopping the current acquisition, the whole application crashed. Then I stopped the acquisition, tried to set new RGB gains, and got the following error "Acquisition already in progress". I know that RGB gains can be changed programatically because by using NI MAX I can change those values.
 
The following is the line of code that it is not working:
 
 GetCtrlVal(panelHandle, PANEL_RED_NUMERICSLIDE, &RedGain); // Get gain value from panel

 if ((imaq1394ErrorCode=imaq1394SetAttribute(Sid, IMG1394_ATTR_COLOR_FILTER_GAIN_R, RedGain)) != IMG1394_ERR_GOOD){
  Displayimaq1394Error("Set Red Gain", imaq1394ErrorCode);
 }
 
Any ideas ?
0 Kudos
Message 1 of 5
(3,669 Views)
You can only alter the Red, Green, and Blue gains for the Bayer filter if the acquistion is not running. In MAX, the acquisition is stopped and unconfigured before the gain values are adjusted. Then the acquisition is configured and started again. This gives the illusion that the gain values are adjusted while the acquisition is running.

Message Edited by JohannS on 10-17-2005 05:55 PM

0 Kudos
Message 2 of 5
(3,666 Views)
I also tried to unconfigure the session, modifying gains, and then configure again the acquisition, but my application crashed exactly when I was trying to set that attribute. I woould expect the imaq1394SetAttribute function to return an error instead of crashing the whole application.
 
0 Kudos
Message 3 of 5
(3,661 Views)
Pacsoft

I implemented the Grab1394 with Bayer filtering and noticed 2 possible pitfalls.

1) The unconfigure and reconfigure should happen in the same thread is the image acquistion. Typically the main loop. So the callbacks should only update state that gains have changed. In the main loop, do the actual reconfigure.

2) The prototype for imaq1394SetAttribute(uInt32 sessionId, uInt32 attribute, uInt32 value) does not readily take a double value. If you were to pass in a double, it would be coerced from 64-bit floating to 32-bit integer. Once the driver attempts to access the value, then a user mode crash was certain to follow. Looking at the reference manual for imaq1394SetAttribute, we notice for the value parameter, the type is

unsigned long (passed by value) or double (passed by reference)

That means the code should look like:

imaq1394SetAttribute (Sid, IMG1394_ATTR_COLOR_FILTER_GAIN_R, (uInt32)&GainRed);

Please see attached example for an implementation that does not crash.

Johann
0 Kudos
Message 4 of 5
(3,651 Views)

Hi,

Now is working perfectly. By sending the address of the gain value (a double) including the cast to an unsigned 32-bit integer (uInt32) solved the problem.

Meanwhile I was setting the hue, white balance red, and white balance blue properties to balance my image and it worked, although I find easier to adjust the RGB gains directly. Now I can use both if needed.

 

Thanks a lot for your response, Johan.

0 Kudos
Message 5 of 5
(3,630 Views)