AVT相机arm版本SDK

This commit is contained in:
zhangpeng
2025-04-30 09:26:04 +08:00
parent 837c870f18
commit 78a1c63a95
705 changed files with 148770 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
PROJECT_NAME = ActionCommands
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES = -D_LITTLE_ENDIAN
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ActionCommands.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,985 @@
/*=============================================================================
Copyright (C) 2021 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ActionCommands.cpp
Description: see header file for description
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <string.h>
#include <ActionCommands.h>
// socket library to check IP addresses
#ifdef _WIN32
#include <conio.h>
#include <WinSock.h>
#else
#include <arpa/inet.h>
#endif
// number of frame buffers to be used by example
#define NUM_FRAMES 3
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Constructor
//
cActionCommands::cActionCommands()
: mSystem( VimbaSystem::GetInstance() )
, mFrameObserver( NULL )
, mSystemFlag( false )
, mInterfaceFlag( false )
, mCameraFlag( false )
, mStreamingFlag( false )
{
}
//
// Destructor
//
cActionCommands::~cActionCommands()
{
}
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType cActionCommands::GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// get feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lError = lFeature->GetDataType( lType );
if( (VmbErrorSuccess == lError) && (NULL != aType) )
{
*aType = lType;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( lType )
{
case VmbFeatureDataInt:
{
// get value
VmbInt64_t lValue = 0;
lError = lFeature->GetValue( lValue );
if( VmbErrorSuccess == lError )
{
memcpy( aValue, &lValue, sizeof(VmbInt64_t) );
}
// set buffer size
if( NULL != aSize )
{
*aSize = sizeof(VmbInt64_t);
}
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType cActionCommands::SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( (NULL == aName) || (NULL == aValue) )
{
return VmbErrorBadParameter;
}
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
// check feature data type
VmbFeatureDataType lType = VmbFeatureDataUnknown;
lFeature->GetDataType( lType );
if( lType != aType )
{
return VmbErrorBadParameter;
}
// proceed in case of no error
if( VmbErrorSuccess == lError )
{
// set feature value
switch( aType )
{
case VmbFeatureDataInt:
{
// check size
if( sizeof(VmbInt64_t) >= aSize )
{
// set value
VmbInt64_t lValue = (VmbInt64_t)aValue;
lError = lFeature->SetValue( lValue );
}
break;
}
case VmbFeatureDataEnum:
{
// set value
const char* lValue = (char*)aValue;
lError = lFeature->SetValue( lValue );
break;
}
default:
{
lError = VmbErrorBadParameter;
break;
}
}
}
return lError;
}
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType cActionCommands::RunCommand( const char* aName, tFeatureOwner aOwner )
{
VmbErrorType lError = VmbErrorSuccess;
// get feature pointer
FeaturePtr lFeature;
switch( aOwner )
{
case eFeatureOwnerSystem:
{
lError = this->mSystem.GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerInterface:
{
lError = this->mInterface->GetFeatureByName( aName, lFeature );
break;
}
case eFeatureOwnerCamera:
{
lError = this->mCamera->GetFeatureByName( aName, lFeature );
break;
}
default:
lError = VmbErrorBadParameter;
}
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
return lError;
}
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void cActionCommands::FailureShutdown()
{
VmbErrorType lError = VmbErrorSuccess;
// stop streaming
if( true == this->mStreamingFlag )
{
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop camera acquisition. Reason: " << lError << std::endl;
}
std::cout << "......Streaming has been stopped." << std::endl;
}
// close camera
if( true == this->mCameraFlag )
{
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
std::cout << "......Camera has been closed." << std::endl;
}
// close interface
if( true == this->mInterfaceFlag )
{
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close interface. Reason: " << lError << std::endl;
}
std::cout << "......Interface has been closed." << std::endl;
}
// shutdown Vimba
if( true == this->mSystemFlag )
{
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not shutdown Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Vimba has been stooped." << std::endl;
}
}
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType cActionCommands::ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress )
{
VmbErrorType lError = VmbErrorSuccess;
VmbUint32_t lIP = 0;
// check parameter
if( (true == aString.empty()) || (NULL == aIPAddress) )
{
std::cout << "[F]...Invalid parameter given" << std::endl;
return VmbErrorBadParameter;
}
// convert given string to IP struct
lIP = inet_addr( aString.c_str() );
if( -1 == lIP )
{
lError = VmbErrorInvalidValue;
}
else
{
#ifdef _LITTLE_ENDIAN
lIP = ntohl( lIP );
#endif
*aIPAddress = lIP;
}
return lError;
}
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType cActionCommands::PrepareCamera( std::string aCamera )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( true == aCamera.empty() )
{
std::cout << "[F]...Invalid device ID or IP address given." << std::endl;
return VmbErrorBadParameter;
}
// start Vimba
lError = this->mSystem.Startup();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not start Vimba API. Reason: " << lError << std::endl;
return lError;
}
this->mSystemFlag = true;
std::cout << "......Vimba has been started." << std::endl;
// open camera with given string (could be device ID or IP address)
lError = this->mSystem.OpenCameraByID( aCamera.c_str(), VmbAccessModeFull, this->mCamera );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open camera " << aCamera << ". Reason: " << lError << std::endl;
this->FailureShutdown();
return lError;
}
this->mCameraFlag = true;
std::cout << "......Camera has been opened (" << aCamera << ")." << std::endl;
return lError;
}
//
// Close camera and shutdown Vimba
//
VmbErrorType cActionCommands::StopCamera()
{
VmbErrorType lError = VmbErrorSuccess;
if( true == this->mCameraFlag )
{
// close camera
lError = this->mCamera->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not close camera. Reason: " << lError << std::endl;
}
this->mCameraFlag = false;
std::cout << "......Camera has been closed." << std::endl;
}
if( true == this->mSystemFlag )
{
// shutdown Vimba
lError = this->mSystem.Shutdown();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not stop Vimba. Reason: " << lError << std::endl;
}
this->mSystemFlag = false;
std::cout << "......Vimba has been stopped." << std::endl;
}
return lError;
}
//
// Prepare trigger settings for given camera
//
VmbErrorType cActionCommands::PrepareTrigger()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
char* lTemp = "";;
// select FrameStart trigger via TriggerSelector feature
lTemp = "FrameStart";
lError = this->SetFeatureValue( "TriggerSelector", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSelector to FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set trigger source to Action0
lTemp = "Action0";
lError = this->SetFeatureValue( "TriggerSource", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set TriggerSource to 'Action0'. Reason: " << lError << ". Probably this camera does not support Action Commands." << std::endl;
FailureShutdown();
return lError;
}
// enable trigger
lTemp = "On";
lError = this->SetFeatureValue( "TriggerMode", eFeatureOwnerCamera, VmbFeatureDataEnum, lTemp, sizeof(lTemp) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not enable TriggerMode for FrameStart. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Trigger FrameStart has been activated and set to Action0" << std::endl;
return lError;
}
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType cActionCommands::PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// check parameter
if( NULL == aCommand )
{
std::cout << "[F]...Invalid Action Command given." << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// set device key
lError = this->SetFeatureValue( "ActionDeviceKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mDeviceKey), sizeof(aCommand->mDeviceKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionDeviceKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group key
lError = this->SetFeatureValue( "ActionGroupKey", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupKey), sizeof(aCommand->mGroupKey) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupKey. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// set group mask
lError = this->SetFeatureValue( "ActionGroupMask", aOwner, VmbFeatureDataInt, (void*)(aCommand->mGroupMask), sizeof(aCommand->mGroupMask) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set ActionGroupMask. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been set (" << aCommand->mDeviceKey << ", " << aCommand->mGroupKey << ", " << aCommand->mGroupMask << ")" << std::endl;
return lError;
}
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType cActionCommands::PrepareStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
FeaturePtr lFeature;
// set GVSP packet size to max value (MTU)
// and wait until command is done
lError = this->mCamera->GetFeatureByName( "GVSPAdjustPacketSize", lFeature );
if( VmbErrorSuccess == lError )
{
lError = lFeature->RunCommand();
}
// check if any failure occurred
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set GVSP packet size. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
// check if operation is done
bool lFlag = false;
do
{
lError = lFeature->IsCommandDone( lFlag );
if( VmbErrorSuccess != lError )
{
break;
}
} while( VmbBoolFalse == lFlag );
// get GVSP packet size, which was actually set in the camera
VmbInt64_t lGVSPSize = 0;
lError = this->GetFeatureValue( "GVSPPacketSize", eFeatureOwnerCamera, NULL, &lGVSPSize, NULL );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not get GVSP packet size. Reason: " << lError << std::endl;
}
std::cout << "......GVSP packet size has been set to maximum (" << lGVSPSize << ")" << std::endl;
// create new frame observer
this->mFrameObserver = new cFrameObserver( this->mCamera );
// start continuous image acquisition
lError = this->mCamera->StartContinuousImageAcquisition( NUM_FRAMES, IFrameObserverPtr(this->mFrameObserver) );
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not start continuous image acquisition. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = true;
std::cout << "......Camera acquisition has been started." << std::endl;
return lError;
}
//
// End streaming
//
VmbErrorType cActionCommands::StopStreaming()
{
VmbErrorType lError = VmbErrorSuccess;
// stop continuous image acquisition
lError = this->mCamera->StopContinuousImageAcquisition();
if( VmbErrorSuccess != lError )
{
FailureShutdown();
std::cout << "[F]...Could not stop streaming. Reason: " << lError << std::endl;
return lError;
}
this->mStreamingFlag = false;
std::cout << "......Camera acquisition has been stopped." << std::endl;
return lError;
}
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to Vimba
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerSystem, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to Vimba system
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerSystem, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerSystem );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType cActionCommands::SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand )
{
VmbErrorType lError = VmbErrorSuccess;
// -start Vimba
// -open camera in full access mode and get handle
lError = PrepareCamera( aCamera );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -select FrameStart trigger feature
// -set source to Action0
// -enable trigger
lError = PrepareTrigger();
if( VmbErrorSuccess != lError )
{
return lError;
}
// Set Action Command to camera
// -set device key
// -set group key
// -set group mask
lError = PrepareActionCommand( eFeatureOwnerCamera, &aCommand );
if( VmbErrorSuccess != lError )
{
return lError;
}
// -adjust GVSP packet size
// -get payload size
// -allocate memory for frame buffers
// -announce frames and move them to buffer input pool
// -start capture engine
// -move frames to capture queue (buffer output queue)
// -call start acquisition feature in the camera
lError = PrepareStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// get available interfaces
InterfacePtrVector lInterfaces;
lError = this->mSystem.GetInterfaces( lInterfaces );
if( (VmbErrorSuccess != lError) || (0 == lInterfaces.size()) )
{
std::cout << "[F]...Could not retrieve interfaces" << std::endl;
FailureShutdown();
return lError;
}
// print interface list
bool lFound = false;
int lIndex = 0;
for( int i=0; i<lInterfaces.size(); ++i )
{
InterfacePtr lInterface = lInterfaces.at(i);
std::string lInterfaceID = "";
lError = lInterface->GetID( lInterfaceID );
if( VmbErrorSuccess == lError )
{
std::cout << ".........[" << i << "] " << lInterfaceID << std::endl;
// compare given interface ID with current one
if( 0 == lInterfaceID.compare( aInterface ) )
{
// if interface ID matches, keep index
lFound = true;
lIndex = i;
}
}
}
// if no interface with given ID was found, return
if( false == lFound )
{
std::cout << "[F]...Given interface with ID '" << aInterface << "' was not found!" << std::endl;
FailureShutdown( );
return VmbErrorBadParameter;
}
// get interface pointer
this->mInterface = lInterfaces.at( lIndex );
if( true == SP_ISNULL(this->mInterface) )
{
std::cout << "[F]...No valid interface pointer with given index found" << std::endl;
FailureShutdown();
return VmbErrorBadParameter;
}
// check interface type
VmbInterfaceType lInterfaceType = VmbInterfaceUnknown;
lError = this->mInterface->GetType( lInterfaceType );
if( (VmbErrorSuccess != lError) || (VmbInterfaceEthernet != lInterfaceType) )
{
printf( "[F]...Selected interface is non-GigE interface!\n" );
FailureShutdown();
return VmbErrorBadParameter;
}
// open interface
lError = this->mInterface->Open();
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not open interface" << std::endl;
FailureShutdown();
return lError;
}
this->mInterfaceFlag = true;
std::cout << "......Interface has been opened." << std::endl;
// determine if Action Command shall be send as uni- or broadcast
// if IP address was given, send it as unicast
VmbUint32_t lIP = 0;
lError = ConvertStringToIPAddress( aCamera, &lIP );
if( VmbErrorSuccess == lError )
{
// set IP address to the selected interface
lError = this->SetFeatureValue( "GevActionDestinationIPAddress", eFeatureOwnerInterface, VmbFeatureDataInt, (void*)lIP, sizeof(lIP) );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not set IP address '" << aCamera << "' to Vimba. Reason: " << lError << std::endl;
}
std::cout << "......Action Command will be send as unicast to IP '" << aCamera << "' (" << lIP << ")" << std::endl;
}
// set Action Command to the selected interface
// -device key
// -group key
// -group mask
lError = PrepareActionCommand(eFeatureOwnerInterface, &aCommand);
if (VmbErrorSuccess != lError)
{
std::cout << "[F]...Could not prepare Action Command. Reason: " << lError << std::endl;
}
#ifdef _WIN32
std::cout << "\n<< Please hit 'a' to send prepared Action Command. To stop example hit 'q' >>\n\n";
#else
std::cout << "\n<< Please enter 'a' and return to send prepared Action Command. To stop example enter 'q' and return >>\n\n";
#endif
// repeat this until user hits ESC
int lKey = 0;
do
{
// wait for user input
#ifdef _WIN32
lKey = _getch();
#else
lKey = getchar();
#endif
if( 97 == lKey )
{
// send Action Command by calling command feature
lError = RunCommand( "ActionCommand", eFeatureOwnerInterface );
if( VmbErrorSuccess != lError )
{
std::cout << "[F]...Could not send Action Command. Reason: " << lError << std::endl;
FailureShutdown();
return lError;
}
std::cout << "......Action Command has been sent." << std::endl;
}
} while( 113 != lKey );
// close interface
lError = this->mInterface->Close();
if( VmbErrorSuccess != lError )
{
std::cout << "Could not close interface. Reason: " << lError << std::endl;
}
this->mInterfaceFlag = false;
std::cout << "......Interface has been closed." << std::endl;
// stop streaming
lError = StopStreaming();
if( VmbErrorSuccess != lError )
{
return lError;
}
// -close camera
// -shutdown Vimba
lError = StopCamera();
return lError;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,200 @@
/*=============================================================================
Copyright (C) 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ActionCommands.h
Description: This example will create an Action Command and send it to any
camera, given by parameter. The following can be set up with
parameters as well:
-send Action Command as broadcast on specific network interface
-send Action Command as broadcast to all network interfaces
-send Action Command to specific IP address (unicast)
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_ACTION_COMMANDS
#define AVT_VMBAPI_EXAMPLES_ACTION_COMMANDS
#include "VimbaCPP/Include/VimbaCPP.h"
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// struct representing an Action Command
typedef struct tActionCommand
{
VmbUint32_t mDeviceKey;
VmbUint32_t mGroupKey;
VmbUint32_t mGroupMask;
} tActionCommand;
typedef enum tFeatureOwner
{
eFeatureOwnerUnknown = 0,
eFeatureOwnerSystem = 1,
eFeatureOwnerInterface = 2,
eFeatureOwnerCamera = 3
} tFeatureOwner;
class cActionCommands
{
private:
VimbaSystem& mSystem;
InterfacePtr mInterface;
CameraPtr mCamera;
cFrameObserver* mFrameObserver;
bool mSystemFlag;
bool mInterfaceFlag;
bool mCameraFlag;
bool mStreamingFlag;
public:
//
// Constructor
//
cActionCommands();
//
// Destructor
//
~cActionCommands();
//
// Helper method to read feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [out] aType Feature data type
// [in/out] aValue Buffer for feature value
// [in/out] aSize Size of buffer
//
VmbErrorType GetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType* aType, void* aValue, size_t* aSize );
//
// Helper method to write feature values of any type
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
// [in] aType Feature data type
// [in] aValue Buffer for feature value
// [in] aSize Size of buffer
//
VmbErrorType SetFeatureValue( const char* aName, tFeatureOwner aOwner, VmbFeatureDataType aType, void* aValue, size_t aSize );
//
// Helper method to run a Command Feature
//
// Parameters:
// [in] aName Feature name
// [in] aOwner Feature owner, like Vimba system, interface or camera
//
VmbErrorType RunCommand( const char* aName, tFeatureOwner aOwner );
//
// Called when any failure occurs within the example.
// Ensures to stop streaming, close interface, close camera and shutdown Vimba
//
void FailureShutdown();
//
// Convert given string to IP address,
// using respective socket library (Winsock/Arpa)
//
// Parameters:
// [in] aString String to be converted
// [out] aIPAddress Decimal representation of given IP address string
//
VmbErrorType ConvertStringToIPAddress( std::string aString, VmbUint32_t* aIPAddress );
//
// Start Vimba and open camera with given string
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
//
VmbErrorType PrepareCamera( std::string aCamera );
//
// Close camera and shutdown Vimba
//
VmbErrorType StopCamera();
//
// Prepare trigger settings for given camera
//
VmbErrorType PrepareTrigger();
//
// Set Action Command information to given feature owner.
// This could be Vimba system, interface or the camera
//
// Parameters:
// [in] aOwner Feature owner, like System, Interface or Camera
// [in] aCommand Action Command struct (device key, group key, group mask)
//
VmbErrorType PrepareActionCommand( tFeatureOwner aOwner, tActionCommand* aCommand );
//
// Prepare streaming settings in Vimba and the camera,
// like allocating the buffers, start capture engine, etc.
//
VmbErrorType PrepareStreaming();
//
// End streaming
//
VmbErrorType StopStreaming();
//
// Send Action Command on system level.
// This command will be broadcasted on all network interfaces.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnAllInterfaces( std::string aCamera, tActionCommand aCommand );
//
// Send Action Command on interface level.
// This command will be broadcasted on given network interface.
//
// Parameters:
// [in] aCamera The ID or IP address of the camera to work with
// [in] aInterface The network interface on which the Action Command
// will be sent out
// [in] aCommand Action Command to be used by Vimba and camera
//
VmbErrorType SendActionCommandOnInterface( std::string aCamera, std::string aInterface, tActionCommand aCommand );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,76 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
cFrameObserver::cFrameObserver( CameraPtr aCamera )
: IFrameObserver( aCamera )
{
this->mCamera = aCamera;
}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void cFrameObserver::FrameReceived( const FramePtr pFrame )
{
if(false == SP_ISNULL( pFrame ) )
{
VmbErrorType lError = VmbErrorSuccess;
VmbFrameStatusType lStatus;
lError = SP_ACCESS( pFrame)->GetReceiveStatus( lStatus);
if( (VmbErrorSuccess == lError) && (VmbFrameStatusComplete == lStatus))
{
std::cout << "......Frame has been received" << std::endl;
}
// requeue frame
this->mCamera->QueueFrame( pFrame );
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,65 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class cFrameObserver : virtual public IFrameObserver
{
private:
CameraPtr mCamera;
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
//
cFrameObserver( CameraPtr aCamera );
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr aFrame );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,98 @@
/*=============================================================================
Copyright (C) 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of ActionCommands example of VimbaCPP.
annotations:
-local variables are prefixed with 'l' for local
-function parameter are prefixed with 'a' for 'argument'
-structs are prefixed with 't' for 'type'
-classes are prefixed with 'c' for 'class'
-class attributes and struct members are prefixed with 'm' for members
-enum literals are prefixed with 'e' for 'enumeration'
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <string.h>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ActionCommands.h"
// function to print out help how to use this example application
void PrintHelp()
{
printf( "Usage: ActionCommands <CameraID/IPAdress> <InterfaceID>\n\n" );
printf( "Parameters: CameraID ID of the camera to be used\n" );
printf( " IPAddress IP address of camera to react on Action Command\n" );
printf( " InterfaceID ID of network interface to send out Action Command\n" );
printf( " 'ALL' enables broadcast on all interfaces\n\n" );
}
int main( int argc, char* argv[] )
{
VmbErrorType lError = VmbErrorSuccess;
std::cout << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << "/// Vimba API Action Commands Example ///" << std::endl;
std::cout << "/////////////////////////////////////////" << std::endl;
std::cout << std::endl;
// check number of arguments
if( 3 == argc )
{
// create Action Command example instance
AVT::VmbAPI::Examples::cActionCommands lProgram;
// define Action Command to be set in the camera
// and used by either Vimba system or interface module
AVT::VmbAPI::Examples::tActionCommand lActionCommand;
lActionCommand.mDeviceKey = 1;
lActionCommand.mGroupKey = 1;
lActionCommand.mGroupMask = 1;
// check if interface index is '-1' to send out Action Command on all interfaces
// if not, send Action Command via given network interface
if( 0 == strcmp("ALL", argv[2]) )
{
lError = lProgram.SendActionCommandOnAllInterfaces( argv[1], lActionCommand );
}
else
{
lError = lProgram.SendActionCommandOnInterface( argv[1], argv[2], lActionCommand );
}
}
else
{
lError = VmbErrorBadParameter;
std::cout << "[F]...Invalid number of parameters given!" << std::endl;
std::cout << std::endl;
PrintHelp();
}
std::cout << std::endl;
return lError;
}

View File

@@ -0,0 +1,57 @@
PROJECT_NAME = AsynchronousGrabConsole
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/../..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
-lrt
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP \
VimbaImageTransform
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,245 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.cpp
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include "ApiController.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
#define NUM_FRAMES 3
ApiController::ApiController()
// Get a reference to the Vimba singleton
: m_system ( VimbaSystem::GetInstance() )
{}
ApiController::~ApiController()
{
}
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartUp()
{
return m_system.Startup();
}
//
// Shuts down the API
//
void ApiController::ShutDown()
{
// Release Vimba
m_system.Shutdown();
}
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] Config A configuration struct including the camera ID and other settings
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartContinuousImageAcquisition( const ProgramConfig& Config )
{
// Open the desired camera by its ID
VmbErrorType res = m_system.OpenCameraByID( Config.getCameraID().c_str(), VmbAccessModeFull, m_pCamera );
if ( VmbErrorSuccess == res )
{
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
FeaturePtr pCommandFeature;
if ( VmbErrorSuccess == m_pCamera->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ))
{
if ( VmbErrorSuccess == pCommandFeature->RunCommand() )
{
bool bIsCommandDone = false;
do
{
if ( VmbErrorSuccess != pCommandFeature->IsCommandDone( bIsCommandDone ))
{
break;
}
} while ( false == bIsCommandDone );
}
}
if ( VmbErrorSuccess == res )
{
// set camera so that transform algorithms will never fail
res = PrepareCamera();
if ( VmbErrorSuccess == res )
{
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
m_pFrameObserver = new FrameObserver( m_pCamera, Config.getFrameInfos(), Config.getColorProcessing(), Config.getRGBValue() );
// Start streaming
res = m_pCamera->StartContinuousImageAcquisition( NUM_FRAMES, IFrameObserverPtr( m_pFrameObserver ), Config.getAllocAndAnnounce() ? FrameAllocation_AllocAndAnnounceFrame : FrameAllocation_AnnounceFrame );
}
}
if ( VmbErrorSuccess != res )
{
// If anything fails after opening the camera we close it
m_pCamera->Close();
}
}
return res;
}
/**setting a feature to maximum value that is a multiple of 2 and a multiple of the increment*/
VmbErrorType SetIntFeatureValueModulo2( const CameraPtr &pCamera, const char* const& Name )
{
VmbErrorType result;
FeaturePtr feature;
VmbInt64_t value_min = 0;
VmbInt64_t value_max = 0;
VmbInt64_t value_increment = 0;
result = SP_ACCESS( pCamera )->GetFeatureByName( Name, feature );
if( VmbErrorSuccess != result )
{
return result;
}
result = SP_ACCESS( feature )->GetRange( value_min, value_max );
if( VmbErrorSuccess != result )
{
return result;
}
result = SP_ACCESS( feature )->GetIncrement( value_increment );
if( VmbErrorSuccess != result )
{
return result;
}
value_max = value_max - ( value_max % value_increment);
if( value_max % 2 != 0)
{
value_max -= value_increment;
}
result = SP_ACCESS( feature )->SetValue ( value_max );
return result;
}
/**prepare camera so that the delivered image will not fail in image transform*/
VmbErrorType ApiController::PrepareCamera()
{
VmbErrorType result;
result = SetIntFeatureValueModulo2( m_pCamera, "Width" );
if( VmbErrorSuccess != result )
{
return result;
}
result = SetIntFeatureValueModulo2( m_pCamera, "Height" );
if( VmbErrorSuccess != result )
{
return result;
}
return result;
}
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StopContinuousImageAcquisition()
{
// Stop streaming
m_pCamera->StopContinuousImageAcquisition();
// Close camera
return m_pCamera->Close();
}
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector ApiController::GetCameraList() const
{
CameraPtrVector cameras;
// Get all known cameras
if ( VmbErrorSuccess == m_system.GetCameras( cameras ))
{
// And return them
return cameras;
}
return CameraPtrVector();
}
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string ApiController::GetVersion() const
{
std::ostringstream os;
os<<m_system;
return os.str();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,123 @@
/*=============================================================================
Copyright (C) 2013 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.h
Description: Header file for the ApiController helper class that demonstrates
how to implement an asynchronous, continuous image acquisition
with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "FrameObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ApiController
{
public:
ApiController();
~ApiController();
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType StartUp();
//
// Shuts down the API
//
void ShutDown();
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] Config A configuration struct including the camera ID and other settings
//
// Returns:
// An API status code
//
VmbErrorType StartContinuousImageAcquisition( const ProgramConfig & );
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType StopContinuousImageAcquisition();
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector GetCameraList() const;
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string GetVersion() const;
private:
VmbErrorType PrepareCamera();
VimbaSystem & m_system; // A reference to our Vimba singleton
CameraPtr m_pCamera; // The currently streaming camera
FrameObserver* m_pFrameObserver; // Every camera has its own frame observer
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,84 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: BaseException.h
Description:
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef BASE_EXCEPTION_H_
#define BASE_EXCEPTION_H_
#include <exception>
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class BaseException: public std::exception
{
std::string m_Function;
std::string m_Message;
VmbErrorType m_Result;
public:
BaseException( const char* const &fun, const char* const& msg, VmbErrorType result )
: m_Result ( result )
{
try
{
if( NULL != fun)
{
m_Function = std::string( fun );
}
}
catch(...) {}
try
{
if( NULL != msg)
{
m_Message = std::string( msg );
}
}
catch(...) {}
}
~BaseException() throw()
{}
const std::string& Function() const
{
return m_Function;
}
const std::string& Message() const
{
return m_Message;
}
VmbErrorType Result() const
{
return m_Result;
}
};
}}}
#endif

View File

@@ -0,0 +1,370 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <iomanip>
#ifdef WIN32
#include <Windows.h>
#else
#include <time.h>
#endif //WIN32
#include "FrameObserver.h"
#include "TransformImage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
FrameObserver::FrameObserver( CameraPtr pCamera, FrameInfos eFrameInfos, ColorProcessing eColorProcessing, bool bRGBValue )
: IFrameObserver( pCamera )
, m_eFrameInfos( eFrameInfos )
, m_bRGB( bRGBValue )
, m_eColorProcessing( eColorProcessing )
#ifdef WIN32
, m_dFrequency( 0.0 )
#endif //WIN32
{
#ifdef WIN32
LARGE_INTEGER nFrequency;
QueryPerformanceFrequency( &nFrequency );
m_dFrequency = (double)nFrequency.QuadPart;
#endif //WIN32
}
//
// Gets the current timestamp for interval measurement
//
double FrameObserver::GetTime()
{
double dTime = 0.0;
#ifdef WIN32
LARGE_INTEGER nCounter;
QueryPerformanceCounter( &nCounter );
dTime = ( (double)nCounter.QuadPart ) / m_dFrequency;
#else
//clock_t nTime = times(NULL);
//dTime = ((double)(nTime) * 10000.0) / ((double)CLOCKS_PER_SEC);
struct timespec now;
clock_gettime( CLOCK_REALTIME, &now );
dTime = ( (double)now.tv_sec ) + ( (double)now.tv_nsec ) / 1000000000.0;
#endif //WIN32
return dTime;
}
//
// Prints out frame parameters such as
// - width
// - height
// - pixel format
//
// Parameters:
// [in] pFrame The frame to work on
//
void PrintFrameInfo( const FramePtr &pFrame )
{
std::cout<<" Size:";
VmbUint32_t nWidth = 0;
VmbErrorType res;
res = pFrame->GetWidth(nWidth);
if( VmbErrorSuccess == res )
{
std::cout<<nWidth;
}
else
{
std::cout<<"?";
}
std::cout<<"x";
VmbUint32_t nHeight = 0;
res = pFrame->GetHeight(nHeight);
if( VmbErrorSuccess == res )
{
std::cout<< nHeight;
}
else
{
std::cout<<"?";
}
std::cout<<" Format:";
VmbPixelFormatType ePixelFormat = VmbPixelFormatMono8;
res = pFrame->GetPixelFormat( ePixelFormat );
if( VmbErrorSuccess == res )
{
std::cout<<"0x"<<std::hex<<ePixelFormat<<std::dec;
}
else
{
std::cout<<"?";
}
}
//
// Prints out frame status codes as readable status messages
//
// Parameters:
// [in] eFrameStatus The error code to be converted and printed out
//
void PrintFrameStatus( VmbFrameStatusType eFrameStatus )
{
switch( eFrameStatus )
{
case VmbFrameStatusComplete:
std::cout<<"Complete";
break;
case VmbFrameStatusIncomplete:
std::cout<<"Incomplete";
break;
case VmbFrameStatusTooSmall:
std::cout<<"Too small";
break;
case VmbFrameStatusInvalid:
std::cout<<"Invalid";
break;
default:
std::cout<<"unknown frame status";
break;
}
}
//
// Prints out details of a frame such as
// - ID
// - receive status
// - width, height, pixel format
// - current frames per second
//
// Parameters:
// [in] pFrame The frame to work on
//
void FrameObserver::ShowFrameInfos( const FramePtr &pFrame )
{
bool bShowFrameInfos = false;
VmbUint64_t nFrameID = 0;
bool bFrameIDValid = false;
VmbFrameStatusType eFrameStatus = VmbFrameStatusComplete;
bool bFrameStatusValid = false;
VmbErrorType res = VmbErrorSuccess;
double dFPS = 0.0;
bool bFPSValid = false;
VmbUint64_t nFramesMissing = 0;
if( FrameInfos_Show == m_eFrameInfos )
{
bShowFrameInfos = true;
}
res = pFrame->GetFrameID( nFrameID );
if( VmbErrorSuccess == res )
{
bFrameIDValid = true;
if( m_FrameID.IsValid() )
{
if( nFrameID != ( m_FrameID() + 1 ) )
{
nFramesMissing = nFrameID - m_FrameID() - 1;
if( 1 == nFramesMissing )
{
std::cout<<"1 missing frame detected\n";
}
else
{
std::cout<<nFramesMissing<<"missing frames detected\n";
}
}
}
m_FrameID( nFrameID );
double dFrameTime = GetTime();
if( ( m_FrameTime.IsValid() )
&& ( 0 == nFramesMissing ) )
{
double dTimeDiff = dFrameTime - m_FrameTime();
if( dTimeDiff > 0.0 )
{
dFPS = 1.0 / dTimeDiff;
bFPSValid = true;
}
else
{
bShowFrameInfos = true;
}
}
m_FrameTime( dFrameTime );
}
else
{
bShowFrameInfos = true;
m_FrameID.Invalidate();
m_FrameTime.Invalidate();
}
res = pFrame->GetReceiveStatus( eFrameStatus );
if( VmbErrorSuccess == res )
{
bFrameStatusValid = true;
if( VmbFrameStatusComplete != eFrameStatus )
{
bShowFrameInfos = true;
}
}
else
{
bShowFrameInfos = true;
}
if( bShowFrameInfos )
{
std::cout<<"Frame ID:";
if( bFrameIDValid )
{
std::cout<<nFrameID;
}
else
{
std::cout<<"?";
}
std::cout<<" Status:";
if( bFrameStatusValid )
{
PrintFrameStatus( eFrameStatus);
}
else
{
std::cout<<"?";
}
PrintFrameInfo( pFrame );
std::cout<<" FPS:";
if( bFPSValid )
{
std::streamsize s = std::cout.precision();
std::cout<<std::fixed<<std::setprecision(2)<<dFPS<<std::setprecision(s);
}
else
{
std::cout<<"?";
}
std::cout<<"\n";
}
else
{
std::cout<<".";
}
}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void FrameObserver::FrameReceived( const FramePtr pFrame )
{
if(! SP_ISNULL( pFrame ) )
{
if( FrameInfos_Off != m_eFrameInfos )
{
ShowFrameInfos( pFrame);
}
VmbFrameStatusType status;
VmbErrorType Result;
Result = SP_ACCESS( pFrame)->GetReceiveStatus( status);
if( VmbErrorSuccess == Result && VmbFrameStatusComplete == status)
{
std::vector<VmbUchar_t> TransformedData;
if ( m_bRGB )
{
switch( m_eColorProcessing )
{
default:
Result = VmbErrorBadParameter;
std::cout<<"unknown color processing parameter\n";
break;
case ColorProcessing_Off:
Result = TransformImage( pFrame, TransformedData, "RGB24" );
break;
case ColorProcessing_Matrix:
{
std::cout<<"Color Transform\n";
const VmbFloat_t Matrix[] = { 0.6f, 0.3f, 0.1f,
0.6f, 0.3f, 0.1f,
0.6f, 0.3f, 0.1f};
Result = TransformImage( pFrame, TransformedData,"BGR24", Matrix );
}
break;
}
if( VmbErrorSuccess == Result && TransformedData.size() >=3 )
{
char old_fill_char = std::cout.fill('0');
std::cout<<std::hex <<"R = 0x"<<std::setw(2)<<(int)TransformedData[0]<<" "
<<"G = 0x"<<std::setw(2)<<(int)TransformedData[1]<<" "
<<"B = 0x"<<std::setw(2)<<(int)TransformedData[2]<<std::dec<<"\n";
std::cout.fill( old_fill_char );
}
else
{
std::cout<<"Transformation failed.\n";
}
}
}
else
{
std::cout<<"frame incomplete\n";
}
}
else
{
std::cout <<" frame pointer NULL\n";
}
m_pCamera->QueueFrame( pFrame );
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,113 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include <queue>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ProgramConfig.h"
#ifdef WIN32
#include <Windows.h>
#endif //WIN32
namespace AVT {
namespace VmbAPI {
namespace Examples {
class FrameObserver : virtual public IFrameObserver
{
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
// [in] eFrameInfos Indicates how the frame will be displayed
// [in] eColorProcessing Indicates how color processing is applied
//
FrameObserver( CameraPtr pCamera, FrameInfos eFrameInfos, ColorProcessing eColorProcessing, bool bRGBValue );
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr pFrame );
private:
void ShowFrameInfos( const FramePtr & );
double GetTime();
template <typename T>
class ValueWithState
{
private:
T m_Value;
bool m_State;
public:
ValueWithState()
: m_State( false )
{}
ValueWithState( T &value )
: m_Value ( value )
, m_State( true )
{}
const T& operator()() const
{
return m_Value;
}
void operator()( const T &value )
{
m_Value = value;
m_State = true;
}
bool IsValid() const
{
return m_State;
}
void Invalidate()
{
m_State = false;
}
};
const FrameInfos m_eFrameInfos;
const bool m_bRGB;
const ColorProcessing m_eColorProcessing;
ValueWithState<double> m_FrameTime;
ValueWithState<VmbUint64_t> m_FrameID;
#ifdef WIN32
double m_dFrequency;
#endif //WIN32
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,246 @@
/*=============================================================================
Copyright (C) 2014 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ProgrammConfig.h
Description:
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef PROGRAM_CONFIG_H_
#define PROGRAM_CONFIG_H_
#include <cstring>
#include "BaseException.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ProgramConfigException: public BaseException
{
public:
ProgramConfigException( const char* const &fun, const char* const& msg, VmbErrorType result = VmbErrorOther )
: BaseException( fun, msg, result )
{
}
~ProgramConfigException() throw()
{}
};
enum FrameInfos
{
FrameInfos_Off,
FrameInfos_Show,
FrameInfos_Automatic
};
enum ColorProcessing
{
ColorProcessing_Off,
ColorProcessing_Matrix,
};
struct ProgramConfig
{
FrameInfos m_FrameInfos;
bool m_RGBValue;
ColorProcessing m_ColorProcessing;
std::string m_CameraID;
bool m_PrintHelp;
bool m_UseAllocAndAnnounce;
public:
ProgramConfig()
: m_FrameInfos( AVT::VmbAPI::Examples::FrameInfos_Off )
, m_RGBValue( false )
, m_ColorProcessing( ColorProcessing_Off )
, m_PrintHelp( false )
, m_UseAllocAndAnnounce( false )
{
}
VmbErrorType ParseCommandline( int argc, char* argv[] )
{
VmbErrorType Result = VmbErrorSuccess;
char * pParameter = NULL; // The command line parameter
for( int i = 1; i < argc; ++i )
{
pParameter = argv[i];
if( 0 >= std::strlen( pParameter ))
{
return VmbErrorBadParameter;
}
if( '/' == pParameter[0] )
{
if( 0 == std::strcmp( pParameter, "/i" ))
{
if( ( FrameInfos_Off != getFrameInfos() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setFrameInfos( FrameInfos_Show );
}
else if( 0 == std::strcmp( pParameter, "/a" ))
{
if( ( FrameInfos_Off != getFrameInfos() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setFrameInfos( FrameInfos_Automatic );
}
else if( 0 == std::strcmp( pParameter, "/h" ))
{
if( ( ! getCameraID().empty() )
|| ( getPrintHelp() )
|| ( AVT::VmbAPI::Examples::FrameInfos_Off != getFrameInfos() ))
{
return VmbErrorBadParameter;
}
setPrintHelp( true );
}
else if( 0 == std::strcmp( pParameter, "/r" ))
{
if( getPrintHelp() )
{
return VmbErrorBadParameter;
}
setRGBValue( true );
}
else if( 0 == std::strcmp( pParameter, "/c" ))
{
if( ( ColorProcessing_Off != getColorProcessing() )
|| ( getPrintHelp() ))
{
return VmbErrorBadParameter;
}
setColorProcessing( ColorProcessing_Matrix );
setRGBValue( true );
}
else if( 0 == std::strcmp( pParameter, "/x" ))
{
if( getPrintHelp() )
{
return VmbErrorBadParameter;
}
setAllocAndAnnounce( true );
}
else
{
return VmbErrorBadParameter;
}
}
else
{
if( !getCameraID().empty() )
{
return VmbErrorBadParameter;
}
setCameraID( pParameter );
}
}
return Result;
}
FrameInfos getFrameInfos() const
{
return m_FrameInfos;
}
void setFrameInfos( FrameInfos infos )
{
m_FrameInfos = infos;
}
bool getRGBValue() const
{
return m_RGBValue;
}
void setRGBValue( bool RGBValue )
{
m_RGBValue = RGBValue;
}
ColorProcessing getColorProcessing() const
{
return m_ColorProcessing;
}
void setColorProcessing( ColorProcessing processing )
{
m_ColorProcessing = processing;
}
bool getAllocAndAnnounce() const
{
return m_UseAllocAndAnnounce;
}
void setAllocAndAnnounce( bool useAllocAndAnnounce )
{
m_UseAllocAndAnnounce = useAllocAndAnnounce;
}
const std::string& getCameraID() const
{
return m_CameraID;
}
void setCameraID( const std::string &name )
{
m_CameraID = name;
}
void setCameraID( const char* const&name )
{
if( NULL != name )
{
m_CameraID = std::string( name );
}
else
{
throw ProgramConfigException(__FUNCTION__,"null pointer in name parameter", VmbErrorBadParameter);
}
}
bool getPrintHelp() const
{
return m_PrintHelp;
}
void setPrintHelp( bool state )
{
m_PrintHelp = state;
}
template <typename STREAM_TYPE>
static STREAM_TYPE& PrintHelp( STREAM_TYPE &s )
{
s<<"Usage: AsynchronousGrab [CameraID] [/i] [/h]\n";
s<<"Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
s<<" /i Show frame infos\n";
s<<" /a Automatically only show frame infos of corrupt frames\n";
s<<" /h Print out help\n";
s<<" /r Convert to RGB and show RGB values\n";
s<<" /c Color correction (includes /r)\n";
s<<" /x Use AllocAndAnnounceFrame instead of AnnounceFrame\n";
return s;
}
};
}}}
#endif

View File

@@ -0,0 +1,163 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ImageTransform.h
Description: Image transformation of Vimba images
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef TRANSFORM_IMAGE_H_
#define TRANSFORM_IMAGE_H_
#include <vector>
#include <string>
#include "VmbTransform.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
VmbErrorType TransformImage( const FramePtr & SourceFrame, std::vector<VmbUchar_t> & DestinationData, const std::string &DestinationFormat )
{
if( SP_ISNULL( SourceFrame) )
{
return VmbErrorBadParameter;
}
VmbErrorType Result;
VmbPixelFormatType InputFormat;
VmbUint32_t InputWidth,InputHeight;
Result = SP_ACCESS( SourceFrame )->GetPixelFormat( InputFormat ) ;
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetWidth( InputWidth );
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetHeight( InputHeight );
if( VmbErrorSuccess != Result )
{
return Result;
}
// Prepare source image
VmbImage SourceImage;
SourceImage.Size = sizeof( SourceImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromPixelFormat( InputFormat, InputWidth, InputHeight, &SourceImage ));
if( VmbErrorSuccess != Result )
{
return Result;
}
VmbUchar_t *DataBegin = NULL;
Result = SP_ACCESS( SourceFrame )->GetBuffer( DataBegin );
if( VmbErrorSuccess != Result )
{
return Result;
}
SourceImage.Data = DataBegin;
// Prepare destination image
VmbImage DestinationImage;
DestinationImage.Size = sizeof( DestinationImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromString( DestinationFormat.c_str(), static_cast<VmbUint32_t>(DestinationFormat.size()), InputWidth, InputHeight, &DestinationImage) );
if ( VmbErrorSuccess != Result )
{
return Result;
}
const size_t ByteCount = ( DestinationImage.ImageInfo.PixelInfo.BitsPerPixel * InputWidth* InputHeight ) / 8 ;
DestinationData.resize( ByteCount );
DestinationImage.Data = &*DestinationData.begin();
// Transform data
Result = static_cast<VmbErrorType>( VmbImageTransform( &SourceImage, &DestinationImage, NULL , 0 ));
return Result;
}
VmbErrorType TransformImage( const FramePtr & SourceFrame, std::vector<VmbUchar_t> & DestinationData, const std::string &DestinationFormat, const VmbFloat_t *Matrix )
{
if( SP_ISNULL( SourceFrame ))
{
return VmbErrorBadParameter;
}
if ( NULL == Matrix )
{
return VmbErrorBadParameter;
}
VmbErrorType Result;
VmbPixelFormatType InputFormat;
VmbUint32_t InputWidth,InputHeight;
Result = SP_ACCESS( SourceFrame )->GetPixelFormat( InputFormat ) ;
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetWidth( InputWidth );
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = SP_ACCESS( SourceFrame )->GetHeight( InputHeight );
if( VmbErrorSuccess != Result )
{
return Result;
}
// Prepare source image
VmbImage SourceImage;
SourceImage.Size = sizeof( SourceImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromPixelFormat( InputFormat, InputWidth, InputHeight, &SourceImage ));
if( VmbErrorSuccess != Result)
{
return Result;
}
VmbUchar_t *DataBegin = NULL;
Result = SP_ACCESS( SourceFrame )->GetBuffer( DataBegin );
if( VmbErrorSuccess != Result )
{
return Result;
}
SourceImage.Data = DataBegin;
// Prepare destination image
VmbImage DestinationImage;
DestinationImage.Size = sizeof( DestinationImage );
Result = static_cast<VmbErrorType>( VmbSetImageInfoFromString( DestinationFormat.c_str(), static_cast<VmbUint32_t>(DestinationFormat.size()), InputWidth, InputHeight, &DestinationImage ));
if ( VmbErrorSuccess != Result )
{
return Result;
}
const size_t ByteCount = ( DestinationImage.ImageInfo.PixelInfo.BitsPerPixel * InputWidth* InputHeight ) / 8 ;
DestinationData.resize( ByteCount );
DestinationImage.Data = &*DestinationData.begin();
// Setup Transform parameter
// Transform data
VmbTransformInfo TransformInfo;
Result = static_cast<VmbErrorType>( VmbSetColorCorrectionMatrix3x3( Matrix, &TransformInfo ));
if( VmbErrorSuccess != Result )
{
return Result;
}
Result = static_cast<VmbErrorType>( VmbImageTransform( &SourceImage, &DestinationImage, &TransformInfo , 1 ));
return Result;
}
}}}
#endif

View File

@@ -0,0 +1,119 @@
/*=============================================================================
Copyright (C) 2013 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Implementation of main entry point of AsynchronousGrabConsole
example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <string>
#include <cstring>
#include <iostream>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "ApiController.h"
int main( int argc, char* argv[] )
{
VmbErrorType err = VmbErrorSuccess;
std::cout<<"///////////////////////////////////////////\n";
std::cout<<"/// Vimba API Asynchronous Grab Example ///\n";
std::cout<<"///////////////////////////////////////////\n\n";
//////////////////////
//Parse command line//
//////////////////////
AVT::VmbAPI::Examples::ProgramConfig Config;
err = Config.ParseCommandline( argc, argv);
//Write out an error if we could not parse the command line
if ( VmbErrorBadParameter == err )
{
std::cout<< "Invalid parameters!\n\n" ;
Config.setPrintHelp( true );
}
//Print out help and end program
if ( Config.getPrintHelp() )
{
Config.PrintHelp( std::cout );
}
else
{
AVT::VmbAPI::Examples::ApiController apiController;
// Print out version of Vimba
std::cout<<"Vimba C++ API Version "<<apiController.GetVersion()<<"\n";
// Startup Vimba
err = apiController.StartUp();
if ( VmbErrorSuccess == err )
{
if( Config.getCameraID().empty() )
{
AVT::VmbAPI::CameraPtrVector cameras = apiController.GetCameraList();
if( cameras.empty() )
{
err = VmbErrorNotFound;
}
else
{
std::string strCameraID;
err = cameras[0]->GetID( strCameraID );
if( VmbErrorSuccess == err )
{
Config.setCameraID( strCameraID );
}
}
}
if ( VmbErrorSuccess == err )
{
std::cout<<"Opening camera with ID: "<<Config.getCameraID()<<"\n";
err = apiController.StartContinuousImageAcquisition( Config );
if ( VmbErrorSuccess == err )
{
std::cout<< "Press <enter> to stop acquisition...\n" ;
getchar();
apiController.StopContinuousImageAcquisition();
}
}
apiController.ShutDown();
}
if ( VmbErrorSuccess == err )
{
std::cout<<"\nAcquisition stopped.\n" ;
}
else
{
std::string strError = apiController.ErrorCodeToMessage( err );
std::cout<<"\nAn error occurred: " << strError << "\n";
}
}
return err;
}

View File

@@ -0,0 +1,84 @@
PROJECT_NAME = AsynchronousGrabQt
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/../..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
include $(MAKE_INCLUDE_DIR)/Qt.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
-I$(OBJ_DIR)
LIBS = $(VIMBACPP_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
$(QTCORE_LIBS) \
$(QTGUI_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS) \
$(QTCORE_CFLAGS) \
$(QTGUI_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
$(OBJ_DIR)/AsynchronousGrab.o \
$(OBJ_DIR)/CameraObserver.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/main.o \
$(OBJ_DIR)/moc_AsynchronousGrab.o \
$(OBJ_DIR)/moc_CameraObserver.o \
$(OBJ_DIR)/moc_FrameObserver.o \
$(OBJ_DIR)/qrc_AsynchronousGrab.o
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
DEPENDENCIES = VimbaCPP \
VimbaImageTransform \
QtCore \
QtGui
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
$(MOC) -o $@ $<
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
$(UIC) -o $@ $<
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
$(RCC) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,340 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.cpp
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <ApiController.h>
#include <sstream>
#include <iostream>
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
enum { NUM_FRAMES=3, };
ApiController::ApiController()
// Get a reference to the Vimba singleton
: m_system( VimbaSystem::GetInstance() )
{
}
ApiController::~ApiController()
{
}
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartUp()
{
VmbErrorType res;
// Start Vimba
res = m_system.Startup();
if( VmbErrorSuccess == res )
{
// This will be wrapped in a shared_ptr so we don't delete it
SP_SET( m_pCameraObserver , new CameraObserver() );
// Register an observer whose callback routine gets triggered whenever a camera is plugged in or out
res = m_system.RegisterCameraListObserver( m_pCameraObserver );
}
return res;
}
//
// Shuts down the API
//
void ApiController::ShutDown()
{
// Release Vimba
m_system.Shutdown();
}
/*** helper function to set image size to a value that is dividable by modulo 2 and a multiple of the increment.
\note this is needed because VimbaImageTransform does not support odd values for some input formats
*/
inline VmbErrorType SetValueIntMod2( const CameraPtr &camera, const std::string &featureName, VmbInt64_t &storage )
{
VmbErrorType res;
FeaturePtr pFeature;
VmbInt64_t minValue = 0;
VmbInt64_t maxValue = 0;
VmbInt64_t incrementValue = 0;
res = SP_ACCESS( camera )->GetFeatureByName( featureName.c_str(), pFeature );
if( VmbErrorSuccess != res )
{
return res;
}
res = SP_ACCESS( pFeature )->GetRange( minValue, maxValue );
if( VmbErrorSuccess != res )
{
return res;
}
res = SP_ACCESS( pFeature )->GetIncrement( incrementValue);
if( VmbErrorSuccess != res)
{
return res;
}
maxValue = maxValue - ( maxValue % incrementValue );
if( maxValue % 2 != 0)
{
maxValue -= incrementValue;
}
res = SP_ACCESS( pFeature )->SetValue( maxValue );
if( VmbErrorSuccess != res )
{
return res;
}
storage = maxValue;
return res;
}
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartContinuousImageAcquisition( const std::string &rStrCameraID )
{
// Open the desired camera by its ID
VmbErrorType res = m_system.OpenCameraByID( rStrCameraID.c_str(), VmbAccessModeFull, m_pCamera );
if( VmbErrorSuccess == res )
{
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
FeaturePtr pCommandFeature;
if( VmbErrorSuccess == SP_ACCESS( m_pCamera )->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ) )
{
if( VmbErrorSuccess == SP_ACCESS( pCommandFeature )->RunCommand() )
{
bool bIsCommandDone = false;
do
{
if( VmbErrorSuccess != SP_ACCESS( pCommandFeature )->IsCommandDone( bIsCommandDone ) )
{
break;
}
} while( false == bIsCommandDone );
}
}
res = SetValueIntMod2( m_pCamera,"Width", m_nWidth );
if( VmbErrorSuccess == res )
{
res = SetValueIntMod2( m_pCamera, "Height", m_nHeight );
if( VmbErrorSuccess == res )
{
// Store currently selected image format
FeaturePtr pFormatFeature;
res = SP_ACCESS( m_pCamera )->GetFeatureByName( "PixelFormat", pFormatFeature );
if( VmbErrorSuccess == res )
{
res = SP_ACCESS( pFormatFeature )->GetValue( m_nPixelFormat );
if ( VmbErrorSuccess == res )
{
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
SP_SET( m_pFrameObserver , new FrameObserver( m_pCamera ) );
// Start streaming
res = SP_ACCESS( m_pCamera )->StartContinuousImageAcquisition( NUM_FRAMES, m_pFrameObserver );
}
}
}
}
if ( VmbErrorSuccess != res )
{
// If anything fails after opening the camera we close it
SP_ACCESS( m_pCamera )->Close();
}
}
return res;
}
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StopContinuousImageAcquisition()
{
// Stop streaming
SP_ACCESS( m_pCamera )->StopContinuousImageAcquisition();
// Close camera
return m_pCamera->Close();
}
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector ApiController::GetCameraList()
{
CameraPtrVector cameras;
// Get all known cameras
if( VmbErrorSuccess == m_system.GetCameras( cameras ) )
{
// And return them
return cameras;
}
return CameraPtrVector();
}
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int ApiController::GetWidth() const
{
return static_cast<int>(m_nWidth);
}
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int ApiController::GetHeight() const
{
return static_cast<int>(m_nHeight);
}
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType ApiController::GetPixelFormat() const
{
return static_cast<VmbPixelFormatType>(m_nPixelFormat);
}
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr ApiController::GetFrame()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver )->GetFrame();
}
//
// Clears all remaining frames that have not been picked up
//
void ApiController::ClearFrameQueue()
{
SP_DYN_CAST( m_pFrameObserver,FrameObserver )->ClearFrameQueue();
}
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType ApiController::QueueFrame( FramePtr pFrame )
{
return SP_ACCESS( m_pCamera )->QueueFrame( pFrame );
}
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetCameraObserver()
{
return SP_DYN_CAST( m_pCameraObserver, CameraObserver ).get();
}
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetFrameObserver()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver ).get();
}
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string ApiController::GetVersion() const
{
std::ostringstream os;
os << m_system;
return os.str();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,191 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.h
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
#include <string>
#include <VimbaCPP/Include/VimbaCPP.h>
#include <CameraObserver.h>
#include <FrameObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ApiController
{
public:
ApiController();
~ApiController();
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType StartUp();
//
// Shuts down the API
//
void ShutDown();
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType StartContinuousImageAcquisition( const std::string &rStrCameraID );
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType StopContinuousImageAcquisition();
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int GetWidth() const;
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int GetHeight() const;
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType GetPixelFormat() const;
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector GetCameraList();
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr GetFrame();
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType QueueFrame( FramePtr pFrame );
//
// Clears all remaining frames that have not been picked up
//
void ClearFrameQueue();
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetCameraObserver();
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetFrameObserver();
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string GetVersion() const;
private:
// A reference to our Vimba singleton
VimbaSystem& m_system;
// The currently streaming camera
CameraPtr m_pCamera;
// Every camera has its own frame observer
IFrameObserverPtr m_pFrameObserver;
// Our camera observer
ICameraListObserverPtr m_pCameraObserver;
// The current pixel format
VmbInt64_t m_nPixelFormat;
// The current width
VmbInt64_t m_nWidth;
// The current height
VmbInt64_t m_nHeight;
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,354 @@
/*=============================================================================
Copyright (C) 2012 - 2017 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: AsynchronousGrab.cpp
Description: Qt dialog class for the GUI of the AsynchronousGrab example of
VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include "AsynchronousGrab.h"
#include "VmbTransform.h"
#define NUM_COLORS 3
#define BIT_DEPTH 8
using AVT::VmbAPI::FramePtr;
using AVT::VmbAPI::CameraPtrVector;
AsynchronousGrab::AsynchronousGrab( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, m_bIsStreaming( false )
{
ui.setupUi( this );
ui.m_LabelStream->setAlignment(Qt::AlignCenter );
// Connect GUI events with event handlers
QObject::connect( ui.m_ButtonStartStop, SIGNAL( clicked() ), this, SLOT( OnBnClickedButtonStartstop() ) );
// Start Vimba
VmbErrorType err = m_ApiController.StartUp();
setWindowTitle( QString( "AsynchronousGrab (Qt version) Vimba C++ API Version " )+ QString::fromStdString( m_ApiController.GetVersion() ) );
Log( "Starting Vimba", err );
if( VmbErrorSuccess == err )
{
// Connect new camera found event with event handler
QObject::connect( m_ApiController.GetCameraObserver(), SIGNAL( CameraListChangedSignal(int) ), this, SLOT( OnCameraListChanged(int) ) );
// Initially get all connected cameras
UpdateCameraListBox();
std::stringstream strMsg;
strMsg << "Cameras found..." << m_cameras.size();
Log(strMsg.str() );
}
}
AsynchronousGrab::~AsynchronousGrab()
{
// if we are streaming stop streaming
if( true == m_bIsStreaming )
{
OnBnClickedButtonStartstop();
}
// Before we close the application we stop Vimba
m_ApiController.ShutDown();
}
void AsynchronousGrab::OnBnClickedButtonStartstop()
{
VmbErrorType err;
int nRow = ui.m_ListBoxCameras->currentRow();
if( -1 < nRow )
{
if( false == m_bIsStreaming )
{
// Start acquisition
err = m_ApiController.StartContinuousImageAcquisition( m_cameras[nRow] );
// Set up Qt image
if ( VmbErrorSuccess == err )
{
m_Image = QImage( m_ApiController.GetWidth(),
m_ApiController.GetHeight(),
QImage::Format_RGB888 );
QObject::connect( m_ApiController.GetFrameObserver(), SIGNAL( FrameReceivedSignal(int) ), this, SLOT( OnFrameReady(int) ) );
}
Log( "Starting Acquisition", err );
m_bIsStreaming = VmbErrorSuccess == err;
}
else
{
m_bIsStreaming = false;
// Stop acquisition
err = m_ApiController.StopContinuousImageAcquisition();
// Clear all frames that we have not picked up so far
m_ApiController.ClearFrameQueue();
m_Image = QImage();
Log( "Stopping Acquisition", err );
}
if( false == m_bIsStreaming )
{
ui.m_ButtonStartStop->setText( QString( "Start Image Acquisition" ) );
}
else
{
ui.m_ButtonStartStop->setText( QString( "Stop Image Acquisition" ) );
}
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
//
// Parameters:
// [in] status The frame receive status (complete, incomplete, ...)
//
void AsynchronousGrab::OnFrameReady( int status )
{
if( true == m_bIsStreaming )
{
// Pick up frame
FramePtr pFrame = m_ApiController.GetFrame();
if( SP_ISNULL( pFrame ) )
{
Log("frame pointer is NULL, late frame ready message");
return;
}
// See if it is not corrupt
if( VmbFrameStatusComplete == status )
{
VmbUchar_t *pBuffer;
VmbErrorType err = SP_ACCESS( pFrame )->GetImage( pBuffer );
if( VmbErrorSuccess == err )
{
VmbUint32_t nSize;
err = SP_ACCESS( pFrame )->GetImageSize( nSize );
if( VmbErrorSuccess == err )
{
VmbPixelFormatType ePixelFormat = m_ApiController.GetPixelFormat();
if( ! m_Image.isNull() )
{
// Copy it
// We need that because Qt might repaint the view after we have released the frame already
if( ui.m_ColorProcessingCheckBox->checkState()== Qt::Checked )
{
static const VmbFloat_t Matrix[] = { 8.0f, 0.1f, 0.1f, // this matrix just makes a quick color to mono conversion
0.1f, 0.8f, 0.1f,
0.0f, 0.0f, 1.0f };
if( VmbErrorSuccess != CopyToImage( pBuffer,ePixelFormat, m_Image, Matrix ) )
{
ui.m_ColorProcessingCheckBox->setChecked( false );
}
}
else
{
CopyToImage( pBuffer,ePixelFormat, m_Image );
}
// Display it
const QSize s = ui.m_LabelStream->size() ;
ui.m_LabelStream->setPixmap( QPixmap::fromImage( m_Image ).scaled(s,Qt::KeepAspectRatio ) );
}
}
}
}
else
{
// If we receive an incomplete image we do nothing but logging
Log( "Failure in receiving image", VmbErrorOther );
}
// And queue it to continue streaming
m_ApiController.QueueFrame( pFrame );
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
//
// Parameters:
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
//
void AsynchronousGrab::OnCameraListChanged( int reason )
{
bool bUpdateList = false;
// We only react on new cameras being found and known cameras being unplugged
if( AVT::VmbAPI::UpdateTriggerPluggedIn == reason )
{
Log( "Camera list changed. A new camera was discovered by Vimba." );
bUpdateList = true;
}
else if( AVT::VmbAPI::UpdateTriggerPluggedOut == reason )
{
Log( "Camera list changed. A camera was disconnected from Vimba." );
if( true == m_bIsStreaming )
{
OnBnClickedButtonStartstop();
}
bUpdateList = true;
}
if( true == bUpdateList )
{
UpdateCameraListBox();
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
//
// Parameters:
// [in] pInbuffer The byte buffer as received from the cam
// [in] ePixelFormat The pixel format of the frame
// [out] OutImage The filled Qt image
//
VmbErrorType AsynchronousGrab::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix /*= NULL */ )
{
const int nHeight = m_ApiController.GetHeight();
const int nWidth = m_ApiController.GetWidth();
VmbImage SourceImage,DestImage;
VmbError_t Result;
SourceImage.Size = sizeof( SourceImage );
DestImage.Size = sizeof( DestImage );
Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, & SourceImage );
if( VmbErrorSuccess != Result )
{
Log( "Could not set source image info", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
QString OutputFormat;
const int bytes_per_line = pOutImage.bytesPerLine();
switch( pOutImage.format() )
{
default:
Log( "unknown output format",VmbErrorBadParameter );
return VmbErrorBadParameter;
case QImage::Format_RGB888:
if( nWidth*3 != bytes_per_line )
{
Log( "image transform does not support stride",VmbErrorWrongType );
return VmbErrorWrongType;
}
OutputFormat = "RGB24";
break;
}
Result = VmbSetImageInfoFromString( OutputFormat.toStdString().c_str(), OutputFormat.length(),nWidth,nHeight, &DestImage );
if( VmbErrorSuccess != Result )
{
Log( "could not set output image info",static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
SourceImage.Data = pInBuffer;
DestImage.Data = pOutImage.bits();
// do color processing?
if( NULL != Matrix )
{
VmbTransformInfo TransformParameter;
Result = VmbSetColorCorrectionMatrix3x3( Matrix, &TransformParameter );
if( VmbErrorSuccess == Result )
{
Result = VmbImageTransform( &SourceImage, &DestImage, &TransformParameter,1 );
}
else
{
Log( "could not set matrix t o transform info ", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
}
else
{
Result = VmbImageTransform( &SourceImage, &DestImage,NULL,0 );
}
if( VmbErrorSuccess != Result )
{
Log( "could not transform image", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
return static_cast<VmbErrorType>( Result );
}
//
// Queries and lists all known camera
//
void AsynchronousGrab::UpdateCameraListBox()
{
// Get all cameras currently connected to Vimba
CameraPtrVector cameras = m_ApiController.GetCameraList();
// Simply forget about all cameras known so far
ui.m_ListBoxCameras->clear();
m_cameras.clear();
// And query the camera details again
for( CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
std::string strCameraName;
std::string strCameraID;
if( VmbErrorSuccess != (*iter)->GetName( strCameraName ) )
{
strCameraName = "[NoName]";
}
// If for any reason we cannot get the ID of a camera we skip it
if( VmbErrorSuccess == (*iter)->GetID( strCameraID ) )
{
ui.m_ListBoxCameras->addItem( QString::fromStdString( strCameraName + " " +strCameraID ) );
m_cameras.push_back( strCameraID );
}
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Prints out a given logging string, error code and the descriptive representation of that error code
//
// Parameters:
// [in] strMsg A given message to be printed out
// [in] eErr The API status code
//
void AsynchronousGrab::Log( std::string strMsg, VmbErrorType eErr )
{
strMsg += "..." + m_ApiController.ErrorCodeToMessage( eErr );
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}
//
// Prints out a given logging string
//
// Parameters:
// [in] strMsg A given message to be printed out
//
void AsynchronousGrab::Log( std::string strMsg)
{
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}

View File

@@ -0,0 +1,112 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: AsynchronousGrab.h
Description: Qt dialog class for the GUI of the AsynchronousGrab example of
VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef ASYNCHRONOUSGRABQT_H
#define ASYNCHRONOUSGRABQT_H
#include <QMainWindow>
#include "ui_AsynchronousGrab.h"
#include <ApiController.h>
using AVT::VmbAPI::Examples::ApiController;
class AsynchronousGrab : public QMainWindow
{
Q_OBJECT
public:
AsynchronousGrab( QWidget *parent = 0, Qt::WindowFlags flags = 0 );
~AsynchronousGrab();
private:
// The Qt GUI
Ui::AsynchronousGrabClass ui;
// Our controller that wraps API access
ApiController m_ApiController;
// A list of known camera IDs
std::vector<std::string> m_cameras;
// Are we streaming?
bool m_bIsStreaming;
// Our Qt image to display
QImage m_Image;
//
// Queries and lists all known camera
//
void UpdateCameraListBox();
//
// Prints out a given logging string, error code and the descriptive representation of that error code
//
// Parameters:
// [in] strMsg A given message to be printed out
// [in] eErr The API status code
//
void Log( std::string strMsg, VmbErrorType eErr );
//
// Prints out a given logging string
//
// Parameters:
// [in] strMsg A given message to be printed out
//
void Log( std::string strMsg);
//
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
//
// Parameters:
// [in] pInbuffer The byte buffer as received from the cam
// [in] ePixelFormat The pixel format of the frame
// [out] OutImage The filled Qt image
//
VmbErrorType CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix = NULL );
private slots:
// The event handler for starting / stopping acquisition
void OnBnClickedButtonStartstop();
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
//
// Parameters:
// [in] status The frame receive status (complete, incomplete, ...)
//
void OnFrameReady( int status );
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
//
// Parameters:
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
//
void OnCameraListChanged( int reason );
};
#endif // ASYNCHRONOUSGRABQT_H

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraObserver.cpp
Description: The camera observer that is used for notifications from VimbaCPP
regarding a change in the camera list.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <CameraObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// This is our callback routine that will be executed every time a camera was plugged in or out
//
// Parameters:
// [in] pCam The camera that triggered the callback
// [in] reason The reason why the callback was triggered
//
void CameraObserver::CameraListChanged( CameraPtr pCam, UpdateTriggerType reason )
{
if ( UpdateTriggerPluggedIn == reason
|| UpdateTriggerPluggedOut == reason )
{
// Emit the new camera signal
emit CameraListChangedSignal( reason );
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,66 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraObserver.h
Description: The camera observer that is used for notifications from VimbaCPP
regarding a change in the camera list.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
#define AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
#include <QObject>
#include <VimbaCPP/Include/VimbaCPP.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class CameraObserver : public QObject, public ICameraListObserver
{
Q_OBJECT
public:
//
// This is our callback routine that will be executed every time a camera was plugged in or out
//
// Parameters:
// [in] pCam The camera that triggered the callback
// [in] reason The reason why the callback was triggered
//
virtual void CameraListChanged( CameraPtr pCamera, UpdateTriggerType reason );
signals:
//
// The camera list changed event (Qt signal) that notifies about a camera change and its reason
//
// Parameters:
// [out] reason The reason why this event was fired
//
void CameraListChangedSignal( int reason );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,105 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <FrameObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void FrameObserver::FrameReceived( const FramePtr pFrame )
{
bool bQueueDirectly = true;
VmbFrameStatusType eReceiveStatus;
if( 0 != receivers(SIGNAL(FrameReceivedSignal(int)) )
&& VmbErrorSuccess == pFrame->GetReceiveStatus( eReceiveStatus ) )
{
// Lock the frame queue
m_FramesMutex.lock();
// Add frame to queue
m_Frames.push( pFrame );
// Unlock frame queue
m_FramesMutex.unlock();
// Emit the frame received signal
emit FrameReceivedSignal( eReceiveStatus );
bQueueDirectly = false;
}
// If any error occurred we queue the frame without notification
if( true == bQueueDirectly )
{
m_pCamera->QueueFrame( pFrame );
}
}
//
// After the view has been notified about a new frame it can pick it up.
// It is then removed from the internal queue
//
// Returns:
// A shared pointer to the latest frame
//
FramePtr FrameObserver::GetFrame()
{
// Lock the frame queue
m_FramesMutex.lock();
// Pop frame from queue
FramePtr res;
if( !m_Frames.empty() )
{
res = m_Frames.front();
m_Frames.pop();
}
// Unlock frame queue
m_FramesMutex.unlock();
return res;
}
//
// Clears the internal (double buffering) frame queue
//
void FrameObserver::ClearFrameQueue()
{
// Lock the frame queue
m_FramesMutex.lock();
// Clear the frame queue and release the memory
std::queue<FramePtr> empty;
std::swap( m_Frames, empty );
// Unlock the frame queue
m_FramesMutex.unlock();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,97 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include <queue>
#include <QObject>
#include <QMutex>
#include <VimbaCPP/Include/VimbaCPP.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class FrameObserver : public QObject, virtual public IFrameObserver
{
Q_OBJECT
public:
//
// We pass the camera that will deliver the frames to the constructor
//
// Parameters:
// [in] pCamera The camera the frame was queued at
//
FrameObserver( CameraPtr pCamera ) : IFrameObserver( pCamera ) {;}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr pFrame );
//
// After the view has been notified about a new frame it can pick it up.
// It is then removed from the internal queue
//
// Returns:
// A shared pointer to the latest frame
//
FramePtr GetFrame();
//
// Clears the internal (double buffering) frame queue
//
void ClearFrameQueue();
private:
// Since a Qt signal cannot contain a whole frame
// the frame observer stores all FramePtr
std::queue<FramePtr> m_Frames;
QMutex m_FramesMutex;
signals:
//
// The frame received event (Qt signal) that notifies about a new incoming frame
//
// Parameters:
// [out] status The frame receive status
//
void FrameReceivedSignal( int status );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,37 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: main.cpp
Description: The main entry point of the AsynchronousGrab example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "AsynchronousGrab.h"
#include <QApplication>
int main( int argc, char *argv[] )
{
QApplication a( argc, argv );
AsynchronousGrab w;
w.show();
return a.exec();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/AsynchronousGrabQt">
<file>AsynchronousGrab.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AsynchronousGrabClass</class>
<widget class="QMainWindow" name="AsynchronousGrabClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1040</width>
<height>780</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1040</width>
<height>780</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1040</width>
<height>780</height>
</size>
</property>
<property name="windowTitle">
<string>AsynchronousGrab (Qt version)</string>
</property>
<property name="windowIcon">
<iconset resource="AsynchronousGrab.qrc">
<normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QListWidget" name="m_ListBoxCameras">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>261</width>
<height>491</height>
</rect>
</property>
</widget>
<widget class="QListWidget" name="m_ListLog">
<property name="geometry">
<rect>
<x>0</x>
<y>580</y>
<width>1041</width>
<height>191</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="m_ButtonStartStop">
<property name="geometry">
<rect>
<x>0</x>
<y>540</y>
<width>261</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Start Image Acquisition</string>
</property>
</widget>
<widget class="QLabel" name="m_LabelStream">
<property name="geometry">
<rect>
<x>270</x>
<y>10</y>
<width>771</width>
<height>561</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QCheckBox" name="m_ColorProcessingCheckBox">
<property name="geometry">
<rect>
<x>140</x>
<y>510</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>ColorProcessing</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="AsynchronousGrab.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,95 @@
PROJECT_NAME = AsynchronousOpenCVRecorder
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/../..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
include $(MAKE_INCLUDE_DIR)/Qt.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
-I$(OBJ_DIR)
OPENCV_CFLAGS = $(shell $(PKGCFG) --cflags opencv)
OPENCV_LIBS = $(shell $(PKGCFG) --libs opencv)
LIBS = $(VIMBACPP_LIBS) \
$(VIMBAIMAGETRANSFORM_LIBS) \
$(QTCORE_LIBS) \
$(QTGUI_LIBS) \
$(OPENCV_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(VIMBAIMAGETRANSFORM_CFLAGS) \
$(QTCORE_CFLAGS) \
$(QTGUI_CFLAGS) \
$(OPENCV_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
$(OBJ_DIR)/AsynchronousOpenCVRecorder.o \
$(OBJ_DIR)/CameraObserver.o \
$(OBJ_DIR)/FrameObserver.o \
$(OBJ_DIR)/main.o \
$(OBJ_DIR)/moc_AsynchronousOpenCVRecorder.o \
$(OBJ_DIR)/moc_CameraObserver.o \
$(OBJ_DIR)/moc_FrameObserver.o \
$(OBJ_DIR)/moc_OpenCVVideoRecorder.o \
$(OBJ_DIR)/qrc_AsynchronousOpenCVRecorder.o
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousOpenCVRecorder.h
DEPENDENCIES = VimbaCPP \
VimbaImageTransform \
QtCore \
QtGui
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
$(MOC) -o $@ $<
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
$(UIC) -o $@ $<
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
$(RCC) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,9 @@
build Linux
requirements:
Installed QT 4
OpenCV3
- Get libopencv-dev package or download from https://github.com/opencv/opencv/archive/3.0.0.tar.gz
- Create OpenCV makefile using CMake
- Build OpenCV by calling 'make' or 'make -j' for multithreaded build
- Install OpenCV by calling 'sudo make install'
For in-depth instructions please refer to: https://docs.opencv.org/3.0.0/d7/d9f/tutorial_linux_install.html

View File

@@ -0,0 +1,339 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.cpp
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <ApiController.h>
#include <sstream>
#include <iostream>
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
enum { NUM_FRAMES=3, };
ApiController::ApiController()
// Get a reference to the Vimba singleton
: m_system( VimbaSystem::GetInstance() )
{
}
ApiController::~ApiController()
{
}
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
{
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
}
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartUp()
{
VmbErrorType res;
// Start Vimba
res = m_system.Startup();
if( VmbErrorSuccess == res )
{
// This will be wrapped in a shared_ptr so we don't delete it
SP_SET( m_pCameraObserver , new CameraObserver() );
// Register an observer whose callback routine gets triggered whenever a camera is plugged in or out
res = m_system.RegisterCameraListObserver( m_pCameraObserver );
}
return res;
}
//
// Shuts down the API
//
void ApiController::ShutDown()
{
// Release Vimba
m_system.Shutdown();
}
/*** helper function to set image size to a value that is dividable by modulo 2.
\note this is needed because VimbaImageTransform does not support odd values for some input formats
*/
inline VmbErrorType SetValueIntMod2( const CameraPtr &camera, const std::string &featureName, VmbInt64_t &storage )
{
VmbErrorType res;
FeaturePtr pFeature;
res = SP_ACCESS( camera )->GetFeatureByName( featureName.c_str(), pFeature );
if( VmbErrorSuccess == res )
{
VmbInt64_t minValue,maxValue;
res = SP_ACCESS( pFeature )->GetRange( minValue,maxValue );
if( VmbErrorSuccess == res )
{
maxValue = ( maxValue>>1 )<<1; // mod 2 dividable
res = SP_ACCESS( pFeature )->SetValue( maxValue );
if( VmbErrorSuccess == res )
{
storage = maxValue;
}
}
}
return res;
}
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StartContinuousImageAcquisition( const std::string &rStrCameraID )
{
// Open the desired camera by its ID
VmbErrorType res = m_system.OpenCameraByID( rStrCameraID.c_str(), VmbAccessModeFull, m_pCamera );
if( VmbErrorSuccess == res )
{
// Set the GeV packet size to the highest possible value
// (In this example we do not test whether this cam actually is a GigE cam)
FeaturePtr pCommandFeature;
if( VmbErrorSuccess == SP_ACCESS( m_pCamera )->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ) )
{
if( VmbErrorSuccess == SP_ACCESS( pCommandFeature )->RunCommand() )
{
bool bIsCommandDone = false;
do
{
if( VmbErrorSuccess != SP_ACCESS( pCommandFeature )->IsCommandDone( bIsCommandDone ) )
{
break;
}
} while( false == bIsCommandDone );
}
}
res = SetValueIntMod2( m_pCamera,"Width", m_nWidth );
if( VmbErrorSuccess == res )
{
res = SetValueIntMod2( m_pCamera, "Height", m_nHeight );
if( VmbErrorSuccess == res )
{
m_FPS = 15.0;
FeaturePtr pFeatureFPS ;
res = SP_ACCESS( m_pCamera )->GetFeatureByName("AcquisitionFrameRateAbs", pFeatureFPS);
if( VmbErrorSuccess != res)
{
// lets try other
res = SP_ACCESS( m_pCamera )->GetFeatureByName("AcquisitionFrameRate", pFeatureFPS);
}
if( VmbErrorSuccess == res )
{
res = SP_ACCESS(pFeatureFPS)->GetValue( m_FPS );
}
// Store currently selected image format
FeaturePtr pFormatFeature;
res = SP_ACCESS( m_pCamera )->GetFeatureByName( "PixelFormat", pFormatFeature );
if( VmbErrorSuccess == res )
{
res = SP_ACCESS( pFormatFeature )->GetValue( m_nPixelFormat );
if ( VmbErrorSuccess == res )
{
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
SP_SET( m_pFrameObserver , new FrameObserver( m_pCamera ) );
// Start streaming
res = SP_ACCESS( m_pCamera )->StartContinuousImageAcquisition( NUM_FRAMES, m_pFrameObserver );
}
}
}
}
}
return res;
}
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType ApiController::StopContinuousImageAcquisition()
{
// Stop streaming
m_pCamera->StopContinuousImageAcquisition();
// Close camera
return m_pCamera->Close();
}
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector ApiController::GetCameraList()
{
CameraPtrVector cameras;
// Get all known cameras
if( VmbErrorSuccess == m_system.GetCameras( cameras ) )
{
// And return them
return cameras;
}
return CameraPtrVector();
}
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int ApiController::GetWidth() const
{
return static_cast<int>(m_nWidth);
}
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int ApiController::GetHeight() const
{
return static_cast<int>(m_nHeight);
}
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType ApiController::GetPixelFormat() const
{
return static_cast<VmbPixelFormatType>(m_nPixelFormat);
}
//
// Gets the current frames per second
//
// Returns:
// Frame rate in Hertz
//
double ApiController::GetFPS() const
{
return m_FPS;
}
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr ApiController::GetFrame()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver )->GetFrame();
}
//
// Clears all remaining frames that have not been picked up
//
void ApiController::ClearFrameQueue()
{
SP_DYN_CAST( m_pFrameObserver,FrameObserver )->ClearFrameQueue();
}
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType ApiController::QueueFrame( FramePtr pFrame )
{
return SP_ACCESS( m_pCamera )->QueueFrame( pFrame );
}
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetCameraObserver()
{
return SP_DYN_CAST( m_pCameraObserver, CameraObserver ).get();
}
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* ApiController::GetFrameObserver()
{
return SP_DYN_CAST( m_pFrameObserver, FrameObserver ).get();
}
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string ApiController::GetVersion() const
{
std::ostringstream os;
os << m_system;
return os.str();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,201 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ApiController.h
Description: Implementation file for the ApiController helper class that
demonstrates how to implement an asynchronous, continuous image
acquisition with VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
#include <string>
#include <VimbaCPP/Include/VimbaCPP.h>
#include <CameraObserver.h>
#include <FrameObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ApiController
{
public:
ApiController();
~ApiController();
//
// Starts the Vimba API and loads all transport layers
//
// Returns:
// An API status code
//
VmbErrorType StartUp();
//
// Shuts down the API
//
void ShutDown();
//
// Opens the given camera
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Sets up the observer that will be notified on every incoming frame
// Calls the API convenience function to start image acquisition
// Closes the camera in case of failure
//
// Parameters:
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
//
// Returns:
// An API status code
//
VmbErrorType StartContinuousImageAcquisition( const std::string &rStrCameraID );
//
// Calls the API convenience function to stop image acquisition
// Closes the camera
//
// Returns:
// An API status code
//
VmbErrorType StopContinuousImageAcquisition();
//
// Gets the width of a frame
//
// Returns:
// The width as integer
//
int GetWidth() const;
//
// Gets the height of a frame
//
// Returns:
// The height as integer
//
int GetHeight() const;
//
// Gets the pixel format of a frame
//
// Returns:
// The pixel format as enum
//
VmbPixelFormatType GetPixelFormat() const;
//
// Gets the current frames per second
//
// Returns:
// Frame rate in Hertz
//
double GetFPS() const;
//
// Gets all cameras known to Vimba
//
// Returns:
// A vector of camera shared pointers
//
CameraPtrVector GetCameraList();
//
// Gets the oldest frame that has not been picked up yet
//
// Returns:
// A frame shared pointer
//
FramePtr GetFrame();
//
// Queues a given frame to be filled by the API
//
// Parameters:
// [in] pFrame The frame to queue
//
// Returns:
// An API status code
//
VmbErrorType QueueFrame( FramePtr pFrame );
//
// Clears all remaining frames that have not been picked up
//
void ClearFrameQueue();
//
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetCameraObserver();
//
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
//
QObject* GetFrameObserver();
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eErr The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
//
// Gets the version of the Vimba API
//
// Returns:
// The version as string
//
std::string GetVersion() const;
private:
// A reference to our Vimba singleton
VimbaSystem& m_system;
// The currently streaming camera
CameraPtr m_pCamera;
// Every camera has its own frame observer
IFrameObserverPtr m_pFrameObserver;
// Our camera observer
ICameraListObserverPtr m_pCameraObserver;
// The current pixel format
VmbInt64_t m_nPixelFormat;
// The current width
VmbInt64_t m_nWidth;
// The current height
VmbInt64_t m_nHeight;
// The current FPS
double m_FPS;
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,376 @@
/*=============================================================================
Copyright (C) 2015 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: AsynchronousOpenCVRecorder.cpp
Description: Qt dialog class for the GUI of the AsynchronousOpenCVRecorder
example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include "AsynchronousOpenCVRecorder.h"
#include "VmbTransform.h"
#define NUM_COLORS 3
#define BIT_DEPTH 8
using AVT::VmbAPI::FramePtr;
using AVT::VmbAPI::CameraPtrVector;
AsynchronousOpenCVRecorder::AsynchronousOpenCVRecorder( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, m_bIsStreaming( false )
{
ui.setupUi( this );
ui.m_LabelStream->setAlignment(Qt::AlignCenter );
// Connect GUI events with event handlers
QObject::connect( ui.m_ButtonStartStop, SIGNAL( clicked() ), this, SLOT( OnBnClickedButtonStartstop() ) );
// Start Vimba
VmbErrorType err = m_ApiController.StartUp();
setWindowTitle( QString( "Asynchronous OpenCV Recorder Vimba C++ API Version " )+ QString::fromStdString( m_ApiController.GetVersion() ) );
Log( "Starting Vimba", err );
if( VmbErrorSuccess == err )
{
// Connect new camera found event with event handler
QObject::connect( m_ApiController.GetCameraObserver(), SIGNAL( CameraListChangedSignal(int) ), this, SLOT( OnCameraListChanged(int) ) );
// Initially get all connected cameras
UpdateCameraListBox();
std::stringstream strMsg;
strMsg << "Cameras found..." << m_cameras.size();
Log(strMsg.str() );
}
}
AsynchronousOpenCVRecorder::~AsynchronousOpenCVRecorder()
{
// if we are streaming stop streaming
if( true == m_bIsStreaming )
OnBnClickedButtonStartstop();
// Before we close the application we stop Vimba
m_ApiController.ShutDown();
}
void AsynchronousOpenCVRecorder::OnBnClickedButtonStartstop()
{
VmbErrorType err;
int nRow = ui.m_ListBoxCameras->currentRow();
if( -1 < nRow )
{
if( false == m_bIsStreaming )
{
// Start acquisition
err = m_ApiController.StartContinuousImageAcquisition( m_cameras[nRow] );
// Set up Qt image
if ( VmbErrorSuccess == err)
{
VmbUint32_t Width = m_ApiController.GetWidth();
VmbUint32_t Height = m_ApiController.GetHeight();
double FPS = m_ApiController.GetFPS();
try
{
m_pVideoRecorder = OpenCVRecorderPtr( new OpenCVRecorder("AsynchronousOpenCVRecorder.avi", FPS, Width,Height) );
m_pVideoRecorder->start();
}
catch(const BaseException &bex)
{
Log( (bex.Function()+" :" + bex.Message() ).toStdString() );
}
m_Image = QImage( Width, Height, QImage::Format_RGB888 );
QObject::connect( m_ApiController.GetFrameObserver(), SIGNAL( FrameReceivedSignal(int) ), this, SLOT( OnFrameReady(int) ) );
}
Log( "Starting Acquisition", err );
m_bIsStreaming = VmbErrorSuccess == err;
}
else
{
if( !m_pVideoRecorder.isNull() )
{
m_pVideoRecorder->stopThread();
if( ! m_pVideoRecorder->wait( 1000 ) )
{
m_pVideoRecorder->terminate();
}
m_pVideoRecorder.clear();
}
m_bIsStreaming = false;
// Stop acquisition
err = m_ApiController.StopContinuousImageAcquisition();
// Clear all frames that we have not picked up so far
m_ApiController.ClearFrameQueue();
m_Image = QImage();
Log( "Stopping Acquisition", err );
}
if( false == m_bIsStreaming )
{
ui.m_ButtonStartStop->setText( QString( "Start Image Acquisition" ) );
}
else
{
ui.m_ButtonStartStop->setText( QString( "Stop Image Acquisition" ) );
}
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
//
// Parameters:
// [in] status The frame receive status (complete, incomplete, ...)
//
void AsynchronousOpenCVRecorder::OnFrameReady( int status )
{
if( true == m_bIsStreaming )
{
// Pick up frame
FramePtr pFrame = m_ApiController.GetFrame();
if( SP_ISNULL( pFrame ) )
{
Log("frame pointer is NULL, late frame ready message");
return;
}
// See if it is not corrupt
if( VmbFrameStatusComplete == status )
{
if(! m_pVideoRecorder.isNull() )
{
m_pVideoRecorder->enqueueFrame( *pFrame);
}
VmbUchar_t *pBuffer;
VmbErrorType err = SP_ACCESS( pFrame )->GetImage( pBuffer );
if( VmbErrorSuccess == err )
{
VmbUint32_t nSize;
err = SP_ACCESS( pFrame )->GetImageSize( nSize );
if( VmbErrorSuccess == err )
{
VmbPixelFormatType ePixelFormat = m_ApiController.GetPixelFormat();
if( ! m_Image.isNull() )
{
// Copy it
// We need that because Qt might repaint the view after we have released the frame already
if( ui.m_ColorProcessingCheckBox->checkState()== Qt::Checked )
{
static const VmbFloat_t Matrix[] = { 8.0f, 0.1f, 0.1f, // this matrix just makes a quick color to mono conversion
0.1f, 0.8f, 0.1f,
0.0f, 0.0f, 1.0f };
if( VmbErrorSuccess != CopyToImage( pBuffer,ePixelFormat, m_Image, Matrix ) )
{
ui.m_ColorProcessingCheckBox->setChecked( false );
}
}
else
{
CopyToImage( pBuffer,ePixelFormat, m_Image );
}
// Display it
const QSize s = ui.m_LabelStream->size() ;
ui.m_LabelStream->setPixmap( QPixmap::fromImage( m_Image ).scaled(s,Qt::KeepAspectRatio ) );
}
}
}
}
else
{
// If we receive an incomplete image we do nothing but logging
Log( "Failure in receiving image", VmbErrorOther );
}
// And queue it to continue streaming
m_ApiController.QueueFrame( pFrame );
}
}
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
//
// Parameters:
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
//
void AsynchronousOpenCVRecorder::OnCameraListChanged( int reason )
{
bool bUpdateList = false;
// We only react on new cameras being found and known cameras being unplugged
if( AVT::VmbAPI::UpdateTriggerPluggedIn == reason )
{
Log( "Camera list changed. A new camera was discovered by Vimba." );
bUpdateList = true;
}
else if( AVT::VmbAPI::UpdateTriggerPluggedOut == reason )
{
Log( "Camera list changed. A camera was disconnected from Vimba." );
if( true == m_bIsStreaming )
{
OnBnClickedButtonStartstop();
}
bUpdateList = true;
}
if( true == bUpdateList )
{
UpdateCameraListBox();
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
//
// Parameters:
// [in] pInbuffer The byte buffer as received from the cam
// [in] ePixelFormat The pixel format of the frame
// [out] OutImage The filled Qt image
//
VmbErrorType AsynchronousOpenCVRecorder::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix /*= NULL */ )
{
const int nHeight = m_ApiController.GetHeight();
const int nWidth = m_ApiController.GetWidth();
VmbImage SourceImage,DestImage;
VmbError_t Result;
SourceImage.Size = sizeof( SourceImage );
DestImage.Size = sizeof( DestImage );
Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, & SourceImage );
if( VmbErrorSuccess != Result )
{
Log( "Could not set source image info", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
QString OutputFormat;
const int bytes_per_line = pOutImage.bytesPerLine();
switch( pOutImage.format() )
{
default:
Log( "unknown output format",VmbErrorBadParameter );
return VmbErrorBadParameter;
case QImage::Format_RGB888:
if( nWidth*3 != bytes_per_line )
{
Log( "image transform does not support stride",VmbErrorWrongType );
return VmbErrorWrongType;
}
OutputFormat = "RGB24";
break;
}
Result = VmbSetImageInfoFromString( OutputFormat.toStdString().c_str(), OutputFormat.length(),nWidth,nHeight, &DestImage );
if( VmbErrorSuccess != Result )
{
Log( "could not set output image info",static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
SourceImage.Data = pInBuffer;
DestImage.Data = pOutImage.bits();
// do color processing?
if( NULL != Matrix )
{
VmbTransformInfo TransformParameter;
Result = VmbSetColorCorrectionMatrix3x3( Matrix, &TransformParameter );
if( VmbErrorSuccess == Result )
{
Result = VmbImageTransform( &SourceImage, &DestImage, &TransformParameter,1 );
}
else
{
Log( "could not set matrix t o transform info ", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
}
else
{
Result = VmbImageTransform( &SourceImage, &DestImage,NULL,0 );
}
if( VmbErrorSuccess != Result )
{
Log( "could not transform image", static_cast<VmbErrorType>( Result ) );
return static_cast<VmbErrorType>( Result );
}
return static_cast<VmbErrorType>( Result );
}
//
// Queries and lists all known camera
//
void AsynchronousOpenCVRecorder::UpdateCameraListBox()
{
// Get all cameras currently connected to Vimba
CameraPtrVector cameras = m_ApiController.GetCameraList();
// Simply forget about all cameras known so far
ui.m_ListBoxCameras->clear();
m_cameras.clear();
// And query the camera details again
for( CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
std::string strCameraName;
std::string strCameraID;
if( VmbErrorSuccess != (*iter)->GetName( strCameraName ) )
{
strCameraName = "[NoName]";
}
// If for any reason we cannot get the ID of a camera we skip it
if( VmbErrorSuccess == (*iter)->GetID( strCameraID ) )
{
ui.m_ListBoxCameras->addItem( QString::fromStdString( strCameraName + " " +strCameraID ) );
m_cameras.push_back( strCameraID );
}
}
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
}
//
// Prints out a given logging string, error code and the descriptive representation of that error code
//
// Parameters:
// [in] strMsg A given message to be printed out
// [in] eErr The API status code
//
void AsynchronousOpenCVRecorder::Log( std::string strMsg, VmbErrorType eErr )
{
strMsg += "..." + m_ApiController.ErrorCodeToMessage( eErr );
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}
//
// Prints out a given logging string
//
// Parameters:
// [in] strMsg A given message to be printed out
//
void AsynchronousOpenCVRecorder::Log( std::string strMsg)
{
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
}

View File

@@ -0,0 +1,114 @@
/*=============================================================================
Copyright (C) 2015 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: AsynchronousOpenCVRecorder.h
Description: Qt dialog class for the GUI of the AsynchronousOpenCVRecorder
example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef ASYNCHRONOUSOPENCVRECORDER_H
#define ASYNCHRONOUSOPENCVRECORDER_H
#include <QMainWindow>
#include "ui_AsynchronousOpenCVRecorder.h"
#include <ApiController.h>
#include "OpenCVVideoRecorder.h"
using AVT::VmbAPI::Examples::ApiController;
class AsynchronousOpenCVRecorder : public QMainWindow
{
Q_OBJECT
public:
AsynchronousOpenCVRecorder( QWidget *parent = 0, Qt::WindowFlags flags = 0 );
~AsynchronousOpenCVRecorder();
private:
typedef QSharedPointer<OpenCVRecorder> OpenCVRecorderPtr;
OpenCVRecorderPtr m_pVideoRecorder;
// The Qt GUI
Ui::AsynchronousOpenCVRecorderClass ui;
// Our controller that wraps API access
ApiController m_ApiController;
// A list of known camera IDs
std::vector<std::string> m_cameras;
// Are we streaming?
bool m_bIsStreaming;
// Our Qt image to display
QImage m_Image;
//
// Queries and lists all known camera
//
void UpdateCameraListBox();
//
// Prints out a given logging string, error code and the descriptive representation of that error code
//
// Parameters:
// [in] strMsg A given message to be printed out
// [in] eErr The API status code
//
void Log( std::string strMsg, VmbErrorType eErr );
//
// Prints out a given logging string
//
// Parameters:
// [in] strMsg A given message to be printed out
//
void Log( std::string strMsg);
//
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
//
// Parameters:
// [in] pInbuffer The byte buffer as received from the cam
// [in] ePixelFormat The pixel format of the frame
// [out] OutImage The filled Qt image
//
VmbErrorType CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix = NULL );
private slots:
// The event handler for starting / stopping acquisition
void OnBnClickedButtonStartstop();
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
//
// Parameters:
// [in] status The frame receive status (complete, incomplete, ...)
//
void OnFrameReady( int status );
//
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
//
// Parameters:
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
//
void OnCameraListChanged( int reason );
};
#endif // ASYNCHRONOUSOPENCVRECORDER_H

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraObserver.cpp
Description: The camera observer that is used for notifications from VimbaCPP
regarding a change in the camera list.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <CameraObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// This is our callback routine that will be executed every time a camera was plugged in or out
//
// Parameters:
// [in] pCam The camera that triggered the callback
// [in] reason The reason why the callback was triggered
//
void CameraObserver::CameraListChanged( CameraPtr pCam, UpdateTriggerType reason )
{
if ( UpdateTriggerPluggedIn == reason
|| UpdateTriggerPluggedOut == reason )
{
// Emit the new camera signal
emit CameraListChangedSignal( reason );
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,66 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraObserver.h
Description: The camera observer that is used for notifications from VimbaCPP
regarding a change in the camera list.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
#define AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
#include <QObject>
#include <VimbaCPP/Include/VimbaCPP.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class CameraObserver : public QObject, public ICameraListObserver
{
Q_OBJECT
public:
//
// This is our callback routine that will be executed every time a camera was plugged in or out
//
// Parameters:
// [in] pCam The camera that triggered the callback
// [in] reason The reason why the callback was triggered
//
virtual void CameraListChanged( CameraPtr pCamera, UpdateTriggerType reason );
signals:
//
// The camera list changed event (Qt signal) that notifies about a camera change and its reason
//
// Parameters:
// [out] reason The reason why this event was fired
//
void CameraListChangedSignal( int reason );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,105 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.cpp
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <FrameObserver.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
void FrameObserver::FrameReceived( const FramePtr pFrame )
{
bool bQueueDirectly = true;
VmbFrameStatusType eReceiveStatus;
if( 0 != receivers(SIGNAL(FrameReceivedSignal(int)) )
&& VmbErrorSuccess == pFrame->GetReceiveStatus( eReceiveStatus ) )
{
// Lock the frame queue
m_FramesMutex.lock();
// Add frame to queue
m_Frames.push( pFrame );
// Unlock frame queue
m_FramesMutex.unlock();
// Emit the frame received signal
emit FrameReceivedSignal( eReceiveStatus );
bQueueDirectly = false;
}
// If any error occurred we queue the frame without notification
if( true == bQueueDirectly )
{
m_pCamera->QueueFrame( pFrame );
}
}
//
// After the view has been notified about a new frame it can pick it up.
// It is then removed from the internal queue
//
// Returns:
// A shared pointer to the latest frame
//
FramePtr FrameObserver::GetFrame()
{
// Lock the frame queue
m_FramesMutex.lock();
// Pop frame from queue
FramePtr res;
if( !m_Frames.empty() )
{
res = m_Frames.front();
m_Frames.pop();
}
// Unlock frame queue
m_FramesMutex.unlock();
return res;
}
//
// Clears the internal (double buffering) frame queue
//
void FrameObserver::ClearFrameQueue()
{
// Lock the frame queue
m_FramesMutex.lock();
// Clear the frame queue and release the memory
std::queue<FramePtr> empty;
std::swap( m_Frames, empty );
// Unlock the frame queue
m_FramesMutex.unlock();
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,93 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FrameObserver.h
Description: The frame observer that is used for notifications from VimbaCPP
regarding the arrival of a newly acquired frame.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
#include <queue>
#include <QObject>
#include <QMutex>
#include <VimbaCPP/Include/VimbaCPP.h>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class FrameObserver : public QObject, virtual public IFrameObserver
{
Q_OBJECT
public:
// We pass the camera that will deliver the frames to the constructor
FrameObserver( CameraPtr pCamera ) : IFrameObserver( pCamera ) {;}
//
// This is our callback routine that will be executed on every received frame.
// Triggered by the API.
//
// Parameters:
// [in] pFrame The frame returned from the API
//
virtual void FrameReceived( const FramePtr pFrame );
//
// After the view has been notified about a new frame it can pick it up.
// It is then removed from the internal queue
//
// Returns:
// A shared pointer to the latest frame
//
FramePtr GetFrame();
//
// Clears the internal (double buffering) frame queue
//
void ClearFrameQueue();
private:
// Since a Qt signal cannot contain a whole frame
// the frame observer stores all FramePtr
std::queue<FramePtr> m_Frames;
QMutex m_FramesMutex;
signals:
//
// The frame received event (Qt signal) that notifies about a new incoming frame
//
// Parameters:
// [out] status The frame receive status
//
void FrameReceivedSignal( int status );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,401 @@
/*=============================================================================
Copyright (C) 2015 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: OpenCVVideoRecorder.h
Description: class to save videos with OpenCV.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
/*===========================================================================
<OpenCV License>
By downloading, copying, installing or using the software you agree to this license.
If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement
For Open Source Computer Vision Library
(3-clause BSD License)
Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
Copyright (C) 2009-2015, NVIDIA Corporation, all rights reserved.
Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
Copyright (C) 2015, OpenCV Foundation, all rights reserved.
Copyright (C) 2015, Itseez Inc., all rights reserved.
Third party copyrights are property of their respective owners.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are disclaimed.
In no event shall copyright holders or contributors be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
</OpenCV License>
=============================================================================*/
#ifndef OPEN_CV_VIDEO_RECORDER_H_
#define OPEN_CV_VIDEO_RECORDER_H_
// open cv include
#include "opencv2/opencv.hpp"
//qt include
#include "QtCore/QSharedPointer"
#include "QtCore/QList"
#include "QtCore/QMutex"
#include "QtCore/QWaitCondition"
#include "QtCore/QThread"
// std include
#include <vector>
#include <algorithm>
#include <exception>
// allied vision image transform include
#include "VmbTransform.h"
#include <VimbaCPP/Include/VimbaCPP.h>
//
// Base exception
//
class BaseException: public std::exception
{
QString m_Function;
QString m_Message;
public:
BaseException( const char*fun, const char* msg)
{
try { if( NULL != fun ) { m_Function = QString( fun );}}
catch(...) {}
try { if( NULL != msg ) { m_Message = QString( msg ); }
} catch(...) {}
}
~BaseException() throw() {}
const QString& Function() const { return m_Function; }
const QString& Message() const { return m_Message; }
};
//
// Exception for video recorder
class VideoRecorderException: public BaseException
{
public:
VideoRecorderException( const char* fun, const char*msg)
: BaseException( fun, msg )
{}
~VideoRecorderException() throw() {}
};
//
// Video recorder using open cv VideoWriter
//
class OpenCVRecorder: public QThread
{
Q_OBJECT;
//
// Example FOURCC codes that can be used with the OpenCVRecorder
//
VmbUint32_t maxQueueElements() const { return 3; }
enum
{
FOURCC_USER_SELECT = CV_FOURCC_PROMPT,
FOURCC_DEFAULT = CV_FOURCC_MACRO('I','Y','U','V'),
FOURCC_MPEG1 = CV_FOURCC_MACRO('P','I','M','1'),
FOURCC_MJPEG = CV_FOURCC_MACRO('M','J','P','G'),
FOURCC_MPEG42 = CV_FOURCC_MACRO('M','P','4','2'),
FOURCC_MPEG43 = CV_FOURCC_MACRO('M','P','4','3'),
FOURCC_DIVX = CV_FOURCC_MACRO('D','I','V','X'),
FOURCC_X264 = CV_FOURCC_MACRO('X','2','6','4'),
};
//
// frame data temporary storage
//
struct frame_store
{
private:
typedef std::vector<VmbUchar_t> data_vector;
data_vector m_Data; // Frame data
VmbUint32_t m_Width; // frame width
VmbUint32_t m_Height; // frame height
VmbPixelFormat_t m_PixelFormat; // frame pixel format
public:
//
// Method: frame_store()
//
// Purpose: default constructing frame store from data pointer and dimensions
//
frame_store(const VmbUchar_t *pBuffer, VmbUint32_t BufferByteSize, VmbUint32_t Width, VmbUint32_t Height, VmbPixelFormatType PixelFormat)
: m_Data ( pBuffer, pBuffer + BufferByteSize )
, m_Width( Width )
, m_Height( Height )
, m_PixelFormat( PixelFormat )
{
}
//
// Method: equal
//
// Purpose: compare frame store to frame dimensions
//
bool equal( VmbUint32_t Width, VmbUint32_t Height, VmbPixelFormat_t PixelFormat) const
{
return m_Width == Width
&& m_Height == Height
&& m_PixelFormat == PixelFormat;
}
//
// Method: setData
//
// Purpose: copy data into frame store from matching source
//
// Returns: false if data size not equal to internal buffer size
//
bool setData( const VmbUchar_t *Buffer, VmbUint32_t BufferSize)
{
if( BufferSize == dataSize() )
{
std::copy( Buffer, Buffer+BufferSize, m_Data.begin() );
return true;
}
return false;
}
//
// Methode: PixelFormat()
//
// Purpose: get pixel format of internal buffer.
//
VmbPixelFormat_t pixelFormat() const { return m_PixelFormat; }
//
// Methode: Width()
//
// Purpose: get image width.
//
VmbUint32_t width() const { return m_Width; }
//
// Methode: Height()
//
// Purpose: get image height
//
VmbUint32_t height() const { return m_Height; }
//
// Methode: dataSize()
//
// Purpose: get buffer size of internal data.
//
VmbUint32_t dataSize() const { return static_cast<VmbUint32_t>( m_Data.size() ); }
//
// Methode: data()
//
// Purpose: get constant internal data pointer.
//
const VmbUchar_t* data() const { return &*m_Data.begin();}
//
// Methode: data()
//
// Purpose: get internal data pointer.
//
VmbUchar_t* data() { return &*m_Data.begin();}
};
typedef QSharedPointer<frame_store> FrameStorePtr; // shared pointer to frame store data
typedef QList<FrameStorePtr> FrameQueue; // queue of frames tore pointers
cv::VideoWriter m_VideoWriter; // OpenCV VideoWriter
cv::Mat m_ConvertImage; // storage for converted image, data should only be accessed inside run
// size and format are const while thread runs
FrameQueue m_FrameQueue; // frame data queue for frames that are to be saved into video stream
bool m_StopThread; // flag to signal that the thread has to finish
QMutex m_ClassLock; // shared data lock
QWaitCondition m_FramesAvailable; // queue frame available condition
//
// Method: run()
//
// Purpose: QThread run() implementation.
//
// Details: main thread processing function that will run while the object is alife.
//
//
void run()
{
while( ! m_StopThread )
{
FrameStorePtr tmp;
{
// two class events unlock the queue
// first if a frame arrives enqueueFrame wakes the condition
// second if the thread is stopped we are woken up
// the while loop is necessary because a condition can be woken up by the system
QMutexLocker local_lock( &m_ClassLock );
while(! m_StopThread && m_FrameQueue.empty() )
{
m_FramesAvailable.wait( local_lock.mutex() );
}
if( ! m_StopThread)
{
tmp = m_FrameQueue.front();
m_FrameQueue.pop_front();
}
}// scope for the lock, from now one we don't need the class lock
if( ! m_StopThread)
{
convertImage( *tmp );
m_VideoWriter << m_ConvertImage;
}
}
}
//
// Method: convertImage()
//
// Purpose: converts frame_store data to internal openCV image for video encoding.
//
// Parameters:
//
// [in] frame internal frame_store struct from queue to convert into m_ConvertImage
//
// Note: access to m_Convert image will race the function is not thread safe and meant to be used as single writer to data.
//
bool convertImage(frame_store &frame)
{
VmbImage srcImage;
VmbImage dstImage;
srcImage.Size = sizeof( srcImage);
dstImage.Size = sizeof( dstImage);
VmbSetImageInfoFromPixelFormat( frame.pixelFormat(), frame.width(), frame.height(), & srcImage );
VmbSetImageInfoFromPixelFormat( VmbPixelFormatBgr8, m_ConvertImage.cols, m_ConvertImage.rows, & dstImage);
srcImage.Data = frame.data();
dstImage.Data = m_ConvertImage.data;
return VmbErrorSuccess == VmbImageTransform( &srcImage, &dstImage, NULL, 0 );
}
public:
OpenCVRecorder(const QString &fileName, VmbFloat_t fps, VmbUint32_t Width, VmbUint32_t Height)
: m_StopThread( false )
#ifdef _MSC_VER // codec selection only supported by Windows
, m_VideoWriter(fileName.toStdString(), FOURCC_USER_SELECT, fps, cv::Size(Width,Height),true )
#else
, m_VideoWriter(fileName.toStdString(), FOURCC_X264, fps, cv::Size(Width,Height),true )
#endif
, m_ConvertImage( Height, Width, CV_8UC3)
{
if( ! m_VideoWriter.isOpened() )
{
throw VideoRecorderException(__FUNCTION__, "could not open recorder");
}
}
virtual ~OpenCVRecorder(){}
//
// Method: stopthread()
//
// Purpose: stops thread and ends video encoding.
//
// Details: will stop any data processing and signal that events are to be handled.
//
void stopThread()
{
QMutexLocker local_lock( &m_ClassLock);
m_StopThread = true;
m_FrameQueue.clear();
m_FramesAvailable.wakeOne();
}
//
// Method: enqueueFrame()
//
// Purpose: copies frame data into internal queue for processing.
//
// Parameters:
//
// [in] frame Vimba frame to add to queue, data will be copied from frame
//
// Returns:
//
// - true if frame was inserted
// - false if frame has not expected size or the insert did not succeed for other reasons
//
// Details: frame data will be added to frame queue, if the MAX_QUEUE_ELEMENTS are reached
// the oldest frame data is dropped and the new frame is enqueued.
//
// Note: after return frame is not referenced by the class.
//
bool enqueueFrame( const AVT::VmbAPI::Frame &frame)
{
VmbUint32_t Width;
VmbUint32_t Height;
VmbUint32_t BufferSize;
VmbPixelFormatType PixelFormat;
const VmbUchar_t* pBuffer(NULL);
if( VmbErrorSuccess == frame.GetPixelFormat( PixelFormat)
&& VmbErrorSuccess == frame.GetWidth( Width )
&& VmbErrorSuccess == frame.GetHeight( Height )
&& VmbErrorSuccess == frame.GetBufferSize( BufferSize )
&& VmbErrorSuccess == frame.GetBuffer( pBuffer ) )
{
if( m_ConvertImage.cols == Width
&& m_ConvertImage.rows == Height )
{
QMutexLocker local_lock( &m_ClassLock);
FrameStorePtr pFrame;
// in case we reached the maximum number of queued frames
// take of the oldest and reuse it to store the newly arriving frame
if( m_FrameQueue.size() >= static_cast<FrameQueue::size_type>( maxQueueElements() ) )
{
pFrame = m_FrameQueue.front();
m_FrameQueue.pop_front();
if ( ! pFrame->equal( Width, Height, PixelFormat ) )
{
pFrame.clear();
}
}
if( pFrame.isNull() )
{
pFrame = FrameStorePtr( new frame_store( pBuffer, BufferSize, Width, Height, PixelFormat) );
}
else
{
pFrame->setData( pBuffer, BufferSize );
}
m_FrameQueue.push_back( pFrame );
m_FramesAvailable.wakeOne();
return true;
}
}
return false;
}
};
#endif

View File

@@ -0,0 +1,38 @@
/*=============================================================================
Copyright (C) 2015 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: main.cpp
Description: The main entry point of the AsynchronousOpenCVRecorder
example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "AsynchronousOpenCVRecorder.h"
#include <QApplication>
int main( int argc, char *argv[] )
{
QApplication a( argc, argv );
AsynchronousOpenCVRecorder w;
w.show();
return a.exec();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/AsynchronousOpenCVRecorder">
<file>AsynchronousOpenCVRecorder.png</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AsynchronousOpenCVRecorderClass</class>
<widget class="QMainWindow" name="AsynchronousOpenCVRecorderClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1040</width>
<height>780</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>1040</width>
<height>780</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1040</width>
<height>780</height>
</size>
</property>
<property name="windowTitle">
<string>AsynchronousOpenCVRecorder</string>
</property>
<property name="windowIcon">
<iconset resource="AsynchronousOpenCVRecorder.qrc">
<normaloff>:/AsynchronousOpenCVRecorder/AsynchronousOpenCVRecorder.png</normaloff>:/AsynchronousOpenCVRecorder/AsynchronousOpenCVRecorder.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QListWidget" name="m_ListBoxCameras">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>261</width>
<height>491</height>
</rect>
</property>
</widget>
<widget class="QListWidget" name="m_ListLog">
<property name="geometry">
<rect>
<x>0</x>
<y>580</y>
<width>1041</width>
<height>191</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="m_ButtonStartStop">
<property name="geometry">
<rect>
<x>0</x>
<y>540</y>
<width>261</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Start Image Recording ...</string>
</property>
</widget>
<widget class="QLabel" name="m_LabelStream">
<property name="geometry">
<rect>
<x>270</x>
<y>10</y>
<width>771</width>
<height>561</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QCheckBox" name="m_ColorProcessingCheckBox">
<property name="geometry">
<rect>
<x>140</x>
<y>510</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>ColorProcessing</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="AsynchronousOpenCVRecorder.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,50 @@
PROJECT_NAME = BandwidthHelper
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/BandwidthHelper.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,495 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: BandwidthHelper.cpp
Description: The BandwidthHelper example demonstrates how to get and set the
bandwidth used by a camera using VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <stdlib.h>
#include <string.h>
#include "BandwidthHelper.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
#define PACKET_SIZE_MAX_1394_S100 1024
#define PACKET_SIZE_MAX_1394_S200 2048
#define PACKET_SIZE_MAX_1394_S400 4096
#define PACKET_SIZE_MAX_1394_S800 8192
//
// Calculates the current bandwidth usage of a camera in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] rfBandwidth The current bandwidth usage (maximum 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nValue / nMax;
}
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimitMode", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strMode;
res = pFeature->GetValue( strMode );
if ( VmbErrorSuccess == res )
{
// If link speed limit is disabled, the used bandwidth can be up to 100%
if ( !strcmp( "Off", strMode.c_str() ))
{
rfBandwidth = 1.0;
}
else
{
// If link speed limit is enabled, get its current value
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetValue( nValue );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nValue / nMax;
}
}
}
}
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// Sets the current bandwidth usage in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] fBandwidth The bandwidth to be set (maximum 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::SetBandwidthUsage( CameraPtr pCamera, double fBandwidth )
{
VmbErrorType res;
VmbInt64_t nValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem& system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
nValue = (VmbUint64_t)(fBandwidth * nMax);
res = pFeature->SetValue( nValue );
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSizeAuto", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->SetValue( "Off" );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
// Set size to new percentage
nValue = (VmbUint64_t)(fBandwidth * nPhySpeed);
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
// Adjust new value to fit increment
VmbInt64_t nInc;
res = pFeature->GetIncrement( nInc );
if ( VmbErrorSuccess == res )
{
nValue -= (nValue % nInc);
// Write new value
res = pFeature->SetValue( nValue );
}
}
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimitMode", pFeature );
if ( VmbErrorSuccess == res )
{
// Enable link speed limit
res = pFeature->SetValue( "On" );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
VmbInt64_t nMin, nMax;
res = pFeature->GetRange( nMin, nMax );
if ( VmbErrorSuccess == res )
{
nValue = (VmbUint64_t)(fBandwidth * nMax);
// Set link speed limit
res = pFeature->SetValue( nValue );
}
}
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// The relative minimum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of minimum and maximum of either stream bytes per second or the packet size
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetMinPossibleBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nMinValue;
VmbInt64_t nMaxValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch( interfaceType )
{
case VmbInterfaceEthernet:
res = pCamera->GetFeatureByName( "StreamBytesPerSecond", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nMinValue / nMaxValue;
}
}
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nMinValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
res = pCamera->GetFeatureByName( "DeviceLinkThroughputLimit", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
rfBandwidth = (double)nMinValue / nMaxValue;
}
}
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// The relative maximum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of maximum packet size as reported by the device and the maximum of the bus (for technologies other than fire wire always 1)
//
// Returns:
// An API status code
//
VmbErrorType BandwidthHelper::GetMaxPossibleBandwidthUsage( CameraPtr pCamera, double &rfBandwidth )
{
VmbErrorType res;
VmbInt64_t nMinValue;
VmbInt64_t nMaxValue;
FeaturePtr pFeature;
InterfacePtr pInterface;
VmbInterfaceType interfaceType;
std::string strInterfaceID;
VimbaSystem & system = VimbaSystem::GetInstance();
res = pCamera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess == res )
{
res = system.GetInterfaceByID( strInterfaceID.c_str(), pInterface );
if( VmbErrorSuccess == res )
{
res = pInterface->GetType( interfaceType );
if( VmbErrorSuccess == res )
{
switch ( interfaceType )
{
case VmbInterfaceEthernet:
rfBandwidth = 1.0;
break;
case VmbInterfaceFirewire:
res = pCamera->GetFeatureByName( "IIDCPacketSize", pFeature );
if ( VmbErrorSuccess == res )
{
res = pFeature->GetRange( nMinValue, nMaxValue );
if ( VmbErrorSuccess == res )
{
res = pCamera->GetFeatureByName( "IIDCPhyspeed", pFeature );
if ( VmbErrorSuccess == res )
{
std::string strPhySpeed;
res = pFeature->GetValue( strPhySpeed );
if ( VmbErrorSuccess == res )
{
int nPhySpeed = atoi( strPhySpeed.substr( 1 ).c_str() );
switch ( nPhySpeed )
{
case 100 : nPhySpeed = PACKET_SIZE_MAX_1394_S100;
break;
case 200 : nPhySpeed = PACKET_SIZE_MAX_1394_S200;
break;
case 400 : nPhySpeed = PACKET_SIZE_MAX_1394_S400;
break;
case 800 : nPhySpeed = PACKET_SIZE_MAX_1394_S800;
break;
default: return VmbErrorInternalFault;
}
rfBandwidth = (double)nMaxValue / (double)nPhySpeed;
}
}
}
}
break;
case VmbInterfaceUsb:
rfBandwidth = 1.0;
break;
default:
res = VmbErrorWrongType;
break;
}
}
}
}
return res;
}
//
// Converts the interface type enum to a string representation
//
// Parameters:
// [in] interfaceType The interface enum to convert
//
// Returns:
// The string representation of the given enum
//
std::string BandwidthHelper::InterfaceToString( VmbInterfaceType interfaceType )
{
switch ( interfaceType )
{
case VmbInterfaceFirewire: return "FireWire";
case VmbInterfaceEthernet: return "GigE";
case VmbInterfaceUsb: return "USB";
default: return "Unknown";
}
}
}}} // AVT:VmbAPI::Examples

View File

@@ -0,0 +1,107 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: BandwidthHelper.h
Description: The BandwidthHelper example demonstrates how to get and set the
bandwidth used by a camera using VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_HELPER_BANDWIDTHHELPER_H
#define AVT_VMBAPI_HELPER_BANDWIDTHHELPER_H
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class BandwidthHelper
{
public:
//
// Calculates the current bandwidth usage of a camera in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] rfBandwidth The current bandwidth usage (maximum 1)
//
// Returns:
// An API status code
//
static VmbErrorType GetBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// Sets the current bandwidth usage in relation to a free bus / network
//
// Parameters:
// [in] pCamera The camera to work on
// [out] fBandwidth The bandwidth to be set (maximum 1)
//
// Returns:
// An API status code
//
static VmbErrorType SetBandwidthUsage( CameraPtr pCamera, double bandwidth );
//
// The relative minimum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of minimum and maximum of either stream bytes per second or the packet size
//
// Returns:
// An API status code
//
static VmbErrorType GetMinPossibleBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// The relative maximum bandwidth usage as reported by the device
//
// Parameters:
// [in] pCamera The camera to work on
// [out rfBandwidth The ratio of maximum packet size as reported by the device and the maximum of the bus (for technologies other than fire wire always 1)
//
// Returns:
// An API status code
//
static VmbErrorType GetMaxPossibleBandwidthUsage( CameraPtr pCamera, double &bandwidth );
//
// Converts the interface type enum to a string representation
//
// Parameters:
// [in] interfaceType The interface enum to convert
//
// Returns:
// The string representation of the given enum
//
static std::string InterfaceToString( VmbInterfaceType interfaceType );
private:
// No default ctor
BandwidthHelper();
};
}}} // AVT:VmbAPI::Examples
#endif

View File

@@ -0,0 +1,402 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of BandwidthHelper example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <map>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iostream>
#include "BandwidthHelper.h"
#include "Common/StreamSystemInfo.h"
enum SettingsMode
{
SettingsModeUnknown = 0,
SettingsModeGet = 1,
SettingsModeSet = 2,
SettingsModeGetMin = 3,
SettingsModeGetMax = 4
};
bool StartsWith( const char *pString, const char *pStart )
{
if( NULL == pString )
{
return false;
}
if( NULL == pStart )
{
return false;
}
if( std::strlen( pString ) < std::strlen( pStart ) )
{
return false;
}
if( std::memcmp( pString, pStart, std::strlen( pStart ) ) != 0 )
{
return false;
}
return true;
}
int main( int argc, char* argv[] )
{
std::string cameraID, cameraName;
VmbInterfaceType cameraInterfaceType;
double fValue;
SettingsMode settingsMode = SettingsModeUnknown;
bool printHelp = false;
std::cout << "\n";
std::cout << "//////////////////////////////////////////\n";
std::cout << "/// Vimba API Bandwidth Helper Example ///\n";
std::cout << "//////////////////////////////////////////\n";
std::cout << std::endl;
VmbErrorType err = VmbErrorSuccess;
//////////////////////
//Parse command line//
//////////////////////
if( 4 < argc )
{
err = VmbErrorBadParameter;
printHelp = true;
}
else
{
for( int i=1; i<argc; ++i )
{
char *pParameter = argv[i];
if( 0 >= std::strlen( pParameter ) )
{
err = VmbErrorBadParameter;
break;
}
if( pParameter[0] == '/' )
{
// Get bandwidth usage
if( 0 == std::strcmp( pParameter, "/g" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGet;
}
// Set bandwidth usage
else if( true == StartsWith( pParameter, "/s:" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeSet;
std::string strVal = pParameter + 3;
if( 0 >= strVal.size() )
{
err = VmbErrorBadParameter;
break;
}
fValue = atof( strVal.c_str() ) / 100;
}
else if( 0 == std::strcmp( pParameter, "/h" ) )
{
if( true == printHelp )
{
err = VmbErrorBadParameter;
break;
}
printHelp = true;
}
// Get min bandwidth usage
else if( 0 == std::strcmp( pParameter, "/min" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGetMin;
}
// Get max bandwidth usage
else if( 0 == std::strcmp( pParameter, "/max" ) )
{
if( SettingsModeUnknown != settingsMode )
{
err = VmbErrorBadParameter;
break;
}
settingsMode = SettingsModeGetMax;
}
else
{
err = VmbErrorBadParameter;
break;
}
}
else
{
if( false == cameraID.empty() )
{
err = VmbErrorBadParameter;
break;
}
cameraID = pParameter;
}
}
}
// Write out an error if we could not parse the command line
if( VmbErrorBadParameter == err )
{
std::cout << "Invalid parameter found.\n\n";
printHelp = true;
}
// Print out help
if( true == printHelp )
{
std::cout << "Gets or sets the current bandwidth as percentage of the theoretically possible bandwidth.\n\n";
std::cout << "Usage: BandwidthHelper [CameraID] [/h] [/{g|s:val|min|max}]\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
std::cout << " /h Print out help\n";
std::cout << " /g Get bandwidth usage (default if not specified)\n";
std::cout << " /s:val Set bandwidth usage to <val> % of the maximum bandwidth\n";
std::cout << " /min Get minimal possible bandwidth usage\n";
std::cout << " /max Get maximal possible bandwidth usage\n\n";
return err;
}
if( VmbErrorSuccess == err )
{
// Get a reference to the VimbaSystem singleton
AVT::VmbAPI::VimbaSystem &rVimbaSystem = AVT::VmbAPI::VimbaSystem::GetInstance();
// Print out version of Vimba
std::cout << "Vimba C++ API Version " << rVimbaSystem << "\n";
// Startup API
err = rVimbaSystem.Startup();
if( VmbErrorSuccess != err )
{
std::cout << "Could not start system. Error code: " << err <<"\n";
}
else
{
AVT::VmbAPI::CameraPtr pCamera;
// Open first available camera
if( cameraID.empty() )
{
// Fetch all cameras known to Vimba
AVT::VmbAPI::CameraPtrVector cameras;
err = rVimbaSystem.GetCameras( cameras );
if( VmbErrorSuccess == err )
{
if( !cameras.empty() )
{
for( AVT::VmbAPI::CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
// Check if we can open the camera in full mode
VmbAccessModeType accessMode = VmbAccessModeNone;
err = (*iter)->GetPermittedAccess( accessMode );
if( VmbErrorSuccess == err )
{
if( VmbAccessModeFull & accessMode )
{
// Now get the camera ID
err = ( *iter )->GetID( cameraID );
if( VmbErrorSuccess == err )
{
// Try to open the camera
err = ( *iter )->Open( VmbAccessModeFull );
if( VmbErrorSuccess == err )
{
pCamera = *iter;
// Get camera name and interface type
if( VmbErrorSuccess == pCamera->GetName( cameraName )
&& VmbErrorSuccess == pCamera->GetInterfaceType( cameraInterfaceType ) )
{
std::cout << "Successfully opened " << AVT::VmbAPI::Examples::BandwidthHelper::InterfaceToString( cameraInterfaceType ) << " camera " << cameraName << " (" << cameraID << ")\n" ;
}
else
{
std::cout << "Successfully opened camera " << "(" << cameraID << ")\n";
}
break;
}
}
}
}
}
if( NULL == pCamera )
{
std::cout << "Could not open any camera.\n";
err = VmbErrorNotFound;
}
}
else
{
std::cout << "No camera available.\n";
err = VmbErrorNotFound;
}
}
else
{
std::cout << "Could not list cameras. Error code: " << err << std::endl;
}
}
else
{
// Open specific camera
err = rVimbaSystem.OpenCameraByID( cameraID.c_str(), VmbAccessModeFull, pCamera );
if( VmbErrorSuccess != err )
{
std::cout << "Could not open camera. Error code: " << err <<"\n";
}
}
if( VmbErrorSuccess == err )
{
switch( settingsMode )
{
default:
case SettingsModeGet:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if ( VmbErrorSuccess != err )
{
std::cout << "Could not get bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
case SettingsModeSet:
{
// Set bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::SetBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else
{
if ( VmbErrorSuccess == err )
{
// Read back written value
err = AVT::VmbAPI::Examples::BandwidthHelper::GetBandwidthUsage( pCamera, fValue );
if ( VmbErrorSuccess == err )
{
std::cout << "Bandwidth usage successfully set to: " << fValue * 100 << "%\n";
}
}
if ( VmbErrorSuccess != err )
{
std::cout << "Could not set bandwidth usage. Error code: " << err <<"\n";
}
}
}
break;
case SettingsModeGetMin:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetMinPossibleBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if( VmbErrorSuccess != err )
{
std::cout << "Could not get minimal possible bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Minimal possible bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
case SettingsModeGetMax:
{
// Get bandwidth
err = AVT::VmbAPI::Examples::BandwidthHelper::GetMaxPossibleBandwidthUsage( pCamera, fValue );
if ( VmbErrorWrongType == err )
{
std::cout << "The bandwidth cannot be controlled for this interface type.\n";
}
else if ( VmbErrorSuccess != err )
{
std::cout << "Could not get maximal possible bandwidth usage. Error code: " << err <<"\n";
}
else
{
std::cout << "Maximal possible bandwidth usage: " << fValue * 100 << "%\n";
}
}
break;
}
// Close camera
err = pCamera->Close();
}
// Shutdown API
rVimbaSystem.Shutdown();
}
return err;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,100 @@
UNAME = $(shell uname -m)
ifeq ($(UNAME),i386)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i486)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i586)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),i686)
ARCH = x86
AUTOWORDSIZE = 32
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),x86_64)
ARCH = x86
AUTOWORDSIZE = 64
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),amd64)
ARCH = x86
AUTOWORDSIZE = 64
AUTOFLOATABI = ignore
endif
ifeq ($(UNAME),armv6l)
ARCH = arm
AUTOWORDSIZE = 32
AUTOFLOATABI = soft
endif
ifeq ($(UNAME),armv7l)
ARCH = arm
AUTOWORDSIZE = 32
AUTOFLOATABI = soft
endif
ifeq ($(UNAME),aarch64)
ARCH = arm
AUTOWORDSIZE = 64
AUTOFLOATABI = hard
endif
#Possible word sizes: 32, 64
WORDSIZE = $(AUTOWORDSIZE)
#Possible float abis: soft, hard
FLOATABI = $(AUTOFLOATABI)
ifneq ($(WORDSIZE),32)
ifneq ($(WORDSIZE),64)
$(error Invalid word size set)
endif
endif
ifneq ($(FLOATABI),soft)
ifneq ($(FLOATABI),hard)
ifneq ($(FLOATABI),ignore)
$(error Invalid float abi set)
endif
endif
endif
#Common tools
PKGCFG = pkg-config
MKDIR = mkdir
RM = rm
CXX = g++
MAKE = make
CP = cp
#Set word size on x86
ifeq ($(ARCH),x86)
ARCH_CFLAGS = -m$(WORDSIZE)
endif
#Configure compiler and linker for soft or hard-float build on ARM
ifeq ($(ARCH),arm)
ifeq ($(FLOATABI),soft)
ARCH_CFLAGS = -marm -mfloat-abi=soft -march=armv4t
else ifeq ($(FLOATABI),hard)
ifeq ($(WORDSIZE),32)
ARCH_CFLAGS = -mthumb -mfloat-abi=hard -march=armv7
else ifeq ($(WORDSIZE),64)
ARCH_CFLAGS = -march=armv8-a
endif
endif
endif
ifeq ($(CONFIG),Debug)
CONFIG_CFLAGS = -O0 -g
else
CONFIG_CFLAGS = -O3
endif
COMMON_CFLAGS = $(CONFIG_CFLAGS) $(ARCH_CFLAGS) -fPIC

View File

@@ -0,0 +1,56 @@
EXAMPLES_DIR = ../..
MAKE_INCLUDE_DIR = $(CURDIR)
include $(MAKE_INCLUDE_DIR)/Common.mk
QT_SUPPORT = true
ifeq ($(QT_SUPPORT),true)
QT_EXAMPLES = VimbaViewer
QT_SUB_EXAMPLES = AsynchronousGrab \
AsynchronousOpenCVRecorder \
SynchronousGrab
endif
CONSOLE_EXAMPLES = ActionCommands \
BandwidthHelper \
CameraFactory \
EventHandling \
ListCameras \
ListFeatures \
ListAncillaryDataFeatures \
LoadSaveSettings \
LookUpTable \
UserSet
CONSOLE_SUB_EXAMPLES = AsynchronousGrab \
SynchronousGrab
make_%: $(EXAMPLES_DIR)/%/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Build/Make
clean_%: $(EXAMPLES_DIR)/%/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Build/Make clean
make_%Console: $(EXAMPLES_DIR)/%/Console/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Console/Build/Make
clean_%Console: $(EXAMPLES_DIR)/%/Console/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Console/Build/Make clean
make_%Qt: $(EXAMPLES_DIR)/%/Qt/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Qt/Build/Make
clean_%Qt: $(EXAMPLES_DIR)/%/Qt/Build/Make/Makefile
$(MAKE) -C $(EXAMPLES_DIR)/$*/Qt/Build/Make clean
all: $(foreach example,$(CONSOLE_EXAMPLES),make_$(example)) \
$(foreach example,$(CONSOLE_SUB_EXAMPLES),make_$(example)Console) \
$(foreach example,$(QT_EXAMPLES),make_$(example)) \
$(foreach example,$(QT_SUB_EXAMPLES),make_$(example)Qt)
clean: $(foreach example,$(CONSOLE_EXAMPLES),clean_$(example)) \
$(foreach example,$(CONSOLE_SUB_EXAMPLES),clean_$(example)Console) \
$(foreach example,$(QT_EXAMPLES),clean_$(example)) \
$(foreach example,$(QT_SUB_EXAMPLES),clean_$(example)Qt)

View File

@@ -0,0 +1,36 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
PKGCFG_MOC = $(shell $(PKGCFG) --variable=moc_location QtCore)
PKGCFG_UIC = $(shell $(PKGCFG) --variable=uic_location QtCore)
#Qt tools
MOC = $(if $(PKGCFG_MOC),$(PKGCFG_MOC),moc)
UIC = $(if $(PKGCFG_UIC),$(PKGCFG_UIC),uic)
RCC = rcc
#Compile options needed for QtCore
QTCORE_CFLAGS = $(shell $(PKGCFG) --cflags QtCore)
#Linker options needed for QtCore
QTCORE_LIBS = $(shell $(PKGCFG) --libs QtCore)
#Compile options needed for QtGui
QTGUI_CFLAGS = $(shell $(PKGCFG) --cflags QtGui)
#Linker options needed for QtGui
QTGUI_LIBS = $(shell $(PKGCFG) --libs QtGui)
#Compile options needed for QtSvg
QTSVG_CFLAGS = $(shell $(PKGCFG) --cflags QtSvg)
#Linker options needed for QtSvg
QTSVG_LIBS = $(shell $(PKGCFG) --libs QtSvg)
#Operations we have to do in order to prepare QtCore
QtCore:
#Operations we have to do in order to prepare QtGui
QtGui:
#Operations we have to do in order to prepare QtSvg
QtSvg:

View File

@@ -0,0 +1,14 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
#Compile options needed for VimbaC
VIMBAC_CFLAGS = -I$(VIMBASDK_DIR)
#Linker options needed for VimbaC
VIMBAC_LIBS = -L$(BIN_DIR) -lVimbaC
#By default we copy libVimbaC.so next to the binary
$(BIN_DIR)/libVimbaC.so: $(BIN_DIR)
$(CP) $(VIMBASDK_DIR)/VimbaC/DynamicLib/$(ARCH)_$(WORDSIZE)bit/libVimbaC.so $(BIN_DIR)/
#Operations we have to do in order to prepare VimbaC
VimbaC: $(BIN_DIR)/libVimbaC.so

View File

@@ -0,0 +1,15 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
include $(MAKE_INCLUDE_DIR)/VimbaC.mk
#Compile options needed for VimbaCPP
VIMBACPP_CFLAGS = -I$(VIMBASDK_DIR) $(VIMBAC_CFLAGS)
#Linker options needed for VimbaCPP
VIMBACPP_LIBS = -L$(BIN_DIR) -lVimbaCPP $(VIMBAC_LIBS) -Wl,-rpath-link,$(BIN_DIR)
#By default we copy libVimbaCPP.so next to the binary
$(BIN_DIR)/libVimbaCPP.so: $(BIN_DIR) VimbaC
$(CP) $(VIMBASDK_DIR)/VimbaCPP/DynamicLib/$(ARCH)_$(WORDSIZE)bit/libVimbaCPP.so $(BIN_DIR)/
#Operations we have to do in order to prepare VimbaCPP
VimbaCPP: $(BIN_DIR)/libVimbaCPP.so

View File

@@ -0,0 +1,14 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
#Compile options needed for VimbaImageTransform
VIMBAIMAGETRANSFORM_CFLAGS = -I$(VIMBASDK_DIR)/VimbaImageTransform/Include
#Compile options needed for VimbaImageTransform
VIMBAIMAGETRANSFORM_LIBS = -L$(BIN_DIR) -lVimbaImageTransform -Wl,-rpath-link,$(BIN_DIR)
#By default we copy libVimbaImageTransform.so next to the binary
$(BIN_DIR)/libVimbaImageTransform.so: $(BIN_DIR)
$(CP) $(VIMBASDK_DIR)/VimbaImageTransform/DynamicLib/$(ARCH)_$(WORDSIZE)bit/libVimbaImageTransform.so $(BIN_DIR)/
#Operations we have to do in order to prepare VimbaImageTransform
VimbaImageTransform: $(BIN_DIR)/libVimbaImageTransform.so

View File

@@ -0,0 +1,12 @@
include $(MAKE_INCLUDE_DIR)/Common.mk
PKGCFG_TINYXML_LIBS = $(shell $(PKGCFG) --libs tinyxml)
#Compile options needed for tinyxml
TINYXML_CFLAGS = $(shell $(PKGCFG) --cflags tinyxml)
#Linker options needed for tinyxml
TINYXML_LIBS = $(if $(PKGCFG_TINYXML_LIBS),$(PKGCFG_TINYXML_LIBS),-ltinyxml)
#Operations we have to do in order to prepare tinyxml
tinyxml:

View File

@@ -0,0 +1,51 @@
PROJECT_NAME = CameraFactory
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/CameraFactory.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/FindCameras.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,208 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraFactory.cpp
Description: The CameraFactory example will create a suitable object for
each known interface. The user can create his own factory and
camera classes for customization.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include "CameraFactory.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
/*=============================================================================
FirewireCamera class
=============================================================================*/
FirewireCamera::FirewireCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess )
: Camera( pCameraID, pCameraName, pCameraModel,
pCameraSerialNumber, pInterfaceID, interfaceType)
{
}
// A custom camera function
void FirewireCamera::addonFireWire( std::string &info )
{
info = "1394 interface connection detected";
}
/*=============================================================================
GigECamera class
=============================================================================*/
GigECamera::GigECamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess )
: Camera( pCameraID, pCameraName, pCameraModel,
pCameraSerialNumber, pInterfaceID, interfaceType)
{
}
// A custom camera function
void GigECamera::addonGigE( std::string &info )
{
info = "Ethernet interface connection detected";
}
/*=============================================================================
USBCamera class
=============================================================================*/
USBCamera::USBCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess )
: Camera( pCameraID, pCameraName, pCameraModel,
pCameraSerialNumber, pInterfaceID, interfaceType)
{
}
// A custom camera function
void USBCamera::addonUSB( std::string &info )
{
info = "USB interface connection detected";
}
/*=============================================================================
CLCamera class
=============================================================================*/
CLCamera::CLCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess )
: Camera( pCameraID, pCameraName, pCameraModel,
pCameraSerialNumber, pInterfaceID, interfaceType)
{
}
// A custom camera function
void CLCamera::addonCL( std::string &info )
{
info = "CL interface connection detected";
}
/*=============================================================================
UserCameraFactory class
=============================================================================*/
CameraPtr UserCameraFactory::CreateCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess)
{
// create camera class, depending on camera interface type
if ( VmbInterfaceFirewire == interfaceType )
{
return FirewireCamera_t( new FirewireCamera( pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType,
pInterfaceName,
pInterfaceSerialNumber,
interfacePermittedAccess));
}
else if ( VmbInterfaceEthernet == interfaceType )
{
return GigECamera_t( new GigECamera( pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType,
pInterfaceName,
pInterfaceSerialNumber,
interfacePermittedAccess));
}
else if ( VmbInterfaceUsb == interfaceType )
{
return USBCamera_t( new USBCamera( pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType,
pInterfaceName,
pInterfaceSerialNumber,
interfacePermittedAccess));
}
else if ( VmbInterfaceCL == interfaceType )
{
return CLCamera_t( new CLCamera( pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType,
pInterfaceName,
pInterfaceSerialNumber,
interfacePermittedAccess));
}
else // unknown camera interface
{
// use default camera class
return Camera_t( new Camera( pCameraID,
pCameraName,
pCameraModel,
pCameraSerialNumber,
pInterfaceID,
interfaceType));
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,152 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: CameraFactory.h
Description: The CameraFactory example will create a suitable object for
each known interface. The user can create his own factory and
camera classes for customization.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_CAMERAFACTORY
#define AVT_VMBAPI_EXAMPLES_CAMERAFACTORY
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class UserCameraFactory;
class FirewireCamera;
class GigECamera;
class USBCamera;
class CLCamera;
typedef SP_DECL( UserCameraFactory ) UserCameraFactory_t;
typedef SP_DECL( FirewireCamera ) FirewireCamera_t;
typedef SP_DECL( GigECamera ) GigECamera_t;
typedef SP_DECL( USBCamera ) USBCamera_t;
typedef SP_DECL( CLCamera ) CLCamera_t;
typedef SP_DECL( Camera ) Camera_t;
//
// A class that derives from standard Vimba Camera with a function specific to fire wire
//
class FirewireCamera:
public Camera
{
public:
FirewireCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess );
void addonFireWire( std::string &info ); // custom camera function
};
//
// A class that derives from standard Vimba Camera with a function specific to GigE
//
class GigECamera:
public Camera
{
public:
GigECamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess );
void addonGigE( std::string &info ); // custom camera function
};
//
// A class that derives from standard Vimba Camera with a function specific to USB
//
class USBCamera:
public Camera
{
public:
USBCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess );
void addonUSB( std::string &info ); // custom camera function
};
//
// A class that derives from standard Vimba Camera with a functions specific to CL
//
class CLCamera:
public Camera
{
public:
CLCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess );
void addonCL( std::string &info ); // custom camera function
};
//
// A class with a static factory method creating specific camera classes dependent on the interface type
//
class UserCameraFactory :
public ICameraFactory
{
public:
CameraPtr CreateCamera( const char *pCameraID,
const char *pCameraName,
const char *pCameraModel,
const char *pCameraSerialNumber,
const char *pInterfaceID,
VmbInterfaceType interfaceType,
const char *pInterfaceName,
const char *pInterfaceSerialNumber,
VmbAccessModeType interfacePermittedAccess);
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,162 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FindCameras.cpp
Description: Find and print a custom string for each known customized camera.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include <vector>
#include "FindCameras.h"
#include "CameraFactory.h"
#include "VimbaCPP/Include/VimbaCPP.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Detects all connected physical cameras and creates polymorphic classes (all inheriting from Vimba Camera class)
// depending on the camera's interface type.
// Starts up the API
// Creates the objects and prints them out
// Shuts down the API and exits
//
void FindCameras::Print()
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
CameraPtrVector cameras; // A vector of std::shared_ptr<AVT::VmbAPI::Camera> objects
std::string strName; // The name of the cam
VmbInterfaceType interfaceType; // The interface type of the cam
std::string strInfo; // The custom information
std::stringstream strError;
if( VmbErrorSuccess == err )
{
std::cout<<"Vimba C++ API Version "<<sys<<"\n";
// Set user factory as default camera object creator.
ICameraFactoryPtr factPtr = UserCameraFactory_t( new UserCameraFactory() );
err = sys.RegisterCameraFactory( factPtr );
if( VmbErrorSuccess == err )
{
err = sys.GetCameras( cameras ); // Fetch all cameras known to Vimba
if( VmbErrorSuccess == err )
{
std::cout << "Cameras found: " << cameras.size() <<"\n\n";
// Query the name and interface of all known cameras and print them out.
// We don't have to open the cameras for that.
for( CameraPtrVector::const_iterator iter = cameras.begin();
cameras.end() != iter;
++iter )
{
err = (*iter)->GetName( strName );
if( VmbErrorSuccess != err )
{
strError << "[Could not get camera name. Error code: " << err <<"("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strName.assign( strError.str() );
}
err = (*iter)->GetInterfaceType( interfaceType );
if( VmbErrorSuccess != err )
{
strError << "[Could not get camera interface. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strInfo = "";
}
else
{
strInfo = "none";
switch( interfaceType )
{
case VmbInterfaceFirewire:
{
FirewireCamera_t fcam = SP_DYN_CAST( *iter, FirewireCamera );
if ( fcam != NULL )
fcam->addonFireWire( strInfo );
break;
}
case VmbInterfaceEthernet:
{
GigECamera_t gcam = SP_DYN_CAST( *iter, GigECamera );
if ( gcam != NULL )
gcam->addonGigE( strInfo );
break;
}
case VmbInterfaceUsb:
{
USBCamera_t ucam = SP_DYN_CAST( *iter, USBCamera );
if ( ucam != NULL )
ucam->addonUSB( strInfo );
break;
}
case VmbInterfaceCL:
{
CLCamera_t ccam = SP_DYN_CAST( *iter, CLCamera );
if ( ccam != NULL )
ccam->addonCL( strInfo );
break;
}
default:
{
break;
}
}
}
std::cout <<"/// Camera Name: " << strName
<<"\n/// Custom Info: " << strInfo
<<"\n\n";
}
}
else
{
std::cout << "Could not list cameras. Error code: " << err <<"("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "\n";
}
sys.Shutdown(); // Close Vimba
}
else
{
strError << "[Could not set user camera factory. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
}
}
else
{
std::cout << "Could not start system. Error code: " << err <<"("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "\n";
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,50 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: FindCameras.h
Description: Find and print a custom string for each known customized camera.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_FINDCAMERAS
#define AVT_VMBAPI_EXAMPLES_FINDCAMERAS
namespace AVT {
namespace VmbAPI {
namespace Examples {
class FindCameras
{
public:
//
// Detects all connected physical cameras and creates polymorphic classes (all inheriting from Vimba Camera class)
// depending on the camera's interface type.
// Starts up the API
// Creates the objects and prints them out
// Shuts down the API and exits
//
static void Print();
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,47 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of CameraFactory example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "FindCameras.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "///////////////////////////////////////\n";
std::cout << "/// Vimba API CameraFactory Example ///\n";
std::cout << "///////////////////////////////////////\n\n";
if( 1 < argc )
{
std::cout << "No parameters expected. Execution will not be affected by the provided parameter(s).\n\n";
}
AVT::VmbAPI::Examples::FindCameras::Print();
std::cout << "\n";
}

View File

@@ -0,0 +1,84 @@
/*=============================================================================
Copyright (C) 2014 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ErrorCodeToMessage.h
Description: Convert the error codes to a self-explanatory message.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef ERROR_CODE_TO_MESSAGE_H_
#define ERROR_CODE_TO_MESSAGE_H_
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
#ifdef UNICODE
typedef std::wstring string_type;
#define MAKE_STRING_LITERAL_(s) L ## s
#else
typedef std::string string_type;
#define MAKE_STRING_LITERAL_(s) s
#endif
#define MAKE_STRING_LITERAL(s) MAKE_STRING_LITERAL_(s)
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Translates Vimba error codes to readable error messages
//
// Parameters:
// [in] eError The error code to be converted to string
//
// Returns:
// A descriptive string representation of the error code
//
inline string_type ErrorCodeToMessage( VmbError_t eError )
{
switch( eError )
{
case VmbErrorSuccess: return string_type( MAKE_STRING_LITERAL( "Success." ) );
case VmbErrorInternalFault: return string_type( MAKE_STRING_LITERAL( "Unexpected fault in VmbApi or driver." ) );
case VmbErrorApiNotStarted: return string_type( MAKE_STRING_LITERAL( "API not started." ) );
case VmbErrorNotFound: return string_type( MAKE_STRING_LITERAL( "Not found." ) );
case VmbErrorBadHandle: return string_type( MAKE_STRING_LITERAL( "Invalid handle " ) );
case VmbErrorDeviceNotOpen: return string_type( MAKE_STRING_LITERAL( "Device not open." ) );
case VmbErrorInvalidAccess: return string_type( MAKE_STRING_LITERAL( "Invalid access." ) );
case VmbErrorBadParameter: return string_type( MAKE_STRING_LITERAL( "Bad parameter." ) );
case VmbErrorStructSize: return string_type( MAKE_STRING_LITERAL( "Wrong DLL version." ) );
case VmbErrorMoreData: return string_type( MAKE_STRING_LITERAL( "More data returned than memory provided." ) );
case VmbErrorWrongType: return string_type( MAKE_STRING_LITERAL( "Wrong type." ) );
case VmbErrorInvalidValue: return string_type( MAKE_STRING_LITERAL( "Invalid value." ) );
case VmbErrorTimeout: return string_type( MAKE_STRING_LITERAL( "Timeout." ) );
case VmbErrorOther: return string_type( MAKE_STRING_LITERAL( "TL error." ) );
case VmbErrorResources: return string_type( MAKE_STRING_LITERAL( "Resource not available." ) );
case VmbErrorInvalidCall: return string_type( MAKE_STRING_LITERAL( "Invalid call." ) );
case VmbErrorNoTL: return string_type( MAKE_STRING_LITERAL( "TL not loaded." ) );
case VmbErrorNotImplemented: return string_type( MAKE_STRING_LITERAL( "Not implemented." ) );
case VmbErrorNotSupported: return string_type( MAKE_STRING_LITERAL( "Not supported." ) );
default: return string_type( MAKE_STRING_LITERAL( "Unknown" ) );
}
}
}}} // AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,51 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: StreamSystemInfo.h
Description:
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef STREAM_SYSTEM_INFO_H
#define STREAM_SYSTEM_INFO_H
#include <exception>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
template<typename STREAM>
STREAM& operator<<( STREAM& os, AVT::VmbAPI::VimbaSystem &sys )
{
VmbVersionInfo_t info;
if (VmbErrorSuccess != sys.QueryVersion( info ))
{
throw std::exception();
}
os << info.major << "." << info.minor << "." << info.patch;
return os;
}
}} // Namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,51 @@
PROJECT_NAME = EventHandling
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/EventHandling.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/EventObserver.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,288 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: EventHandling.cpp
Description: The EventHandling example will register observer on all
'EventData' features and turn on camera notification for
'AcquisitionStart' events.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <EventHandling.h>
#include <EventObserver.h>
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// Purpose: Example execution.
//
// Parameter:
// [in ] std::string cameraID Use camera with this ID for the example.
void EventHandling::RunExample( std::string cameraID )
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
std::cout << "Vimba C++ API Version " << sys << "\n\n"; // Print out version of Vimba
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
CameraPtr pCamera = CameraPtr(); // Our camera
if( VmbErrorSuccess == err )
{
if( cameraID.empty() ) // If no ID was provided use the first camera
{
CameraPtrVector cameras;
err = sys.GetCameras( cameras );
if( VmbErrorSuccess == err
&& !cameras.empty() )
{
err = cameras[0]->Open( VmbAccessModeFull ); // Open the camera
if( VmbErrorSuccess == err )
{
pCamera = cameras[0];
err = pCamera->GetID( cameraID );
}
}
}
else
{
err = sys.OpenCameraByID( cameraID.c_str(), VmbAccessModeFull, pCamera ); // Open the camera
}
if( NULL != pCamera )
{
VmbInterfaceType interfaceType;
pCamera->GetInterfaceType( interfaceType );
if( VmbErrorSuccess == err )
{
switch ( interfaceType )
{
case VmbInterfaceEthernet:
{
if( VmbErrorSuccess == err )
{
err = DeactivateAllCameraNotifications( pCamera );
if( VmbErrorSuccess == err )
{
err = ActivateNotification( pCamera, "AcquisitionStart" );
if( VmbErrorSuccess == err )
{
err = RegisterEventObserver( pCamera );
if( VmbErrorSuccess == err )
{
std::cout << "Acquire image to trigger event.\n";
std::cout << "\n----------- Events -----------\n\n";
FramePtr pFrame;
VmbInt32_t exampleTimeoutValue = 2000;
pCamera->AcquireSingleImage( pFrame, exampleTimeoutValue ); // Trigger the event
}
}
}
}
break;
}
default:
std::cout << "Interface type of camera not supported by this example.: " << cameraID << "\n";
}
}
else
{
std::cout << "Could not get interface type. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
pCamera->Close();
}
else
{
std::cout << "Could not open camera or no camera available. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
sys.Shutdown();
}
else
{
std::cout << "Could not start system. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
// Purpose: Deactivate all camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::DeactivateAllCameraNotifications( CameraPtr pCamera )
{
std::cout << "Deactivate notifications.\n";
FeaturePtr pFeatureEventSelector;
VmbErrorType err = pCamera->GetFeatureByName( "EventSelector", pFeatureEventSelector );
if( VmbErrorSuccess == err )
{
EnumEntryVector eventSelectorEntrys;
err = pFeatureEventSelector->GetEntries( eventSelectorEntrys );
if( VmbErrorSuccess == err )
{
FeaturePtr pFeatureEnumEntry;
for( size_t i = 0; i < eventSelectorEntrys.size(); i++ )
{
std::string entryValue = "";
err = eventSelectorEntrys[i].GetName( entryValue );
if( VmbErrorSuccess == err )
{
bool isCurrentEntryAvailable = false;
err = pFeatureEventSelector->IsValueAvailable( entryValue.c_str(), isCurrentEntryAvailable );
if ( VmbErrorSuccess == err )
{
if ( isCurrentEntryAvailable )
{
err = pFeatureEventSelector->SetValue( entryValue.c_str() );
if( VmbErrorSuccess == err )
{
err = pCamera->GetFeatureByName( "EventNotification", pFeatureEnumEntry );
if( VmbErrorSuccess == err )
{
err = pFeatureEnumEntry->SetValue( "Off" );
if( VmbErrorSuccess != err )
{
std::cout << "Could not set notification 'Off'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventNotification'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not set 'EventSelector' value to '" << entryValue << "'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
else
{
std::cout << "Could not check if entry is currently available. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get entry value. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
else
{
std::cout << "Could not get 'EventSelector' entry's. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventSelector'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
// Purpose: Create for each 'Camera->EventData' feature an observer and register it.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::RegisterEventObserver( CameraPtr pCamera )
{
FeaturePtrVector features;
VmbErrorType err = pCamera->GetFeatures( features );
if( VmbErrorSuccess == err )
{
for( size_t i = 0; i < features.size(); i++ )
{
std::string category;
err = features[i]->GetCategory( category );
if( 0 == category.compare( "/EventControl/EventData" ) && VmbErrorSuccess == err )
{
IFeatureObserverPtr pObserver;
SP_SET( pObserver, new EventObserver( pCamera ) );
err = features[i]->RegisterObserver( pObserver );
if( VmbErrorSuccess != err )
{
std::cout << "Could not register observer. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}
}
else
{
std::cout << "Could not get features. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
// Purpose: Activate camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
// [in ] std::string eventName Name of event to activate.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType EventHandling::ActivateNotification( CameraPtr pCamera, std::string eventName )
{
std::cout << "Activate notification for '" << eventName << "' events.\n";
FeaturePtr feature;
VmbErrorType err = pCamera->GetFeatureByName( "EventSelector", feature );
if( VmbErrorSuccess == err )
{
err = feature->SetValue( eventName.c_str() );
if( VmbErrorSuccess == err )
{
err = pCamera->GetFeatureByName( "EventNotification", feature );
if( VmbErrorSuccess == err )
{
err = feature->SetValue( "On" );
if( VmbErrorSuccess != err )
{
std::cout << "Could not set notification 'On'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventNotification'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get selector '" << eventName << "'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get feature 'EventSelector'. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,83 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: EventHandling.h
Description: The EventHandling example will register observer on all
'EventData' features and turn on camera notification for
'AcquisitionStart' events.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_EVENT_HANDLING
#define AVT_VMBAPI_EXAMPLES_EVENT_HANDLING
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class EventHandling
{
public:
// Purpose: Example execution.
//
// Parameter:
// [in ] std::string cameraID Use camera with this ID for the example.
void RunExample( std::string cameraID );
private:
// Purpose: Deactivate all camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType DeactivateAllCameraNotifications( CameraPtr pCamera );
// Purpose: Create for each 'Camera->EventData' feature an observer and register it.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType RegisterEventObserver( CameraPtr pCamera );
// Purpose: Activate camera notification.
//
// Parameter:
// [in ] CameraPtr pCamera Intern camera object.
// [in ] std::string eventName Name of event to activate.
//
// Returns:
// VmbErrorSuccess in case of success otherwise an error code
VmbErrorType ActivateNotification( CameraPtr pCamera, std::string eventName );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,71 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: EventObserver.h
Description: The EventObserver can be attached to a camera feature. On Feature
changing the function FeatureChanged() is called.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "EventObserver.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
EventObserver::EventObserver( AVT::VmbAPI::CameraPtr pCam )
: m_pCam( pCam )
{
}
// Purpose: This function will be called when the observed feature is changing.
//
// Parameter:
// [in ] const AVT::VmbAPI::FeaturePtr &feature changed feature
//
void EventObserver::FeatureChanged( const AVT::VmbAPI::FeaturePtr &feature )
{
if( feature != NULL )
{
std::string featureName;
if ( !feature->GetName( featureName ) )
{
std::cout << featureName << " (Event) has changed to ";
AVT::VmbAPI::FeaturePtr pFeature;
VmbInt64_t nID;
if ( !( m_pCam->GetFeatureByName( featureName.c_str(), pFeature ) )
&& !( pFeature->GetValue( nID ) ) )
{
std::cout << nID << std::endl;
}
}
else
{
std::cout << "An error occurred" << std::endl;
}
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,58 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: EventObserver.h
Description: The EventObserver can be attached to a camera feature. On Feature
changing the function FeatureChanged() is called.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_EVENT_OBSERVER_H
#define AVT_VMBAPI_EXAMPLES_EVENT_OBSERVER_H
#include <string>
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
class EventObserver : public AVT::VmbAPI::IFeatureObserver
{
private:
AVT::VmbAPI::CameraPtr m_pCam;
public:
// Purpose: This function will be called when the observed feature is changing.
//
// Parameter:
// [in ] const AVT::VmbAPI::FeaturePtr &feature changed feature
//
virtual void FeatureChanged( const AVT::VmbAPI::FeaturePtr &feature );
EventObserver( AVT::VmbAPI::CameraPtr pCam );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of EventHandling example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "EventHandling.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "////////////////////////////////////////\n";
std::cout << "/// Vimba API Event Handling Example ///\n";
std::cout << "////////////////////////////////////////\n\n";
if( 2 < argc )
{
std::cout << "Usage: EventHandling [CameraID]\n\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
}
else if( 2 == argc )
{
AVT::VmbAPI::Examples::EventHandling eventHandler;
eventHandler.RunExample( argv[1] );
}
else
{
AVT::VmbAPI::Examples::EventHandling eventHandler;
eventHandler.RunExample( "" );
}
std::cout <<"\n";
}

View File

@@ -0,0 +1,50 @@
PROJECT_NAME = ListAncillaryDataFeatures
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListAncillaryDataFeatures.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,384 @@
/*=============================================================================
Copyright (C) 2014 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListAncillaryDataFeatures.cpp
Description: The ListAncillaryDataFeatures example will list all available
features of a camera that are found by VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ListAncillaryDataFeatures.h>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// Purpose: Uses an API feature to set the biggest packet size possible
//
// Parameter:
// [in ] CamerPtr pCamera The camera to work on
VmbErrorType AdjustPacketSize(CameraPtr pCamera)
{
FeaturePtr pPacketSize;
VmbErrorType err;
err = SP_ACCESS( pCamera )->GetFeatureByName( "GVSPAdjustPacketSize", pPacketSize );
if( VmbErrorSuccess == err )
{
err = SP_ACCESS( pPacketSize )->RunCommand() ;
if( VmbErrorSuccess == err)
{
bool bIsCommandDone = false;
do
{
if( VmbErrorSuccess != SP_ACCESS( pPacketSize )->IsCommandDone( bIsCommandDone ) )
{
break;
}
} while( false == bIsCommandDone );
}
}
return err;
}
enum
{
ACQ_TIMEOUT = 1000,
};
// Purpose: Prints out the value of a given feature
//
// Parameter:
// [in ] const FeaturePtr& feature A reference to the feature shared pointer
void PrintFeatureValue( const FeaturePtr& pFeature )
{
VmbFeatureDataType featureType;
VmbErrorType err = pFeature->GetDataType( featureType );
if( VmbErrorSuccess != err )
{
std::cout << "[Could not get feature Data Type. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]\n";
}
else
{
std::cout << "/// Value : ";
switch( featureType )
{
case VmbFeatureDataBool:
{
VmbBool_t value;
err = pFeature->GetValue( value );
if ( VmbErrorSuccess == err )
{
std::cout << value << "\n";
}
}
break;
case VmbFeatureDataEnum:
{
std::string value;
err = pFeature->GetValue( value );
if ( VmbErrorSuccess == err )
{
std::cout << value << "\n";
}
}
break;
case VmbFeatureDataFloat:
{
double value;
err = pFeature->GetValue( value );
if( VmbErrorSuccess == err)
{
std::cout << value << "\n";
}
}
break;
case VmbFeatureDataInt:
{
VmbInt64_t value;
err = pFeature->GetValue( value );
if( VmbErrorSuccess == err)
{
std::cout << value << "\n";
}
}
break;
case VmbFeatureDataString:
{
std::string value;
err = pFeature->GetValue( value );
if( VmbErrorSuccess == err)
{
std::cout << value << "\n";
}
}
break;
case VmbFeatureDataCommand:
default:
std::cout << "[None]" << "\n";
break;
}
if( VmbErrorSuccess == err )
{
std::cout << "\n";
}
else
{
std::cout << "Could not get feature value. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n\n";
}
}
}
// Purpose: Prints out all details of a given feature
//
// Parameter:
// [in ] const FeaturePtr& pFeature A reference to the feature shared pointer
void PrintFeature( const FeaturePtr& pFeature )
{
std::string name; // The name of the feature
std::string displayName; // The display name of the feature
std::string toolTip; // A short description of the feature
std::string description; // A long description of the feature
std::string category; // A category to group features
std::string sfncNamespace; // The Standard Feature Naming Convention namespace
std::string unit; // The measurement unit of the value
std::ostringstream ErrorStream;
VmbErrorType err = pFeature->GetName( name );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Name. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
name = ErrorStream.str();
}
err = pFeature->GetDisplayName( displayName );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Display Name. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
displayName = ErrorStream.str();
}
err = pFeature->GetToolTip( toolTip );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Tooltip. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
toolTip = ErrorStream.str();
}
err = pFeature->GetDescription( description );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Description. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
description = ErrorStream.str();
}
err = pFeature->GetCategory( category );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Category. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
category = ErrorStream.str();
}
err = pFeature->GetSFNCNamespace( sfncNamespace );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature SNFC Namespace. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
sfncNamespace = ErrorStream.str();
}
err = pFeature->GetUnit( unit );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Unit. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
unit = ErrorStream.str();
}
std::cout << "/// Feature Name : " << name << "\n";
std::cout << "/// Display Name : " << displayName << "\n";
std::cout << "/// Tooltip : " << toolTip << "\n";
std::cout << "/// Description : " << description << "\n";
std::cout << "/// SNFC Namespace : " << sfncNamespace << "\n";
PrintFeatureValue( pFeature );
}
// Purpose: Pints out features from the ancillary data. Ancillary data is part of a frame,
// therefore we need to capture a single frame beforehand.
// If no camera ID string was passed we use the first camera found.
//
// Parameter:
// [in ] string cameraID The ID of the camera to use
void ListAncillaryDataFeatures::Print( std::string cameraID )
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
std::cout << "Vimba C++ API Version " << sys << "\n"; // Print out version of Vimba
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
FeaturePtrVector features; // A vector of std::shared_ptr<AVT::VmbAPI::Feature> objects
CameraPtr pCamera = CameraPtr(); // Our camera
std::stringstream errorString;
if( VmbErrorSuccess == err )
{
if( cameraID.empty() ) // If no ID was provided use the first camera
{
CameraPtrVector cameras;
err = sys.GetCameras( cameras );
if( VmbErrorSuccess == err
&& !cameras.empty() )
{
pCamera = cameras[0]; // Get the camera
err = pCamera->Open( VmbAccessModeFull ); // Open the camera
if( VmbErrorSuccess == err )
{
err = pCamera->GetID( cameraID );
}
}
}
else
{
err = sys.OpenCameraByID( cameraID.c_str(), // Get and open the camera
VmbAccessModeFull,
pCamera );
}
if( !SP_ISNULL( pCamera ))
{
if ( VmbErrorSuccess == err )
{
AdjustPacketSize( pCamera );
std::cout << "Printing all ancillary data features of camera with ID: " << cameraID << "\n\n";
FeaturePtr pFeature;
err = pCamera->GetFeatureByName( "ChunkModeActive", pFeature );
if( VmbErrorSuccess == err )
{
err = pFeature->SetValue( true ); // Enable ancillary data
if( VmbErrorSuccess == err )
{
std::cout << "Capture a single frame\n\n"; // In order to fill the ancillary data we need to fill a frame
FramePtr pFrame;
err = pCamera->AcquireSingleImage( pFrame, ACQ_TIMEOUT );
if ( VmbErrorSuccess == err )
{
VmbFrameStatusType status;
err = pFrame->GetReceiveStatus( status ); // Check whether we received a complete frame
if( VmbErrorSuccess == err )
{
if ( VmbFrameStatusComplete == status )
{
AncillaryDataPtr pAncillaryData;
err = pFrame->GetAncillaryData( pAncillaryData ); // Get the ancillary data of the frame
if ( VmbErrorSuccess == err )
{
err = pAncillaryData->Open();
if( VmbErrorSuccess == err)
{
err = pAncillaryData->GetFeatures( features ); // Fetch all features of the ancillary data
if( VmbErrorSuccess == err )
{
// Query all static details as well as the value of all fetched features and print them out.
std::for_each( features.begin(), features.end(), PrintFeature );
}
else
{
std::cout << "Could not get features. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
pAncillaryData->Close();
}
else
{
std::cout << "Could not open ancillary data. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not get ancillary data. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else if( VmbFrameStatusIncomplete == status )
{
std::cout << "Could not acquire complete frame. Receive status: " << err << "\n";
}
else
{
std::cout << "Could not acquire frame. Receive status: " << err << "\n";
}
}
else
{
std::cout << "Could not get frame receive status. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not acquire image. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "Could not enable ancillary data. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else if( VmbErrorNotFound == err )
{
std::cout << "The camera does not provide ancillary data. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
else
{
std::cout << "Could not query for the presence of ancillary data. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
pCamera->Close();
}
else
{
std::cout << "Could not open camera. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
else
{
std::cout << "No camera available.\n";
}
sys.Shutdown(); // Finally close Vimba
}
else
{
std::cout << "Could not start system. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,52 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListAncillaryDataFeatures.h
Description: The ListAncillaryDataFeatures example will list all available
features of the ancillary data.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_LISTANCILLARYDATAFEATURES
#define AVT_VMBAPI_EXAMPLES_LISTANCILLARYDATAFEATURES
#include <string>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ListAncillaryDataFeatures
{
public:
// Purpose: Pints out features from the ancillary data. Ancillary data is part of a frame,
// therefore we need to capture a single frame beforehand.
// If no camera ID string was passed we use the first camera found.
//
// Parameter:
// [in ] string cameraID The ID of the camera to use
static void Print( std::string cameraID );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,54 @@
/*=============================================================================
Copyright (C) 2014 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of ListAncillaryDataFeatures example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "ListAncillaryDataFeatures.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "//////////////////////////////////////////////////////\n";
std::cout << "/// Vimba API List Ancillary Data Features Example ///\n";
std::cout << "//////////////////////////////////////////////////////\n\n";
if( 2 < argc )
{
std::cout << "Usage: ListAncillaryDataFeatures [CameraID]\n\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
}
else if( 2 == argc )
{
AVT::VmbAPI::Examples::ListAncillaryDataFeatures::Print( argv[1] );
}
else
{
AVT::VmbAPI::Examples::ListAncillaryDataFeatures::Print( "" );
}
std::cout << "\n";
}

View File

@@ -0,0 +1,50 @@
PROJECT_NAME = ListCameras
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListCameras.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,138 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListCameras.cpp
Description: The ListCameras example will list all available cameras that
are found by VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include "ListCameras.h"
#include "VimbaCPP/Include/VimbaCPP.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
/**printing camera info for a camera.
*\note this function is used with for_each and is called for each camera in range cameras.begin(), cameraas.end()
*/
void PrintCameraInfo( const CameraPtr &camera )
{
std::string strID;
std::string strName;
std::string strModelName;
std::string strSerialNumber;
std::string strInterfaceID;
std::ostringstream ErrorStream;
VmbErrorType err = camera->GetID( strID );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get camera ID. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strID = ErrorStream.str();
}
err = camera->GetName( strName );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get camera name. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strName = ErrorStream.str() ;
}
err = camera->GetModel( strModelName );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get camera mode name. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strModelName = ErrorStream.str();
}
err = camera->GetSerialNumber( strSerialNumber );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get camera serial number. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strSerialNumber = ErrorStream.str();
}
err = camera->GetInterfaceID( strInterfaceID );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get interface ID. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "]";
strInterfaceID = ErrorStream.str() ;
}
std::cout << "/// Camera Name : " << strName << "\n"
<< "/// Model Name : " << strModelName << "\n"
<< "/// Camera ID : " << strID << "\n"
<< "/// Serial Number : " << strSerialNumber << "\n"
<< "/// @ Interface ID : " << strInterfaceID << "\n\n";
}
//
// Starts Vimba
// Gets all connected cameras
// And prints out information about the camera name, model name, serial number, ID and the corresponding interface ID
//
void ListCameras::Print()
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
std::cout<<"Vimba C++ API Version "<<sys<<"\n"; // Print out version of Vimba
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
CameraPtrVector cameras; // A vector of std::shared_ptr<AVT::VmbAPI::Camera> objects
std::stringstream strError;
if( VmbErrorSuccess == err )
{
err = sys.GetCameras( cameras ); // Fetch all cameras known to Vimba
if( VmbErrorSuccess == err )
{
std::cout << "Cameras found: " << cameras.size() <<"\n\n";
// Query all static details of all known cameras and print them out.
// We don't have to open the cameras for that.
std::for_each( cameras.begin(), cameras.end(), PrintCameraInfo );
}
else
{
std::cout << "Could not list cameras. Error code: " << err << "("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "\n";
}
sys.Shutdown(); // Close Vimba
}
else
{
std::cout << "Could not start system. Error code: " << err <<"("<<AVT::VmbAPI::Examples::ErrorCodeToMessage(err)<<")"<< "\n";
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,49 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListCameras.h
Description: The ListCameras example will list all available cameras that
are found by VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_LISTCAMERAS
#define AVT_VMBAPI_EXAMPLES_LISTCAMERAS
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ListCameras
{
public:
//
// Starts Vimba
// Gets all connected cameras
// And prints out information about the camera name, model name, serial number, ID and the corresponding interface ID
//
static void Print();
};
}}} // mamespace AVT::Vimba::Examples
#endif

View File

@@ -0,0 +1,47 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of ListCameras example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "ListCameras.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "//////////////////////////////////////\n";
std::cout << "/// Vimba API List Cameras Example ///\n";
std::cout << "//////////////////////////////////////\n\n";
if( 1 < argc )
{
std::cout << "No parameters expected. Execution will not be affected by the provided parameter(s).\n\n";
}
AVT::VmbAPI::Examples::ListCameras::Print();
std::cout << "\n";
}

View File

@@ -0,0 +1,50 @@
PROJECT_NAME = ListFeatures
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/ListFeatures.o \
$(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,314 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListFeatures.cpp
Description: The ListFeatures example will list all available features of a
camera that are found by VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <sstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <ListFeatures.h>
#include "VimbaCPP/Include/VimbaCPP.h"
#include "Common/StreamSystemInfo.h"
#include "Common/ErrorCodeToMessage.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
//
// Prints out an error message in case a feature's value could not be queried.
// Prints nothing in case the error means success.
//
// Parameters:
// [in] err The return code indicating the error
//
// Returns:
// The error code as passed in
//
VmbErrorType PrintGetValueErrorMessage ( const VmbErrorType err )
{
if ( VmbErrorSuccess != err )
{
std::cout << "Could not get feature value. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
return err;
}
//
// Prints out the value and the type of a given feature
//
// Parameters:
// [in] feature The feature to work on
//
void PrintFeatureValue( const FeaturePtr &feature )
{
VmbFeatureDataType eType;
VmbErrorType err = feature->GetDataType( eType );
if( VmbErrorSuccess != err )
{
std::cout << "[Could not get feature Data Type. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]\n";
}
else
{
std::cout << "/// Value : ";
switch( eType )
{
case VmbFeatureDataBool:
{
VmbBool_t bValue;
err = feature->GetValue( bValue );
if ( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << bValue << "\n";
}
std::cout << "/// Type : Boolean\n";
}
break;
case VmbFeatureDataEnum:
{
std::string strValue;
err = feature->GetValue( strValue );
if ( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << strValue << "\n";
}
std::cout << "/// Type : Enumeration\n";
}
break;
case VmbFeatureDataFloat:
{
double fValue;
double fMin, fMax;
err = feature->GetValue( fValue );
if( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << fValue << "\n";
}
std::cout << "/// Minimum : ";
err = feature->GetRange( fMin, fMax );
if( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << fMin << "\n";
std::cout << "/// Maximum : " << fMax << "\n";
}
std::cout << "/// Type : Double precision floating point\n";
}
break;
case VmbFeatureDataInt:
{
VmbInt64_t nValue;
VmbInt64_t nMin, nMax;
err = feature->GetValue( nValue );
if( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << nValue << "\n";
}
std::cout << "/// Minimum : ";
err = feature->GetRange( nMin, nMax );
if( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << nMin << "\n";
std::cout << "/// Maximum : " << nMax << "\n";
}
std::cout << "/// Type : Long long integer\n";
}
break;
case VmbFeatureDataString:
{
std::string strValue;
err = feature->GetValue( strValue );
if( VmbErrorSuccess == PrintGetValueErrorMessage( err ) )
{
std::cout << strValue << "\n";
}
std::cout << "/// Type : String\n";
}
break;
case VmbFeatureDataCommand:
default:
{
std::cout << "[None]" << "\n";
std::cout << "/// Type : Command feature\n";
}
break;
}
std::cout << "\n";
}
}
//
// Prints out all details of a feature
//
// Parameters:
// [in] feature The feature to work on
//
void PrintFeatures( const FeaturePtr &feature )
{
std::string strName; // The name of the feature
std::string strDisplayName; // The display name of the feature
std::string strToolTip; // A short description of the feature
std::string strDescription; // A long description of the feature
std::string strCategory; // A category to group features
std::string strSFNCNamespace; // The Standard Feature Naming Convention namespace
std::string strUnit; // The measurement unit of the value
std::ostringstream ErrorStream;
VmbErrorType err = feature->GetName( strName );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Name. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strName = ErrorStream.str();
}
err = feature->GetDisplayName( strDisplayName );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Display Name. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strDisplayName = ErrorStream.str();
}
err = feature->GetToolTip( strToolTip );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Tooltip. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strToolTip = ErrorStream.str();
}
err = feature->GetDescription( strDescription );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Description. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strDescription = ErrorStream.str();
}
err = feature->GetCategory( strCategory );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Category. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strCategory = ErrorStream.str();
}
err = feature->GetSFNCNamespace( strSFNCNamespace );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature SNFC Namespace. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strSFNCNamespace = ErrorStream.str();
}
err = feature->GetUnit( strUnit );
if( VmbErrorSuccess != err )
{
ErrorStream << "[Could not get feature Unit. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "]";
strUnit = ErrorStream.str();
}
std::cout << "/// Feature Name : " << strName << "\n";
std::cout << "/// Display Name : " << strDisplayName << "\n";
std::cout << "/// Tooltip : " << strToolTip << "\n";
std::cout << "/// Description : " << strDescription << "\n";
std::cout << "/// SNFC Namespace : " << strSFNCNamespace << "\n";
std::cout << "/// Unit : " << strUnit << "\n";
PrintFeatureValue( feature );
}
//
// Prints out all features and their values and details of a given camera.
// If no camera ID is provided, the first camera will be used.
// Starts and stops the API
// Opens and closes the camera
//
// Parameters:
// [in] CameraID The ID of the camera to work
//
void ListFeatures::Print( std::string CameraID )
{
VimbaSystem& sys = VimbaSystem::GetInstance(); // Get a reference to the VimbaSystem singleton
std::cout << "Vimba C++ API Version " << sys << "\n"; // Print out version of Vimba
VmbErrorType err = sys.Startup(); // Initialize the Vimba API
FeaturePtrVector features; // A vector of std::shared_ptr<AVT::VmbAPI::Feature> objects
CameraPtr pCamera = CameraPtr(); // Our camera
std::stringstream strError;
if( VmbErrorSuccess == err )
{
if( CameraID.empty() ) // If no ID was provided use the first camera
{
CameraPtrVector cameras;
err = sys.GetCameras( cameras );
if( VmbErrorSuccess == err
&& !cameras.empty() )
{
err = cameras[0]->Open( VmbAccessModeFull ); // Open the camera
if( VmbErrorSuccess == err )
{
pCamera = cameras[0];
err = pCamera->GetID( CameraID );
}
}
}
else
{
err = sys.OpenCameraByID( CameraID.c_str(), VmbAccessModeFull, pCamera ); // Get and open the camera
}
if( NULL != pCamera )
{
std::cout << "Printing all features of camera with ID: " << CameraID << "\n";
err = pCamera->GetFeatures( features ); // Fetch all features of our cam
if( VmbErrorSuccess == err )
{
// Query all static details as well as the value of all fetched features and print them out.
std::for_each( features.begin(), features.end(), PrintFeatures );
}
else
{
std::cout << "Could not get features. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
pCamera->Close();
}
else
{
std::cout << "Could not open camera or no camera available. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
sys.Shutdown();
}
else
{
std::cout << "Could not start system. Error code: " << err << " (" << AVT::VmbAPI::Examples::ErrorCodeToMessage( err ) << ")" << "\n";
}
}
}}} // namespace AVT::VmbAPI::Examples

View File

@@ -0,0 +1,55 @@
/*=============================================================================
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: ListFeatures.h
Description: The ListFeatures example will list all available features of a
camera that are found by VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifndef AVT_VMBAPI_EXAMPLES_LISTFEATURES
#define AVT_VMBAPI_EXAMPLES_LISTFEATURES
#include <string>
namespace AVT {
namespace VmbAPI {
namespace Examples {
class ListFeatures
{
public:
//
// Prints out all features and their values and details of a given camera.
// If no camera ID is provided, the first camera will be used.
// Starts and stops the API
// Opens and closes the camera
//
// Parameters:
// [in] CameraID The ID of the camera to work
//
static void Print( std::string CameraID );
};
}}} // namespace AVT::VmbAPI::Examples
#endif

View File

@@ -0,0 +1,54 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: Main entry point of ListFeatures example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include "ListFeatures.h"
int main( int argc, char* argv[] )
{
std::cout << "\n";
std::cout << "///////////////////////////////////////\n";
std::cout << "/// Vimba API List Features Example ///\n";
std::cout << "///////////////////////////////////////\n\n";
if( 2 < argc )
{
std::cout << "Usage: ListFeatures [CameraID]\n\n";
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
}
else if( 2 == argc )
{
AVT::VmbAPI::Examples::ListFeatures::Print( argv[1] );
}
else
{
AVT::VmbAPI::Examples::ListFeatures::Print( "" );
}
std::cout <<"\n";
}

View File

@@ -0,0 +1,53 @@
PROJECT_NAME = LoadSaveSettings
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
include $(MAKE_INCLUDE_DIR)/tinyxml.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS) \
$(TINYXML_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS) \
$(TINYXML_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/program.o
DEPENDENCIES = VimbaCPP \
tinyxml
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,472 @@
/*=============================================================================
Copyright (C) 2016 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: program.cpp
Description: LoadSaveSettings example of VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <iostream>
#include <sstream>
#include <VimbaCPP/Include/VimbaCPP.h>
int main( int argc, char* argv[] )
{
using namespace AVT::VmbAPI;
VmbErrorType err = VmbErrorSuccess;
std::stringstream ss;
bool apiFlag = false;
bool cameraFlag = false;
std::cout << std::endl;
std::cout << "////////////////////////////////////////////" << std::endl;
std::cout << "/// Vimba API Load/Save Settings Example ///" << std::endl;
std::cout << "////////////////////////////////////////////" << std::endl;
std::cout << std::endl;
// create camera pointer
// get VimbaCPP instance singleton
CameraPtr pCam;
VimbaSystem &sys = VimbaSystem::GetInstance();
try
{
// start Vimba API
err = sys.Startup();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not start Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
throw std::exception();
}
apiFlag = true;
std::cout << "--> VimbaCPP has been started" << std::endl;
// get connected cameras from VimbaCPP
CameraPtrVector pCameras;
err = sys.GetCameras( pCameras );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not get connected cameras [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
throw std::exception();
}
// select first camera in list
pCam = pCameras[0];
// open camera
err = pCam->Open( VmbAccessModeFull );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not open camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
throw std::exception();
}
// get camera id
std::string cameraId;
err = pCam->GetID( cameraId );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not get camera id [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
throw std::exception();
}
cameraFlag = true;
ss.str( "" );
ss << "--> Camera with id '" << cameraId << "' has been opened";
std::cout << ss.str() << std::endl;
// create xml file name
ss.str( "" );
ss << cameraId << ".xml";
std::string xmlFile = ss.str();
// -------------------------------------------------------------------------------------
// setup load/save settings behaviour:
// there are three different ways in VimbaCPP to setup the behaviour for
// loading and saving feature values with load/save settings implementation.
// SaveCameraSettings() and LoadCameraSettings() can be called either with
// an created struct of type 'VmbFeaturePersistSettings_t' or not. The third
// alternative is to call LoadSaveSettingsSetup() beforehand and provide the
// same parameters as it will be done by the struct.
//
// (1) default usage:
// pCam->SaveCameraSettings( xmlFile );
// pCam->LoadCameraSettings( xmlFile );
//
// (2) usage with settings struct:
// VmbFeaturePersistSettings_t settingsStruct;
// settingsStruct.loggingLevel = 4; // set logging level (0:info only, 1: with errors, 2: with warnings, 3: with debug, 4: with traces)
// settingsStruct.maxIterations = 5; // since its difficult to catch all feature dependencies during loading multiple
// iterations are used (compare desired value with camera value and write it to camera)
// settingsStruct.persistType = VmbFeaturePersistNoLUT; // set which features shall be persisted (saved to XML):
// VmbFeaturePersistAll: all features shall be persisted (including LUTs).
// VmbFeaturePersistStreamable: only streamable features shall be persisted.
// VmbFeaturePersistNoLUT: all features shall be persisted except for LUT,
// which is the recommended setting, because it might be very time consuming.
// pCam->SaveCameraSettings( xmlFile, &settingsStruct );
// pCam->LoadCameraSettings( xmlFile, &settingsStruct );
//
// (3) usage with setup method:
// pCam->LoadSaveSettingsSetup( VmbFeaturePersistNoLUT, 5, 4 );
// pCam->SaveCameraSettings( xmlFile );
// pCam->LoadCameraSettings( xmlFile );
// -------------------------------------------------------------------------------------
// call VimbaCPP method for saving all feature values
err = pCam->SaveCameraSettings( xmlFile );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not save camera settings to file '" << xmlFile << "' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
ss.str( "" );
ss << "--> Feature values have been saved to '" << xmlFile << "'";
std::cout << ss.str() << std::endl;
// get feature selector for user set
FeaturePtr feature;
err = pCam->GetFeatureByName( "UserSetSelector", feature );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not get feature 'UserSetSelector' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
// set value of selector to 'Default'
err = feature->SetValue( "Default" );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not set value of feature 'UserSetSelector' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
// get feature command 'UserSetLoad'
err = pCam->GetFeatureByName( "UserSetLoad", feature );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not get feature 'UserSetLoad' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
// load selected user set
err = feature->RunCommand();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not run command 'UserSetLoad' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
std::cout << "--> All feature values have been restored to default" << std::endl;
// create settings struct to determine behaviour during loading
VmbFeaturePersistSettings_t settingsStruct;
settingsStruct.loggingLevel = 4;
settingsStruct.maxIterations = 5;
settingsStruct.persistType = VmbFeaturePersistNoLUT;
// re-load saved settings from file
err = pCam->LoadCameraSettings( xmlFile, &settingsStruct );
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not load camera settings to file '" << xmlFile << "' [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
cameraFlag = false;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
ss.str( "" );
ss << "--> Feature values have been loaded from given XML file '" << xmlFile << "'";
std::cout << ss.str() << std::endl;
// close camera
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
apiFlag = false;
throw std::exception();
}
cameraFlag = false;
std::cout << "--> Camera has been closed" << std::endl;
// shutdown Vimba
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
throw std::exception();
}
apiFlag = false;
std::cout << "--> VimbaCPP has been shut down" << std::endl;
}
catch( std::exception &e )
{
std::cout << "[Exception] " << e.what() << std::endl;
if( true == cameraFlag )
{
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
}
if( true == apiFlag )
{
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
}
}
catch(...)
{
std::cout << "[Exception]" << std::endl;
if( true == cameraFlag )
{
err = pCam->Close();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not close camera [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
}
if( true == apiFlag )
{
err = sys.Shutdown();
if( VmbErrorSuccess != err )
{
ss.str( "" );
ss << "Could not shutdown Vimba [error code: " << err << "]";
std::cout << ss.str() << std::endl;
}
}
}
std::cout << std::endl << "<<press any key to close example>>" << std::endl;
std::cin.get();
return err;
}

View File

@@ -0,0 +1,51 @@
PROJECT_NAME = LookUpTable
PROJECT_DIR = ../..
EXAMPLES_DIR = $(PROJECT_DIR)/..
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
include $(MAKE_INCLUDE_DIR)/Common.mk
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
BIN_FILE = $(PROJECT_NAME)
BIN_DIR = binary/$(CONFIG_DIR)
OBJ_DIR = object/$(CONFIG_DIR)
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
all: $(BIN_PATH)
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBACPP_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBACPP_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/LookUpTable.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/Csv.o
DEPENDENCIES = VimbaCPP
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
clean:
$(RM) binary -r -f
$(RM) object -r -f
$(OBJ_DIR):
$(MKDIR) -p $(OBJ_DIR)
$(BIN_DIR):
$(MKDIR) -p $(BIN_DIR)

View File

@@ -0,0 +1,97 @@
/*=============================================================================
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
Redistribution of this file, in original or modified form, without
prior written consent of Allied Vision Technologies is prohibited.
-------------------------------------------------------------------------------
File: Csv.cpp
Description: Helper to access a CSV file using VimbaCPP.
-------------------------------------------------------------------------------
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#include <vector>
#include "Csv.h"
#include "VimbaCPP/Include/VimbaCPP.h"
namespace AVT {
namespace VmbAPI {
namespace Examples {
// Class to write data to a CSV file
CsvSave::CsvSave( const std::string &FileName )
:m_Stream( FileName.c_str() )
{ }
// Writes a single row to a CSV file.
bool CsvSave::Row( const std::string &text )
{
if( 0 == text.size() )
{
return false;
}
std::string line = text + m_CsvParameter.RD() ;
m_Stream.write( line.c_str(), line.length() );
return true;
}
// Class to load data from CSV
CsvLoad::CsvLoad( const std::string &filename )
: m_Stream( filename.c_str() )
{}
// Reads a row of data from CSV
bool CsvLoad::Row( std::vector<std::string> &row )
{
row.clear();
char pLineText[256];
if( m_Stream.getline( pLineText, 256, m_CsvParameter.RD() ) )
{
std::string lineText = std::string( pLineText );
if( 0 == lineText.size() )
{
return false;
}
typedef std::string::size_type pos_type;
pos_type pos = 0;
while( pos != std::string::npos )
{
pos_type start = pos;
pos = lineText.find( m_CsvParameter.VD(), start );
const std::string value = lineText.substr( start, pos );
row.push_back( value );
if( pos != std::string::npos )
{
pos++;
}
}
}
else
{
return false;
}
return ( row.size() > 0 );
}
}}} // namespace AVT::VmbAPI::Examples

Some files were not shown because too many files have changed in this diff Show More