PDA

View Full Version : Simple snap images program



Unregistered
March 17, 2005, 15:24:08
Hi, I am using VC 7.1 and MFC. I just creat a very simle program to grab an image. I add two items in "MENU": "SHOW" and "SNAP". "SHOW" is to start the web camera. "SNAP" is just to grab an image. The "SHOW" function is working fine. I can display the video. But after I click "SNAP" button the program always break at "pGrabber->getActiveMemBuffer()->getCollection();" and give me "Unhandled exception at 0x100e0b41 in ex1.exe: 0xC0000005: Access violation reading location 0x00000004." I wrote this code in my program accoring to the "Pixelformat" example. Anyone know what I am missing?
Thank you.
void Cex1View::OnIcSnap()
{
// TODO: Add your command handler code here
DShowLib::Grabber* pGrabber = GetDocument()->m_pGrabber;
IplImage *image = 0;
BYTE *data;
Grabber::tMemBufferCollectionPtr pMemBuffColl;
pGrabber->setSinkType( DShowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eSN AP, eRGB24 ) );

pMemBuffColl =pGrabber->newMemBufferCollection( 1 );
pGrabber->setActiveMemBufferCollection( pMemBuffColl );
pGrabber->snapImages( 1, 2000 );
// get pointer to the image data
pGrabber->getActiveMemBuffer()->getCollection();

}

Tim Cassens
March 17, 2005, 15:58:39
Hello

The problem with your code is that you try to set the SinkType and the MemBufferCollection while live video is running.

You have to do this prior to calling startLive.

In your code sample, getActiveMemBuffer returns 0, because the MemBufferCollection was not set successfully.

ted616
March 17, 2005, 16:31:32
Yes, I changed the program a little(put setting codes before startlive()). Now every thing works find. But I use a trace time class find the pGrabber->snapImages( 1, 200 ); function takes about 30 ms which is a little bit long for only snap image even though I didn't do any operation yet. Do you know how to grab frames in very short time?
Thanks again.

Stefan Geissler
March 17, 2005, 17:00:04
Hello

The 30 ms sounds for the frame rate duration. SnapImages waits for the next delivered frame. This is copied into memory. Then snapImages returns.

ted616
March 17, 2005, 17:18:38
Thanks. Is there anyway I can acess the image buffer directly without snap images? because I don't want to spend 30ms to grab every frame. Is there any way the IC image control can give a interrupt on every fram?

Tim Cassens
March 18, 2005, 16:34:14
Have a look at the Callback sample.

It registers a Listener class with a method that is called every time a frame is delivered from the device.

ted616
March 19, 2005, 15:23:20
Thanks, Tim. I'll study the CallBack sample. By the way, I found every time I click "SNAP" button to snap a image, the usage of memory will increase. If I continuously snap the images, the memory will fill up. And I can find any release memory function to free the snaped images in "IC Imaging Control Class User's Guide".

Tim Cassens
March 21, 2005, 11:36:27
All memory allocated by the IC Imaging Control class library is given to you through reference counting smart pointers.

The memory stays allocated as long as the smart_ptr objects exist.

The only way to make these smart_ptr's live longer than the button event handler is to either 'new' them on the heap themselves (bad idea) or save them in some kind of list, which would both make you responsible for freeing the smart_ptrs.

However, I wont be able to tell whats wrong without seeing your code, so it would be nice if you could send me a small demo application that shows the increasing memory consumption.

ted616
March 22, 2005, 17:08:11
I found the problem is not IC image control. I create a opencv image object but didn't delete so the memory allocation is increasing.