PDA

View Full Version : Large overhead when adjusting gain



yan_zhao_ep
June 23, 2014, 20:01:26
Hi,

I found there is a considerate delay when I switch the gain values. The interesting part is that when I use the same method adjusting the exposure, I don' see the large delay. So I want to make sure if it's a known behavior or because of something I did was wrong.

My code is below, it updates the gain of the camera every 50 frames. The SetGainAbsolute function in the code is modified from Stefan's SetExposureAbsolute function by replacing "Exposure" with "Gain".

The delay causes more than 60% FPS drop. For example for 50Hz capturing, the rate will drop to below 25Hz when adjusting the gain (and then goes back up to 50Hz). For exposure adjusting, it is only 10%-20%.



Thanks very much for your reply.


YZ



/************************************************** ***********************/
/* Start to run the test */
/************************************************** ***********************/
int nTotalTests = 10;
double dfGain = 0.5;
double dfGainD = dfGain;

for(int i = 0; i < nTotalTests; i++)
{
dfGain = dfGainD*(double)(i+1);
lPrevTimeInMs = GetTime();
StartTimer();
SetGainAbsolute(mpGrabber, dfGain);
mpGrabber->startLive();
for(int f = 0; f < nNumTotalFrames; f++)
{
StartTimer();
pSink->snapImages(1);
StopTimer();
lCurrTime = GetTime();
oRez.push_back(lCurrTime - lPrevTime);
lPrevTime = lCurrTime;
}
StartTimer();
mpGrabber->stopLive();
StopTimer();
}




bool SetGainAbsolute( DShowLib::Grabber *pGrabber, double dGain )
{
bool bOK = false;
DShowLib::tIVCDAbsoluteValuePropertyPtr pGainRange;
DShowLib::tIVCDSwitchPropertyPtr pGainAuto;

pGainRange = NULL;
pGainAuto = NULL;

tIVCDPropertyItemsPtr pItems = pGrabber->getAvailableVCDProperties();
if( pItems != 0 )
{
// Try to find the Gain item.
tIVCDPropertyItemPtr pGainItem = pItems->findItem( VCDID_Gain );
if( pGainItem != 0 )
{
// Try to find the value and auto elements
tIVCDPropertyElementPtr pGainValueElement = pGainItem->findElement( VCDElement_Value );
tIVCDPropertyElementPtr pGainAutoElement = pGainItem->findElement( VCDElement_Auto );

// If an auto element exists, try to acquire a switch interface
if( pGainAutoElement != 0 )
{
pGainAutoElement->getInterfacePtr( pGainAuto );
pGainAuto->setSwitch(false); // Disable auto, otherwise we can not set Gain.
}


// If a value element exists, try to acquire a range interface
if( pGainValueElement != 0 )
{
pGainValueElement->getInterfacePtr( pGainRange );

double min = pGainRange->getRangeMin();
double max = pGainRange->getRangeMax();

if ( dGain < min )
{
dGain = min;
}
else if( dGain > max )
{
dGain = max;
}

// Here we set the the Gain value.
pGainRange->setValue( dGain);
bOK = true;
}
}
}
return bOK;
}

Stefan Geissler
June 24, 2014, 08:35:42
Which camera model do you use? I lost it somewhere.
Also you can use DShowLib::tIVCDAbsoluteValuePropertyPtr pGainRange; as global variable, so you only query it once for your camera.

yan_zhao_ep
June 24, 2014, 13:50:15
It's a DFK23UP031.

I'll try to put pGainRange outside the function.

Stefan Geissler
June 24, 2014, 14:18:10
However, this should be fast enough too.
I suppose the number of buffers in your sink is greater than one. If not set it to a value greater one.

Setting a gain value should not take noticeable time. Not more, than exposure. The gain automatic runs in the camera driver, it sends new gain values all the time to the camera, if the automatic is enabled.

The line
pGainRange->setValue( dGain);
is the interresting one for you, which you may insert directly in your snapImage loop.

yan_zhao_ep
June 24, 2014, 14:55:47
Hi Stefan,

Thanks for your help. Actually I made a mistake in the code that I stopped and started live as I did for ROI update.

Now the function works fine after I moving startLive and stopLive out of my test loop.



Regards,

YZ

Stefan Geissler
June 24, 2014, 15:18:50
Very well.