PDA

View Full Version : Howto detect the end of an image Capture



vdaanen
July 16, 2007, 16:13:08
Hi,

my compagy just bought a USB frame grabber. I have to add a library to support this new framegrabber.

In the current library, we can queue a snap request and the poll to wait the end of the snapping.

I found the way to queue a snap request (snapImagesAsync) but I can figure what I should do to know that an image was snapped !

Does a method saying " your request has been satisfied" exsit ?

Thanks

Vincent

Stefan Geissler
July 16, 2007, 16:50:51
Hi Vincent,

If you would IC Imaging Control, then you would call grabber::snapimages. This function returns right after an image has been delivered.
From which SDK comes "snapImagesAsync"? This function is unknown to me.

vdaanen
July 16, 2007, 17:04:33
Hi Stefan

Hi Vincent,

If you would IC Imaging Control, then you would call grabber::snapimages. This function returns right after an image has been delivered.

Yes I know this function and I'm using it for the method which returns once an image has been grabbed

But I have also to post a request and poll to know if the request has been processed.



From which SDK comes "snapImagesAsync"? This function is unknown to me.


I'm using IC Imaging Control 3.0


FrameHandlerSink::snapImagesAsync Method
Queues up a snap job, thus copying a number of frames into the MemBufferCollection. The method returns immediately after queuing the job.
Syntax: Error snapImagesAsync( unsigned int count );

Parameter Description

count Number of frames to copy into the MemBufferCollection.

Return Value: An error object, reporting the status of the performed operation.

Remarks: You cannot terminate this snap job unless you stop live mode by calling Grabber::stopLive.

See also: FrameHandlerSink, FrameHandlerSink::snapImages

<< FrameHandlerSink

V

Stefan Geissler
July 17, 2007, 13:25:23
Hello Vincent,

You are right, the function "snapImagesAsync" is available. I never worked with this function, thus I was a little bit puzzled. I am not sure, whether the use of this function is sensefull, because the function "snapImages" is easier to handle and returns after all images have been snapped.

Anyway, here is the solution for your problem:
You need to add a GrabberListener derived class. Its frameReady() method is used to count the imcoming frames. If it is bigger than the image count you want snap, a message is send to the parent window:

void CListener::frameReady( Grabber& param, smart_ptr<MemBuffer> pBuffer, DWORD FrameNumber)
{
if( m_pParent != NULL)
{
ImageCounter++;
if( ImageCounter >= 10 )
{
m_pParent->PostMessage(WM_USER+91,0,0); // Tell the parent, we have finished.
}
}
}

Before m_pSink->snapImagesAsync() is called, the counter in CListener must be reset:

void CsnapImagesAsyncDlg::OnBnClickedButtonsnapasync()
{
m_cListener.PrepareSnapCounter();
m_pSink->snapImagesAsync(10);
}


void CListener::PrepareSnapCounter()
{
ImageCounter = 0;
}

Also the CListener class must know the parent window:

void CListener::SetParent( CWnd *pParent)
{
m_pParent = pParent;
}


Thus we have to setup the sink and the grabber as follows:

m_cGrabber.addListener(&m_cListener);

// Tell the listener, who is his parent window:
m_cListener.SetParent(this);

// Set the sink
m_pSink = FrameHandlerSink::create( DShowLib::eRGB24, 3 );
m_pSink->setSnapMode( true ); // Automatically copy not any frame to the sink and call CListener::frameReady().
m_cGrabber.setSinkType( m_pSink );


I attached a Visual Studio 2003 VC++ sample.

vdaanen
July 17, 2007, 14:01:33
Thanks for your help Stefan.

I came to the conclusion I had to use the listener.

V