PDA

View Full Version : DFK 22BUC03 testing (OpencV, GPIO and Frames/second)



manueldejodar
December 8, 2016, 08:37:19
Hi Stefan

I have tested DFK 22BUC03, I would like to do the following points:
- Software by OpenCv
- Depend on the algoritm use an external output to active a sensor.
I have used the example MemBuffer in OpenCv but the system is not quick enough, I couldn’t get 50 frames/second.
Here you are the configuration I have selected:

- 320x240 pixels B/N and also (RGB24).
-Exposure time 1/5000 s.
-Nº frames: 160

Please take a look the following script, I only need to test the camera and check if it is enough quick according to the points above. Also I included the configuration of Serial port in order to test an external signal to a simple hardware (Arduino), instead of use GPIO port, according to specifications this camera could use GPIO, but I only found Strobbe function, please clarify If this option is available and How can I use it?

I am pretty sure the script is not the most efficiency, maybe there is something wrong, I think the “for loop” is not the best way.
There are not too much information about OpenCv and IS.

Finally, could you provide a simple script in OpenCV to test the speed of the camera and GPIO port?

Script en C++:

///////////////////////////////////////////////////////////////////////////////
// This example demonstrates how to setup a MemBuffer collection and use it to
// capture images.

#define _WIN32_WINNT 0x0500
#include <iostream>

#include <C:\Users\Antonio\Documents\IC Imaging Control 3.4\classlib\include\tisudshl.h>
#include <C:\Users\Antonio\Documents\IC Imaging Control 3.4\samples\vc10\Common\CmdHelper.h>
#include <opencv2\opencv.hpp>
#include <Windows.h>
#include "SerialClass.h"

using namespace _DSHOWLIB_NAMESPACE;
using namespace cv;
using namespace std;


int main(int argc, char* argv[])
{

//Serial Port configuration
//Send a character in order to test external communication with hw Arduino
char palabra[] = "A";
//
Serial* Arduino = new Serial("COM3");
//while (Arduino->IsConnected()) {

// Initialize the library.
DShowLib::InitLibrary();

Grabber grabber;
if( !setupDeviceFromFile( grabber ) )
{
return -1;
}

grabber.setOverlayBitmapPathPosition( ePP_NONE );

// Set the image buffer format to RGB24.
// Let the sink create a matching MemBufferCollection with 1 buffer.
//tFrameHandlerSinkPtr pSink = FrameHandlerSink::create( eY800, 1 );
tFrameHandlerSinkPtr pSink = FrameHandlerSink::create(eRGB24, 1);
//tFrameHandlerSinkPtr pSink = FrameHandlerSink::create(eRGB8, 1);

// We use snap mode.
pSink->setSnapMode( true );

// Set the sink.
grabber.setSinkType( pSink );

//// Prepare the live mode, to get the output size if the sink.
if( !grabber.prepareLive( false ) )
{
std::cerr << "Could not render the VideoFormat into a eY800 sink.";
return -1;
}

// Retrieve the output type and dimension of the handler sink.
// The dimension of the sink could be different from the VideoFormat, when
// you use filters.
FrameTypeInfo info;
pSink->getOutputFrameType( info );

BYTE* pBuf[1];
// Allocate 5 image buffers of the above calculate buffer size.
for( int i = 0; i < 1; ++i )
{
pBuf[i] = new BYTE[info.buffersize];
}

// Create a new MemBuffer collection that uses our own image buffers.
tMemBufferCollectionPtr pCollection = MemBufferCollection::create( info, 1, pBuf );
if( pCollection == 0 || !pSink->setMemBufferCollection( pCollection ) )
{
std::cerr << "Could not set the new MemBufferCollection, because types do not match.";
return -1;
}

//************************************************** **************************************
// 100 frames to test
for (int j = 0; j < 100; ++j)
{

// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive( false );

// Snap 1 image. The images are copied to the MemBufferCollection the
// application created above.
pSink->snapImages( 1 );

// Stop the live video.
grabber.stopLive();

//Monitorizamos con OpenCV la captura
//Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC3);
memcpy(newImg.ptr(), pBuf[0], info.buffersize);
imshow("cap", newImg);

// Send a character to Arduino
Arduino->WriteData(palabra, sizeof(palabra) - 1);

//Esperamos 1 ms
//waitKey(1);

}
//************************************************** **************************************

// Close the device.
grabber.closeDev();

return 0;
}

