#ifdef _MSC_VER
# if _MSC_VER < 1300
# pragma warning( disable : 4786 )
# endif
#endif
#include <algorithm>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <apps/Common/exampleHelper.h>
#include <common/crt/mvstdio.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h>
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
# include <windows.h>
# include <process.h>
# include <mvDisplay/Include/mvIMPACT_acquire_display.h>
# define USE_DISPLAY
#else
# include <unistd.h>
#endif
using namespace std;
static bool s_boTerminated = false;
struct ThreadParameter
{
#ifdef USE_DISPLAY
#endif
explicit ThreadParameter(
Device* p ) : pDev( p )
#ifdef USE_DISPLAY
, displayWindow(
"mvIMPACT_acquire sample, Device " + pDev->
serial.
read() )
#endif
{}
};
static void configureDevice(
Device* pDev );
static void configureBlueCOUGAR_X(
Device* pDev );
static void configureVirtualDevice(
Device* pDev );
static bool isDeviceSupportedBySample(
const Device*
const pDev );
static unsigned int DMR_CALL liveThread( void* pData );
static void reportProblemAndExit(
Device* pDev,
const string& prologue,
const string& epilogue =
"" );
inline bool isBlueCOUGAR_X(
const Device*
const pDev )
{
return ( pDev->
product.
read().find(
"mvBlueCOUGAR-X" ) == 0 ) ||
( pDev->
product.
read().find(
"mvBlueCOUGAR-2X" ) == 0 ) ||
( pDev->
product.
read().find(
"mvBlueCOUGAR-3X" ) == 0 );
}
void configureDevice(
Device* pDev )
{
{
configureVirtualDevice( pDev );
}
else if( isBlueCOUGAR_X( pDev ) )
{
configureBlueCOUGAR_X( pDev );
}
else
{
reportProblemAndExit( pDev, "The selected device is not supported by this application!" );
}
}
void configureVirtualDevice(
Device* pDev )
{
if( !cs.bufferPartCount.isValid() )
{
reportProblemAndExit( pDev, "This version of the mvVirtualDevice driver does not support the multi-part format. An update will fix this problem!" );
}
cs.bufferPartCount.write( cs.bufferPartCount.getMaxValue() );
cs.frameDelay_us.write( 200000 );
}
void configureBlueCOUGAR_X(
Device* pDev )
{
usc.userSetSelector.writeS( "Default" );
usc.userSetLoad.call();
if( !tlc.gevGVSPExtendedIDMode.isValid() )
{
reportProblemAndExit( pDev, "This device does not support the multi-part format. A firmware update will fix this problem!" );
}
tlc.gevGVSPExtendedIDMode.writeS( "On" );
ac.mvFeatureMode.writeS( "mvJPEGWithRaw" );
}
bool isDeviceSupportedBySample(
const Device*
const pDev )
{
return ( pDev->
product.
read() ==
"VirtualDevice" ) || isBlueCOUGAR_X( pDev );
}
void storeBufferPartToDisc(
Device* pDev,
const Request* pRequest,
const BufferPart& bufferPart,
unsigned int partIndex,
const string& fileExtension )
{
ostringstream oss;
oss << "Buffer.part" << partIndex
<<
"id" << std::setfill(
'0' ) << std::setw( 16 ) << pRequest->
infoFrameID.
read() <<
"."
<< fileExtension;
FILE* pFile = mv_fopen_s( oss.str().c_str(), "wb" );
if( pFile )
{
{
reportProblemAndExit( pDev, "Could not write file '" + oss.str() + "'" );
}
cout <<
"Buffer Part handled: " << bufferPart.
dataType.
readS() <<
"(index " << partIndex <<
"): Stored to disc as '" << oss.str() <<
"'." << endl;
fclose( pFile );
}
}
unsigned int DMR_CALL liveThread( void* pData )
{
ThreadParameter* pThreadParameter = reinterpret_cast<ThreadParameter*>( pData );
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();
if( bufferPartCount == 0 )
{
cout << " NOT running in multi-part mode";
}
else
{
cout << " running in multi-part mode, delivering " << bufferPartCount << " parts";
}
cout << ": " << statistics.framesPerSecond.name() << ": " << statistics.framesPerSecond.readS()
<< ", " << statistics.errorCount.name() << ": " << statistics.errorCount.readS()
<< ", " << statistics.captureTime_s.name() << ": " << statistics.captureTime_s.readS() << endl;
}
if( bufferPartCount == 0 )
{
#ifdef USE_DISPLAY
ImageDisplay& display = pThreadParameter->displayWindow.GetImageDisplay();
#else
#endif
}
else
{
#ifdef USE_DISPLAY
bool boImageDisplayed = false;
ImageDisplay& display = pThreadParameter->displayWindow.GetImageDisplay();
#endif
for( unsigned int i = 0; i < bufferPartCount; i++ )
{
{
{
#ifdef USE_DISPLAY
if( !boImageDisplayed )
{
boImageDisplayed = true;
}
else
#endif
{
}
}
break;
storeBufferPartToDisc( pThreadParameter->pDev, pRequest, bufferPart, i, "jpeg" );
break;
storeBufferPartToDisc( pThreadParameter->pDev, pRequest, bufferPart, i, "chunk" );
break;
storeBufferPartToDisc( pThreadParameter->pDev, pRequest, bufferPart, i, "xml" );
break;
storeBufferPartToDisc( pThreadParameter->pDev, pRequest, bufferPart, i, "h264" );
break;
cout << "Buffer Part" << "(index " << i << ") has an unknown data type. Skipped!" << endl;
break;
}
}
}
}
else
{
}
if( pPreviousRequest )
{
}
pPreviousRequest = pRequest;
fi.imageRequestSingle();
}
else
{
cout << "imageRequestWaitFor failed (" << requestNr << ", " << ImpactAcquireException::getErrorCodeAsString( requestNr ) << ")"
<< ", timeout value too small?" << endl;
}
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__APPLE__)
s_boTerminated = waitForInput( 0, STDOUT_FILENO ) == 0 ? false : true;
#endif
}
manuallyStopAcquisitionIfNeeded( pThreadParameter->pDev, fi );
#ifdef USE_DISPLAY
pThreadParameter->displayWindow.GetImageDisplay().RemoveImage();
#endif
if( pRequest )
{
}
fi.imageRequestReset( 0, 0 );
return 0;
}
void reportProblemAndExit(
Device* pDev,
const string& prologue,
const string& epilogue )
{
<< "Press [ENTER] to end the application..." << endl;
cin.get();
exit( 42 );
}
int main( void )
{
Device* pDev = getDeviceFromUserInput( devMgr, isDeviceSupportedBySample );
if( !pDev )
{
cout << "Unable to continue! Press [ENTER] to end the application" << endl;
cin.get();
return 1;
}
try
{
cout << "Initialising the device. This might take some time..." << endl << endl;
}
{
cout <<
"An error occurred while opening device " << pDev->
serial.
read()
<< "Press [ENTER] to end the application..." << endl;
cin.get();
return 1;
}
try
{
configureDevice( pDev );
cout << "Press [ENTER] to end the application" << endl;
ThreadParameter threadParam( pDev );
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
unsigned int dwThreadID;
HANDLE hThread = ( HANDLE )_beginthreadex( 0, 0, liveThread, ( LPVOID )( &threadParam ), 0, &dwThreadID );
cin.get();
s_boTerminated = true;
WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
#else
liveThread( &threadParam );
#endif
}
{
cout <<
"An error occurred while setting up device " << pDev->
serial.
read()
<< "Press [ENTER] to end the application..." << endl;
cin.get();
return 1;
}
return 0;
}
Contains information about a specific part of a captured buffer.
Definition mvIMPACT_acquire.h:8410
const ImageBufferDesc & getImageBufferDesc(void) const
Returns a const reference to the image buffer descriptor of this buffer part.
Definition mvIMPACT_acquire.h:8465
PropertyI64 dataSize
A 64-bit integer property (read-only) containing the size (in bytes) of this buffer part.
Definition mvIMPACT_acquire.h:8508
PropertyI64 width
A 64-bit integer property (read-only) containing the width of the buffer part in pixels.
Definition mvIMPACT_acquire.h:8520
PropertyI64BufferPartDataType dataType
An enumerated 64-bit integer property (read-only) containing the data type of this buffer part.
Definition mvIMPACT_acquire.h:8513
PropertyI64 offsetY
A 64-bit integer property (read-only) containing the Y-offset of the buffer part in pixels.
Definition mvIMPACT_acquire.h:8526
PropertyPtr address
A pointer property (read-only) containing the start address of this buffer part.
Definition mvIMPACT_acquire.h:8502
PropertyI64 height
A 64-bit integer property (read-only) containing the height of the buffer part in pixels.
Definition mvIMPACT_acquire.h:8522
PropertyI64 offsetX
A 64-bit integer property (read-only) containing the X-offset of the buffer part in pixels.
Definition mvIMPACT_acquire.h:8524
mvVirtualDevice related camera settings(Device specific interface layout only).
Definition mvIMPACT_acquire.h:18872
Grants access to devices that can be operated by this software interface.
Definition mvIMPACT_acquire.h:7171
This class and its functions represent an actual device detected by this interface in the current sys...
Definition mvIMPACT_acquire.h:6118
PropertyI firmwareVersion
An integer property (read-only) containing the firmware version of this device.
Definition mvIMPACT_acquire.h:6610
PropertyS product
A string property (read-only) containing the product name of this device.
Definition mvIMPACT_acquire.h:6537
PropertyS serial
A string property (read-only) containing the serial number of this device.
Definition mvIMPACT_acquire.h:6551
void open(void)
Opens a device.
Definition mvIMPACT_acquire.h:6420
ZYX read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:4907
ZYX read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:4300
The function interface to devices supported by this interface.
Definition mvIMPACT_acquire.h:10758
Category for the acquisition and trigger control features.
Definition mvIMPACT_acquire_GenICam.h:2115
Category that contains the transport Layer control features.
Definition mvIMPACT_acquire_GenICam.h:13070
Category that contains the User Set control features.
Definition mvIMPACT_acquire_GenICam.h:9632
ImageBuffer * getBuffer(void) const
Grants access to the underlying mvIMPACT::acquire::ImageBuffer structure managed by this object.
Definition mvIMPACT_acquire.h:8313
A base class for exceptions generated by Impact Acquire.
Definition mvIMPACT_acquire.h:256
std::string getErrorCodeAsString(void) const
Returns a string representation of the error associated with the exception.
Definition mvIMPACT_acquire.h:288
void * read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:5176
std::string read(int index=0) const
Reads a value from a property.
Definition mvIMPACT_acquire.h:5323
std::string readS(int index=0, const std::string &format="") const
Reads data from this property as a string.
Definition mvIMPACT_acquire.h:3340
Contains information about a captured buffer.
Definition mvIMPACT_acquire.h:8640
PropertyI64 infoFrameID
A 64 bit integer property (read-only) containing a frame identifier.
Definition mvIMPACT_acquire.h:9849
PropertyI imageHeight
An integer property (read-only) containing the height of the image in pixels.
Definition mvIMPACT_acquire.h:10331
bool isOK(void) const
Convenience function to check if a request has been processed successfully.
Definition mvIMPACT_acquire.h:9474
PropertyIRequestResult requestResult
An enumerated integer property (read-only) defining the result of this request.
Definition mvIMPACT_acquire.h:9780
PropertyI imageWidth
An integer property (read-only) containing the width of the image in pixels.
Definition mvIMPACT_acquire.h:10320
unsigned int getBufferPartCount(void) const
Returns the number of buffer parts currently associated with this request.
Definition mvIMPACT_acquire.h:8997
int unlock(void)
Unlocks the request for the driver again.
Definition mvIMPACT_acquire.h:9614
PropertyI64 infoTimeStamp_us
A 64 bit integer property (read-only) containing a timestamp to define the exact time this image has ...
Definition mvIMPACT_acquire.h:9913
PropertyI imageOffsetX
An integer property (read-only) containing the X-offset of the image in pixels.
Definition mvIMPACT_acquire.h:10312
BufferPart & getBufferPart(unsigned int index) const
Returns a reference to a buffer part descriptor of this request.
Definition mvIMPACT_acquire.h:9023
PropertyI imageOffsetY
An integer property (read-only) containing the Y-offset of the image in pixels.
Definition mvIMPACT_acquire.h:10318
Contains basic statistical information.
Definition mvIMPACT_acquire.h:14509
A class that can be used to display images in a window.
Definition mvIMPACT_acquire_display.h:606
A class that can be used for displaying images within existing windows or GUI elements that can provi...
Definition mvIMPACT_acquire_display.h:176
void SetImage(const void *pData, int width, int height, int bitsPerPixel, int pitch)
Sets the next image to display.
Definition mvIMPACT_acquire_display.h:316
void Update(void) const
Immediately redraws the current image.
Definition mvIMPACT_acquire_display.h:405
TDMR_ERROR
Errors reported by the device manager.
Definition mvDriverBaseEnums.h:2601
@ DMR_NO_ERROR
The function call was executed successfully.
Definition mvDriverBaseEnums.h:2603
@ bpdtGDC_JPEG
JPEG image data (GenDC).
Definition TBufferPartDataType.h:134
@ bpdt3DPlaneTriplanar
Single color plane of a planar (3D) image (GenTL).
Definition TBufferPartDataType.h:86
@ bpdt3DImage
3D image (pixel coordinates) (GenTL).
Definition TBufferPartDataType.h:74
@ bpdtGDC_GenICamXML
GenICam XML data (GenDC).
Definition TBufferPartDataType.h:124
@ bpdt3DPlaneBiplanar
Single color plane of a planar (3D) image (GenTL).
Definition TBufferPartDataType.h:80
@ bpdt2DImage
Color or monochrome (2D) image (GenTL).
Definition TBufferPartDataType.h:51
@ bpdtConfidenceMap
Confidence of the individual pixel values (GenTL).
Definition TBufferPartDataType.h:99
@ bpdtJPEG
JPEG image data (GenTL).
Definition TBufferPartDataType.h:108
@ bpdtGDC_2DImage
Color or monochrome (2D) image (GenDC).
Definition TBufferPartDataType.h:129
@ bpdtUnknown
The framework is not aware of the data type of the data in the provided buffer part.
Definition TBufferPartDataType.h:46
@ bpdtGenICamChunkData
Chunk data (GenTL).
Definition TBufferPartDataType.h:106
@ bpdt3DPlaneQuadplanar
Single color plane of a planar (3D) image (GenTL).
Definition TBufferPartDataType.h:92
@ bpdt2DPlaneBiplanar
Single color plane of a planar (2D) image (GenTL).
Definition TBufferPartDataType.h:57
@ bpdtJPEG2000
JPEG 2000 image data (GenTL).
Definition TBufferPartDataType.h:110
@ bpdt2DPlaneTriplanar
Single color plane of a planar (2D) image (GenTL).
Definition TBufferPartDataType.h:63
@ bpdtGDC_JPEG2000
JPEG 2000 image data (GenDC).
Definition TBufferPartDataType.h:139
@ bpdtGDC_H264
A H.264 buffer (GenDC).
Definition TBufferPartDataType.h:146
@ bpdtGDC_GenICamChunkData
Chunk data (GenDC).
Definition TBufferPartDataType.h:117
@ bpdt2DPlaneQuadplanar
Single color plane of a planar (2D) image (GenTL).
Definition TBufferPartDataType.h:69
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:34