PDA

View Full Version : External Trigger & snapImages for Sony DFW-X700



mrafique
June 29, 2004, 23:20:16
Hi, I'm using IC Imaging Control 1.4 1 for capturing images from a pair of Sony DFW-X700 cameras.

I would like to synchronize the images captured from the cameras, therefore I am using an external trigger (through the parallel port).

My problem is that when I trigger the cameras, I call snapImages(1,1000) to capture the triggered image from the left and right cameras. The snapImages works for the left camera, but when I call it for the right camera it fails.

If I reverse the calling order (i.e. call snapImages for the right camera first), snapImages fails on the left camera.

Why is this happening ??

Does the image that was captured using the trigger, disappear if I wait too long?


This is the code I am using




if( !DShowLib::InitLibrary( 0 ) )
{
printf("Error - Invalid Key");
return 0;
}
DShowLib::Grabber* m_rightCamera = new DShowLib::Grabber;
DShowLib::Grabber* m_leftCamera = new DShowLib::Grabber;

// 2.0 Enumerate devices on each camera
DShowLib::Grabber::tVidCapDevListPtr
pVidCapDevList;

// 2.1 Enumerate devices on left Camera
pVidCapDevList = m_leftCamera->getAvailableVideoCaptureDevices();

// 2.1.1 Check for errors
if (pVidCapDevList==0)
{
if (m_leftCamera->getLastError())
{
cout << m_leftCamera->getLastError().c_str() << endl;
return 0;
}
else
{
cout << "Unable to get a list of devices" << endl;
return 0;
}
}
// Enough Cameras ?
if (pVidCapDevList->size() !=2)
{
cout << "Not Enough Cameras connected" << endl;
return 0;
}

m_rightCamera->openDev((*pVidCapDevList)[0]);
m_leftCamera->openDev((*pVidCapDevList)[1]);

DShowLib::Grabber::tVidFmtListPtr pVideoFormats
= m_rightCamera->getAvailableVideoFormats();

m_leftCamera->setVideoFormat( (*pVideoFormats)[2] );
m_rightCamera->setVideoFormat( (*pVideoFormats)[2] );

// 3.0 Engage the trigger
m_leftCamera->setFrameRate(133);
m_rightCamera->setFrameRate(133);

DShowLib::Grabber::tMemBufferCollectionPtr pLeftMemBufferCollection,
pRightMemBufferCollection;

pLeftMemBufferCollection = m_rightCamera->newMemBufferCollection(5);
pRightMemBufferCollection = m_leftCamera->newMemBufferCollection(5);

DShowLib::Grabber::tMemBufferPtr pLeftMemBuffer, pRightMemBuffer;

if (!m_rightCamera->setActiveMemBufferCollection(pRightMemBufferCollec tion))
{
printf("Error - Setting Left Active Buffer\n");
}
if (!m_leftCamera->setActiveMemBufferCollection(pLeftMemBufferCollect ion))
{
printf("Error - Setting Right Active Buffer\n");
}

if (!m_rightCamera->isDevOpen() || !m_leftCamera->isDevOpen())
{
printf("ERROR - DEVICES NOT OPEN");
}
if (!m_leftCamera->setExternalTrigger(true))
printf("Error - Left External Trigger\n");
if (!m_leftCamera->startLive(false))
printf("Error - Start Left Streaming\n");

if (!m_rightCamera->setExternalTrigger(true))
printf("Error - Right External Trigger\n");
if (!m_rightCamera->startLive(false))
printf("Error - Start Right Streaming\n");
Out32(888,255);
Sleep(1);

char filename[255];
double deftime1=0,deftime2=0;
// 4.0 Capture as fast as possilbe
for (int i=1; i <= 10; i++)
{
cout << "****** Trial #: " << i << endl;
cout << endl;
cout << endl;
// Capture the files
deftime1=clock();

Out32(888,0);

if (!m_rightCamera->snapImages(1,180))
cout << "Error snapImages in Right" << endl;
if (!m_leftCamera->snapImages(1,180))
cout << "Error snapImages in Left" << endl;

Out32(888,255);
deftime2=clock();
printf("Capture time: %.3f\n",(deftime2-deftime1) / CLOCKS_PER_SEC);

pLeftMemBuffer = m_leftCamera->getActiveMemBuffer();
pRightMemBuffer = m_rightCamera->getActiveMemBuffer();

// Save the files
if (pLeftMemBuffer!=NULL)
{
sprintf(&filename[0],"left%03d.bmp",i);
pLeftMemBuffer->save(filename);
}
else
cout << "Error in left buffer" << endl;

if (pRightMemBuffer!=NULL)
{
sprintf(&filename[0],"right%03d.bmp",i);
pRightMemBuffer->save(filename);
}
else
printf("Error in right buffer\n");
cout << endl;
cout << endl;
}
m_rightCamera->closeDev();
m_leftCamera->closeDev();
delete m_leftCamera;
delete m_rightCamera;

return 0;

Stefan Geissler
June 30, 2004, 14:54:26
Hello,

The problem of your program is, that snapImages() returns after an image was delivered or the timeout occurred. If snapImages() is called, it waits for the next delivered frame of your camera. Therefore it worked for the first camera. But the second one delivered a frame at the same time. If snapImages() is called for the second camera, the frame has been delivered previously and snapImages() waits for the next frame.

The solution is to use the FrameGrabberSink with the “eGRAB” sinkmode. This means, that every frame which is delivered by the camera, is saved into memory automatically. In your case, frames are delivered only if the cameras are triggered. A call to snapImages() is not longer needed.

Setup the FrameGrabberSink for both grabbers:


m_rightCamera->setSinkType( DshowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eGR AB, DShowLib::eRGB24 ) );
m_leftCamera->setSinkType( DshowLib::FrameGrabberSink(
DShowLib::FrameGrabberSink::tFrameGrabberMode::eGR AB, DShowLib::eRGB24 ) );


Then create the membuffer collections and call startLive() for both grabbers.
After you have initiated the trigger, you can access both images with:


pLeftMemBuffer = m_leftCamera->getActiveMemBuffer();
pRightMemBuffer = m_rightCamera->getActiveMemBuffer();

mrafique
July 7, 2004, 01:48:48
Thanks Stefan,
it worked :)