Stefan Geissler
December 8, 2016, 14:08:53
Hello

Your code at


for (int j = 0; j < 100; ++j)
{

// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive( false );

// Snap 1 image. The images are copied to the MemBufferCollection the
// application created above.
pSink->snapImages( 1 );

// Stop the live video.
grabber.stopLive();

//Monitorizamos con OpenCV la captura
//Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC3);
memcpy(newImg.ptr(), pBuf[0], info.buffersize);
imshow("cap", newImg);

// Send a character to Arduino
Arduino->WriteData(palabra, sizeof(palabra) - 1);

//Esperamos 1 ms
//waitKey(1);

}


Is indeed slow. Move the start and stop outside the loop:
// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive( false );



for (int j = 0; j < 100; ++j)
{

// Snap 1 image. The images are copied to the MemBufferCollection the
// application created above.
pSink->snapImages( 1 );

// Stop the live video.

//Monitorizamos con OpenCV la captura
//Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC3);
memcpy(newImg.ptr(), pBuf[0], info.buffersize);
imshow("cap", newImg);

// Send a character to Arduino
Arduino->WriteData(palabra, sizeof(palabra) - 1);

//Esperamos 1 ms
//waitKey(1);

}
grabber.stopLive();



Finally, could you provide a simple script in OpenCV to test the speed of the camera and GPIO port?
No. That is not part of what OpenCV can do.

The GPOut is the same pin as the strobe. And both are Open Drain / Open Collector, not TTL

manueldejodar
December 13, 2016, 22:22:42
Hello

Your code at


for (int j = 0; j < 100; ++j)
{

// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive( false );

// Snap 1 image. The images are copied to the MemBufferCollection the
// application created above.
pSink->snapImages( 1 );

// Stop the live video.
grabber.stopLive();

//Monitorizamos con OpenCV la captura
//Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC3);
memcpy(newImg.ptr(), pBuf[0], info.buffersize);
imshow("cap", newImg);

// Send a character to Arduino
Arduino->WriteData(palabra, sizeof(palabra) - 1);

//Esperamos 1 ms
//waitKey(1);

}


Is indeed slow. Move the start and stop outside the loop:
// Start live mode for fast snapping. The live video will not be displayed,
// because false is passed to startLive().
grabber.startLive( false );



for (int j = 0; j < 100; ++j)
{

// Snap 1 image. The images are copied to the MemBufferCollection the
// application created above.
pSink->snapImages( 1 );

// Stop the live video.

//Monitorizamos con OpenCV la captura
//Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC1, Scalar(0));
Mat newImg = Mat(info.dim.cy, info.dim.cx, CV_8UC3);
memcpy(newImg.ptr(), pBuf[0], info.buffersize);
imshow("cap", newImg);

// Send a character to Arduino
Arduino->WriteData(palabra, sizeof(palabra) - 1);

//Esperamos 1 ms
//waitKey(1);

}
grabber.stopLive();



No. That is not part of what OpenCV can do.

The GPOut is the same pin as the strobe. And both are Open Drain / Open Collector, not TTL

Hi Stefan,

Exactly the code is working, and we have tested succesfully the camera, but I would like to ask you if you could provide a specific hardware to process 50 frames/sec, the final code is more complex and we only get 50 frames/sec with a high level of computer. I am pretty sure there is a more simple computer which we can get 50 frames/sec. Could you recommend hardware to get it?

Thanks.