#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <thread>
#include <apps/Common/exampleHelper.h>
#include <common/crt/mvstdio.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire_GenICam.h>
#include <mvIMPACT_CPP/mvIMPACT_acquire_helper.h>
#ifdef _WIN32
# include <mvDisplay/Include/mvIMPACT_acquire_display.h>
# define USE_DISPLAY
#endif
using namespace std;
struct ThreadParameter
{
unsigned int requestsCaptured_;
#ifdef USE_DISPLAY
#endif
explicit ThreadParameter(
Device* pDev ) : pDev_( pDev ), requestsCaptured_( 0 ), statistics_( pDev )
#ifdef USE_DISPLAY
, displayWindow_(
"mvIMPACT_acquire sample, Device " + pDev_->
serial.
read() )
#endif
{}
ThreadParameter( const ThreadParameter& src ) = delete;
ThreadParameter& operator=( const ThreadParameter& rhs ) = delete;
};
static void configureDevice(
Device* pDev );
static void configureBlueCOUGAR_X(
Device* pDev );
static void configureVirtualDevice(
Device* pDev );
static bool isDeviceSupportedBySample(
const Device*
const pDev );
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 shared_ptr<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() << "."
<< "ts" << std::setfill( '0' ) << std::setw( 16 ) << pRequest->infoTimeStamp_us.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 );
}
}
void myThreadCallback( shared_ptr<Request> pRequest, ThreadParameter& threadParameter )
{
if( pRequest->isOK() )
{
const unsigned int bufferPartCount = pRequest->getBufferPartCount();
++threadParameter.requestsCaptured_;
if( threadParameter.requestsCaptured_ % 100 == 0 )
{
const Statistics& s = threadParameter.statistics_;
cout << "Info from " << threadParameter.pDev_->serial.read();
if( bufferPartCount == 0 )
{
cout << " NOT running in multi-part mode";
}
else
{
cout << " running in multi-part mode, delivering " << bufferPartCount << " parts";
}
}
if( bufferPartCount == 0 )
{
#ifdef USE_DISPLAY
ImageDisplay& display = threadParameter.displayWindow_.GetImageDisplay();
#else
cout << "Image captured: " << pRequest->imageOffsetX.read() << "x" << pRequest->imageOffsetY.read() << "@" << pRequest->imageWidth.read() << "x" << pRequest->imageHeight.read() << endl;
#endif
}
else
{
#ifdef USE_DISPLAY
bool boImageDisplayed = false;
ImageDisplay& display = threadParameter.displayWindow_.GetImageDisplay();
#endif
for( unsigned int i = 0; i < bufferPartCount; i++ )
{
const BufferPart& bufferPart = pRequest->getBufferPart( i );
{
{
#ifdef USE_DISPLAY
if( !boImageDisplayed )
{
boImageDisplayed = true;
}
else
#endif
{
}
}
break;
storeBufferPartToDisc( threadParameter.pDev_, pRequest, bufferPart, i, "jpeg" );
break;
storeBufferPartToDisc( threadParameter.pDev_, pRequest, bufferPart, i, "chunk" );
break;
storeBufferPartToDisc( threadParameter.pDev_, pRequest, bufferPart, i, "xml" );
break;
storeBufferPartToDisc( threadParameter.pDev_, pRequest, bufferPart, i, "h264" );
break;
cout << "Buffer Part" << "(index " << i << ") has an unknown data type. Skipped!" << endl;
break;
}
}
}
}
else
{
cout << "Error: " << pRequest->requestResult.readS() << endl;
}
}
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 == nullptr )
{
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 );
requestProvider.acquisitionStart( myThreadCallback, std::ref( threadParam ) );
cin.get();
requestProvider.acquisitionStop();
}
{
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:18875
std::string name(void) const
Returns the name of the component referenced by this object.
Definition mvIMPACT_acquire.h:1206
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
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 basic statistical information.
Definition mvIMPACT_acquire.h:14509
PropertyF framesPerSecond
A float property (read-only) containing the current number of frames captured per second.
Definition mvIMPACT_acquire.h:14586
PropertyF captureTime_s
A float property (read-only) containing the overall time an image request spent in the device drivers...
Definition mvIMPACT_acquire.h:14560
PropertyI errorCount
An integer property (read-only) containing the overall count of image requests which returned with an...
Definition mvIMPACT_acquire.h:14568
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
A helper class that can be used to implement a simple continuous acquisition from a device.
Definition mvIMPACT_acquire_helper.h:432
@ 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