that_pic
July 29, 2010, 18:55:01
Hi I am having some trouble getting the camera to work with an external trigger and to use the captured buffer in an IplImage for opencv.
I know the hardware trigger works because I have verified this with IC Capture. The issue seems to be when I run my code I am not getting the image off of the buffer in the camera. The viewer window I have setup in opencv just remains blank I guess my problem is in extracting the image off the buffer or maybe setting up the trigger?
I saw in some previous posts that Stefan said you should use the callback function instead of snapImages because snapImages is a blocking call.
Here is what I believe to be the relevant portions of my code, the callback function and main code.
Thanks
void CListener::frameReady( Grabber& caller, smart_ptr<MemBuffer> pBuffer, DWORD currFrame)
{
memcpy(input->imageData, pBuffer->getPtr(), 640*480);
cvShowImage("Input", input); //show image
key = cvWaitKey(10);
}
(From main)
Grabber grabber;
CListener *pListener = new CListener();
// Disable overlay. If it was in the graph, we could not get UYVY images.
grabber.setOverlayBitmapPathPosition( ePP_NONE );
grabber.addListener(pListener, GrabberListener::eFRAMEREADY);
if( !setupDeviceFromFile( grabber ) )
{
return -1;
}
{
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( eY800, 1 );
// We use snap mode.
pSink->setSnapMode( true );
grabber.setSinkType( pSink );
// Prepare the live mode, to get the output size if the sink.
if( !grabber.prepareLive( false ) )
{
printf("Could not render the VideoFormat into the sink. \n");
exit(0);
}
FrameTypeInfo info;
pSink->getOutputFrameType( info );
BYTE** pBuf = (BYTE **)malloc(nPics*sizeof(BYTE *));
BYTE* buffer = new BYTE[640*480*NPICS];
for( int i = 0; i < nPics; ++i )
{
pBuf[i] = new BYTE[info.buffersize];
}
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, nPics, pBuf );
if( pCollection == 0 || !pSink->setMemBufferCollection( pCollection ) )
{
std::cerr << "Could not set the new MemBufferCollection, because types do not match.";
}
// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive(false);
sleep(1000);
grabber.setExternalTrigger(true);
I know the hardware trigger works because I have verified this with IC Capture. The issue seems to be when I run my code I am not getting the image off of the buffer in the camera. The viewer window I have setup in opencv just remains blank I guess my problem is in extracting the image off the buffer or maybe setting up the trigger?
I saw in some previous posts that Stefan said you should use the callback function instead of snapImages because snapImages is a blocking call.
Here is what I believe to be the relevant portions of my code, the callback function and main code.
Thanks
void CListener::frameReady( Grabber& caller, smart_ptr<MemBuffer> pBuffer, DWORD currFrame)
{
memcpy(input->imageData, pBuffer->getPtr(), 640*480);
cvShowImage("Input", input); //show image
key = cvWaitKey(10);
}
(From main)
Grabber grabber;
CListener *pListener = new CListener();
// Disable overlay. If it was in the graph, we could not get UYVY images.
grabber.setOverlayBitmapPathPosition( ePP_NONE );
grabber.addListener(pListener, GrabberListener::eFRAMEREADY);
if( !setupDeviceFromFile( grabber ) )
{
return -1;
}
{
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( eY800, 1 );
// We use snap mode.
pSink->setSnapMode( true );
grabber.setSinkType( pSink );
// Prepare the live mode, to get the output size if the sink.
if( !grabber.prepareLive( false ) )
{
printf("Could not render the VideoFormat into the sink. \n");
exit(0);
}
FrameTypeInfo info;
pSink->getOutputFrameType( info );
BYTE** pBuf = (BYTE **)malloc(nPics*sizeof(BYTE *));
BYTE* buffer = new BYTE[640*480*NPICS];
for( int i = 0; i < nPics; ++i )
{
pBuf[i] = new BYTE[info.buffersize];
}
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, nPics, pBuf );
if( pCollection == 0 || !pSink->setMemBufferCollection( pCollection ) )
{
std::cerr << "Could not set the new MemBufferCollection, because types do not match.";
}
// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive(false);
sleep(1000);
grabber.setExternalTrigger(true);