PDA

View Full Version : why I always get Last Frame Image not Current Frame Image?



dongfenghe
January 21, 2013, 11:53:27
Hi:
I have encountered a problem in my programme. I have a Thread,in which I must move a worktable by Motion Control Card, then wait for worktable moving stop,and then snap image,save image,set event for Image process Thread. But when I examine image saved, I found that system always save the Last frame Image(before worktable moving) but not the Current Frame Image(after worktable moving). what's Wrong?

My camera Type is DFK23G618(GigECam), Serial Number is 31214052, MAC address is 00074889D944
IP Address is 192.168.1.140, Subnet Mask is 255.255.255.0, Default GateWay is 0.0.0.0

I use IC Imaging Control Class library 3.2 and Microsoft Visual C++ 6.0(SP6)
My Code is :


unsigned long _stdcall ThreadTaping(LPVOID pParam) //my ThreadFunction
{
DShowLib::Grabber* pGrabber;
DShowLib::tFrameHandlerSinkPtr pSink;
DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList;

pGrabber = new DShowLib::Grabber();

pVidCapDevList = pGrabber->getAvailableVideoCaptureDevices();
pGrabber->openDev(pVidCapDevList->at(0));
pGrabber->setHWND(g_pView->m_staImageShow.m_hWnd);

pGrabber->setVideoFormat("RGB24 (640x480)");

pSink= DShowLib::FrameHandlerSink::create(DShowLib::eRGB2 4, 5);

pSink->setSnapMode(true);

pGrabber->setSinkType(pSink);

pGrabber->getOverlay()->setEnable( true );

pGrabber->addListener( g_pDoc->m_pListener, DShowLib::GrabberListener::eOVERLAYCALLBACK );

pGrabber->setDefaultWindowPosition(false);

pGrabber->setWindowSize(640*0.85,480*1.0);

while(g_AutoRunState ==1) //when Auto Run State
{
WaitForSingleObject(TapingEvent.m_hObject,INFINITE ); //wait for process

//moving worktable ........
//wait for worktable moving stop.
//snap image
pSink->snapImages(1);

//save image
pSink->getLastAcqMemBuffer()->save("C:\\Testcap.bmp");

lpImage=pSink->getLastAcqMemBuffer()->getPtr();
ImageDetectEvent.SetEvent(); //SetEvent for Image process Thread
}
}

Stefan Geissler
January 22, 2013, 08:49:33
Hi

I just wonder, why you receive an image at all, because I miss the pGrabber->startLive() and pGrabber->stopLive() calls. So you may add them and try again.

dongfenghe
January 22, 2013, 13:36:57
thanks for your reply so quickly.
Actually,I have two versions of programme. In first version, I have defined Grabber,FrameHandlerSink,and call pGrabber->startLive() in one Thread, and then moving worktable,snap image,save image,process Image in another thread. Unluckily I found that system always save the Last frame Image(before worktable moving) but not the Current Frame Image(after worktable moving). In second version, as above code(in fact, I have some clerical error: I have pGrabber->startLive() before while(g_AutoRunState ==1) and pGrabber->stopLive() after while),I also found that system save the Last frame Image but not the Current Frame Image.
It is noticeable that two versions of code are runing in multithread programme, does it have influence on image snapping?

thanks again for your help
he dongfeng

Stefan Geissler
January 22, 2013, 14:07:45
Hi

Just worth a try. What happens if you call
pSink->snapImages(2);
?



It is noticeable that two versions of code are runing in multithread programme, does it have influence on image snapping?

If they do not run at the same time, there should be no problem.

dongfenghe
January 24, 2013, 13:20:54
Hi

Just worth a try. What happens if you call
pSink->snapImages(2);
?


If they do not run at the same time, there should be no problem.

hi:
thanks for your help again!
I have a try in calling pSink->snapImages(2), unluckily,I have also got the same result. It is noticeable that I create Grabber and FrameHandlerSink, call pBrabber->startLive in my UI thread, call pSink->snapImages(2) in my work thread. Is it right?(When I call pSink->snapImages in same UI thread, It is seemly right)

yours He dongfeng

Stefan Geissler
January 24, 2013, 15:33:24
Well, accessing the grabber from different threads seems to be no good idea.