The continuous acquisition is similar to the single capture. The only major difference is, that this sample will continuously request images from the device. This is done without the need of a separate thread here but instead the keyboard is checked for input after every image captured. This is not the most elegant approach but the most portable and simple in this scenario.
First of all the user is prompted to select the device he wants to use for this sample:
Then after the device has been initialised successfully image requests will constantly be sent to the drivers request queue and the application waits for the results:
int requestResult = DMR_NO_ERROR;
int requestCount = 0;
if( boSingleShotMode )
{
fi.imageRequestSingle();
++requestCount;
}
else
{
while( ( requestResult = fi.imageRequestSingle() ) == DMR_NO_ERROR )
{
++requestCount;
}
}
if( requestResult != DEV_NO_FREE_REQUEST_AVAILABLE )
{
cout << "Last result: " << requestResult << "(" << ImpactAcquireException::getErrorCodeAsString( requestResult ) << "), ";
}
cout << requestCount << " buffers requested";
if( ss.requestCount.hasMaxValue() )
{
cout << ", max request count: " << ss.requestCount.getMaxValue();
}
cout << endl;
cout << "Press <<ENTER>> to end the application!!" << endl;
manuallyStartAcquisitionIfNeeded( pDev, fi );
const Request* pRequest = 0;
const unsigned int timeout_ms = 8000;
int requestNr = -1;
bool boError = false;
while( !boError )
{
requestNr = fi.imageRequestWaitFor( timeout_ms );
if( fi.isRequestNrValid( requestNr ) )
{
pRequest = fi.getRequest( requestNr );
if( pRequest->isOK() )
{
}
else
{
cout << "*** Error: request not OK, result: " << pRequest->requestResult << endl;
boError = true;
}
fi.imageRequestUnlock( requestNr );
fi.imageRequestSingle();
}
else
{
cout << "imageRequestWaitFor failed (" << requestNr << ", " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << ")"
<< ", timeout value too small?" << endl;
boError = true;
}
if( waitForInput( 0, STDOUT_FILENO ) != 0 )
{
cout << " == " << __FUNCTION__ << " finished by user - " << endl;
break;
}
}
The image attached to the request can then be processed and/or displayed if the request does not report an error.
When the image is no longer needed you have to unlock the image buffer as otherwise the driver will refuse to use it again. This makes sure, that no image, that is still used by the user will be overwritten by the device:
#ifdef _MSC_VER
# if _MSC_VER < 1300
# pragma warning( disable : 4786 )
# endif
#endif
#include <windows.h>
#include <process.h>
#include <iostream>
#include <apps/Common/exampleHelper.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#include <mvDisplay/Include/mvIMPACT_acquire_display.h>
using namespace std;
static bool s_boTerminated = false;
struct ThreadParameter
{
ThreadParameter(
Device* p,
const string& windowTitle ) : pDev( p ), displayWindow( windowTitle ) {}
};
unsigned int __stdcall liveThread( void* pData )
{
ThreadParameter* pThreadParameter = reinterpret_cast<ThreadParameter*>( pData );
cout << "Initialising the device. This might take some time..." << endl;
try
{
pThreadParameter->pDev->open();
}
{
cout << "An error occurred while opening the device " << pThreadParameter->pDev->serial.read()
<< "Press [ENTER] to end the application..." << endl;
cin.get();
return 0;
}
ImageDisplay& display = pThreadParameter->displayWindow.GetImageDisplay();
while( ( result =
static_cast<TDMR_ERROR>( fi.imageRequestSingle() ) ) == DMR_NO_ERROR ) {};
if( result != DEV_NO_FREE_REQUEST_AVAILABLE )
{
cout << "'FunctionInterface.imageRequestSingle' returned with an unexpected result: " << result
}
manuallyStartAcquisitionIfNeeded( pThreadParameter->pDev, fi );
const unsigned int timeout_ms = 500;
unsigned int cnt = 0;
while( !s_boTerminated )
{
int requestNr = fi.imageRequestWaitFor( timeout_ms );
pRequest = fi.isRequestNrValid( requestNr ) ? fi.getRequest( requestNr ) : 0;
if( pRequest )
{
{
++cnt;
if( cnt % 100 == 0 )
{
cout << "Info from " << pThreadParameter->pDev->serial.read()
<< ": " << statistics.framesPerSecond.name() << ": " << statistics.framesPerSecond.readS()
<< ", " << statistics.errorCount.name() << ": " << statistics.errorCount.readS()
<< ", " << statistics.captureTime_s.name() << ": " << statistics.captureTime_s.readS() << endl;
}
}
else
{
}
if( pPreviousRequest )
{
}
pPreviousRequest = pRequest;
fi.imageRequestSingle();
}
}
manuallyStopAcquisitionIfNeeded( pThreadParameter->pDev, fi );
if( pRequest )
{
}
fi.imageRequestReset( 0, 0 );
return 0;
}
int main( void )
{
Device* pDev = getDeviceFromUserInput( devMgr );
if( !pDev )
{
cout << "Unable to continue! Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
cout << "Press [ENTER] to end the application" << endl;
unsigned int dwThreadID;
string windowTitle(
"mvIMPACT_acquire sample, Device " + pDev->
serial.
read() );
ThreadParameter threadParam( pDev, windowTitle );
HANDLE hThread = ( HANDLE )_beginthreadex( 0, 0, liveThread, ( LPVOID )( &threadParam ), 0, &dwThreadID );
cin.get();
s_boTerminated = true;
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
return 0;
}
Grants access to devices that can be operated by this software interface.
Definition: mvIMPACT_acquire.h:6990
This class and its functions represent an actual device detected by this interface in the current sys...
Definition: mvIMPACT_acquire.h:5951
PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition: mvIMPACT_acquire.h:6383
The function interface to devices supported by this interface.
Definition: mvIMPACT_acquire.h:10473
A base class for exceptions generated by Impact Acquire.
Definition: mvIMPACT_acquire.h:251
std::string getErrorCodeAsString(void) const
Returns a string representation of the error associated with the exception.
Definition: mvIMPACT_acquire.h:283
std::string read(int index=0) const
Reads a value from a property.
Definition: mvIMPACT_acquire.h:5162
std::string readS(int index=0, const std::string &format="") const
Reads data from this property as a string.
Definition: mvIMPACT_acquire.h:3216
Contains information about a captured buffer.
Definition: mvIMPACT_acquire.h:8449
bool isOK(void) const
Convenience function to check if a request has been processed successfully.
Definition: mvIMPACT_acquire.h:9224
PropertyIRequestResult requestResult
An enumerated integer property (read-only) defining the result of this request.
Definition: mvIMPACT_acquire.h:9530
int unlock(void)
Unlocks the request for the driver again.
Definition: mvIMPACT_acquire.h:9364
Contains basic statistical information.
Definition: mvIMPACT_acquire.h:14201
A class that can be used to display images in a window.
Definition: mvIMPACT_acquire_display.h:585
A class that can be used for displaying images within existing windows or GUI elements that can provi...
Definition: mvIMPACT_acquire_display.h:175
void RemoveImage(void)
Removes the current image from the display.
Definition: mvIMPACT_acquire_display.h:374
void SetImage(const void *pData, int width, int height, int bitsPerPixel, int pitch)
Sets the next image to display.
Definition: mvIMPACT_acquire_display.h:295
void Update(void) const
Immediately redraws the current image.
Definition: mvIMPACT_acquire_display.h:384
TDMR_ERROR
Errors reported by the device manager.
Definition: mvDriverBaseEnums.h:2591
@ DMR_NO_ERROR
The function call was executed successfully.
Definition: mvDriverBaseEnums.h:2596
This namespace contains classes and functions that can be used to display images.
This namespace contains classes and functions belonging to the image acquisition module of this SDK.
Definition: mvCommonDataTypes.h:30