PDA

View Full Version : Snapshot problem



PAP
October 19, 2010, 22:54:41
Hi,

at first sorry for my english. I have USB camera DFx 21BUC03 and I would like to make simple program, which will sample scene every ~34 ms. I need to work with OpenCV. I have program, which sample only first image. Where is mistake?



int main(void)
{
LONG imSize;
BOOL result;
Grabber *pGrabber;
/* MemBufferCollection::tBmInfHPtr pInf;*/
tFrameHandlerSinkPtr pSink;
MemBufferCollection::tMemBufferPtr pBuffer;
IplImage *img;

pGrabber = new DShowLib::Grabber();
assert(pGrabber);

if( !DShowLib::InitLibrary( "...." ) )
{
printf("The library could not be initialized ");
printf("(invalid license key?).\n");
exit( 1 );
}

pGrabber->showDevicePage();
pSink = FrameHandlerSink::create(1);
pGrabber->setSinkType(pSink);
pGrabber->startLive(false);
cvNamedWindow("img",CV_WINDOW_AUTOSIZE);
imSize = IM_WIDTH * IM_HEIGHT * 32 / 8;
img = cvCreateImage( cvSize(744,480),IPL_DEPTH_8U , 4);

for(INT16 i = 0; i < 1000; i++)
{

pSink->snapImages(1);
pBuffer = pSink->getLastAcqMemBuffer();

/*pInf = pBuffer->getBitmapInfoHeader();*/
/*imSize = pInf->biWidth * pInf->biHeight * pInf->biBitCount / 8;*/

memcpy((unsigned char *)img->imageData, pBuffer->getPtr(), imSize);

cvShowImage("img",img);

Sleep(30);
}

pGrabber->stopLive();
pGrabber->closeDev();


pSink = NULL;
pBuffer = NULL;

cvDestroyWindow("img");
cvReleaseImage(&img);

return 0;
}


I thank for response ...

Michael Kirmse
October 20, 2010, 09:38:28
Hello PAP

I compiled your code on my computer and it works as expected.

PAP
October 20, 2010, 10:45:51
Hello PAP

I compiled your code on my computer and it works as expected.

Thanks Michael,
but did you get two differen image in two different steps "i"?

Michael Kirmse
October 20, 2010, 10:53:48
Yes, I did.

PAP
October 20, 2010, 11:58:44
Yes, I did.

You have right! Thanks!

I tested save images in loop and images were different. Problem will be in cvShowImage, because window "img" doesn't redraw. When I minimized and maximized "img" window, images was different.

The window freeze over and the image is overturned, I don't know why ...

PAP
October 20, 2010, 15:17:57
I solved problem with redraw window: With using Win API GetAcitveWindow and UpdateWindow.

Michael Kirmse
October 20, 2010, 15:41:39
I am very glad to hear this, thank you for the feedback.