PDA

View Full Version : eGRAB and Callback Function



Unregistered
October 17, 2002, 18:05:27
I'm trying to continuously grab images then paint them into a chroma-key overlay buffer for display in the "chroma-keyed" portion of a display window. I can snap 5 images and everything works with the callback routine doing the display, 5 frames then stop. If I change eSNAP to eGRAB it no longer works. Any Ideas?


This message was originally posted by John Oehrle in the old IC Imaging Control Support Forum.

Unregistered
October 18, 2002, 18:01:53
John,

If you use eGRAB at the FrameGrabberSink, you do not need to call snapImages() explicitly. Your registered callback function is called automatically by the grabber for each frame, if the FrameGrabberSink is set to eGRAB.

Best regards
Stefan
IC Support


This message was originally posted by Stefan in the old IC Imaging Control Support Forum.

Unregistered
October 18, 2002, 19:42:25
Dear Stefan:

First, thanks for your response.
Yes, I removed the snapImages(5) call and the stopLive() call and the callback routine never executes.
changed eSNAP to eGRAB in the setSinkType(....eGRAB)

also changed from:

startLive(false);
snapImages(5);
stopLive();//(can do this when exiting prgm)

to:
startLive(false);
//snapImages(5);
//stopLive();//(can do this when exiting prgm)

BELIEVE IT OR NOT THE CODE BELOW WORKS, I GET 5 FRAMES THEN NOTHING, AS EXPECTED.
WHEN I DO THE ABOVE CHANGES IT NO LONGER WORKS.
I cheat at least 3 times, 5 buffers all point to the same place, VideoFormat[5] by experience, text Logitec.....I promise to clean it up.

/*
This is the callback function which will be installed with setCallback.
*/
void callBackFunc(void *data, DShowLib::Grabber::tMemBufferPtr pBuffer, unsigned long currFrame )
{
CRect windowRect, clientRect;
pMainFrame->m_pImage->GetClientRect(&clientRect);
pMainFrame->m_pImage->ClientToScreen (&clientRect);
pos_x=mid_x-clientRect.left-theCamera.m_width/2;
pos_y=mid_y-clientRect.top-theCamera.m_height/2;

if( currFrame < 5 )
{
SetDIBitsToDevice(hDC, pos_x, pos_y, theCamera.m_width, theCamera.m_height, 0, 0, 0, theCamera.m_height, theApp.m_pBitmap, &bmi, DIB_RGB_COLORS);
}

return ;
}
SNIPPETS:
CString text="Logitech QuickCam Pro 3000";
m_pGrabber = new DShowLib::Grabber();
ASSERT( m_pGrabber );


m_pGrabber->setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eSN AP ) );

m_pGrabber->openDev( text );

struct userDataStruct userdata;
userdata.count=0;

int i;

for( i = 0; i < 5; i++ )
{
userdata.writtenBuffers = false;
}

// Create the tsFrameEndCallback structure
DShowLib::tsFrameEndCallback callback( callBackFunc, &userdata );
// Set the callback function
m_pGrabber->setCallback( callback );

// Select a video format
DShowLib::Grabber::tVidFmtListPtr pVideoFormats
= m_pGrabber->getAvailableVideoFormats();
m_pGrabber->setVideoFormat( (*pVideoFormats)[5]);
.
.
.
BYTE* pBuf[5];
// Allocate 5 image buffers
for( i = 0; i < 5; ++i )
{
// pBuf[i] = new BYTE;
pBuf[i] = m_pBitmap;
}
// Create a new mem buffer collection which uses our own image buffers
DShowLib::Grabber::tMemBufferCollectionPtr pMemBufferCollection = m_pGrabber->newMemBufferCollection( size_buffer, pBuf, 5 );

// Make the collection the active one
m_pGrabber->setActiveMemBufferCollection( pMemBufferCollection );

// Prepare the snap
m_pGrabber->startLive( false );
// Snap 5 images
m_pGrabber->snapImages( 5 );
// Stop the device. This means no snaps are allowed after this call
// m_pGrabber->stopLive();


[SIZE=1][I]This message was originally posted by John Oehrle in the old IC Imaging Control Support Forum.

Unregistered
October 22, 2002, 18:38:40
I tried opening the device before setting the frame grabber sink to eGRAB. That works. Now I am having a problem understanding the videoformats and the buffering. 640x480 RGB24, IYUV and I420 all seem to work the same. Do they all get converted to RGB24 before lbeing put in the memory buffer?


This message was originally posted by John Oehrle in the old IC Imaging Control Support Forum.

Unregistered
October 23, 2002, 15:44:40
John,

The color depth of the frame grabber sink is set to RGB 24 by default. The constructor of the FrameGrabberSink looks like follows:

FrameGrabberSink( DShowLib::FrameGrabberSink::tFrameGrabberMode mode , DShowLib::tColorformatEnum colorformat = eRGB24 );

If you want to choose another color depth, you should enter following line:

m_pGrabber->setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eSN AP, eRGB32 ) );

At this time, RGB 8, 555, 565, 24 and 32 fornats are supported.

For continuously image grabbing see the example at
http://www.imagingcontrol.com/ic/downloads/code/snippet/2_2.htm.

Best regards
Stefan
IC Support


This message was originally posted by IC Support in the old IC Imaging Control Support Forum.