AVT相机arm版本SDK
This commit is contained in:
51
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Build/Make/Makefile
Normal file
51
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Build/Make/Makefile
Normal 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)
|
||||
97
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Csv.cpp
Normal file
97
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Csv.cpp
Normal 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
|
||||
90
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Csv.h
Normal file
90
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Csv.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/*=============================================================================
|
||||
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.h
|
||||
|
||||
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.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef AVT_VMBAPI_EXAMPLES_LOOKUPTABLE_CSV
|
||||
#define AVT_VMBAPI_EXAMPLES_LOOKUPTABLE_CSV
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "VimbaCPP/Include/VimbaCPP.h"
|
||||
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class Csv
|
||||
{
|
||||
private:
|
||||
char m_VD;
|
||||
char m_RD;
|
||||
bool m_bHasHeader;
|
||||
|
||||
public:
|
||||
//ctor
|
||||
Csv()
|
||||
: m_VD( ';' )
|
||||
, m_RD( '\n' )
|
||||
, m_bHasHeader( false )
|
||||
{ }
|
||||
char VD( ) const { return m_VD; }
|
||||
void VD( char vd ) { m_VD = vd;}
|
||||
char RD ( ) const { return m_RD; }
|
||||
bool HasHeader() const { return m_bHasHeader; }
|
||||
void HasHeader( bool bHasHeader ) { m_bHasHeader = bHasHeader; }
|
||||
|
||||
};
|
||||
|
||||
class CsvLoad
|
||||
{
|
||||
private:
|
||||
std::ifstream m_Stream;
|
||||
Csv m_CsvParameter;
|
||||
public:
|
||||
//ctor
|
||||
CsvLoad( const std::string &filename );
|
||||
bool Row( std::vector<std::string> &row );
|
||||
};
|
||||
|
||||
class CsvSave
|
||||
{
|
||||
private:
|
||||
std::ofstream m_Stream;
|
||||
Csv m_CsvParameter;
|
||||
public:
|
||||
//ctor
|
||||
CsvSave( const std::string &filename );
|
||||
|
||||
bool Row( const std::string &text );
|
||||
};
|
||||
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
87
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Exception.h
Normal file
87
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/Exception.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*=============================================================================
|
||||
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: Exception.h
|
||||
|
||||
Description: Helper for exceptions.
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
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_EXCEPTION
|
||||
#define AVT_VMBAPI_EXAMPLES_EXCEPTION
|
||||
|
||||
#include "VimbaCPP/Include/VimbaCPP.h"
|
||||
#include "Common/ErrorCodeToMessage.h"
|
||||
using namespace std;
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class Exception: public exception
|
||||
{
|
||||
private:
|
||||
std::string m_sMsg;
|
||||
// Vimba error code
|
||||
VmbErrorType m_eError;
|
||||
public:
|
||||
Exception( const std::string &rsMessage, const VmbErrorType eError )
|
||||
: m_eError(eError)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_sMsg = rsMessage;
|
||||
} catch(...){}
|
||||
}
|
||||
Exception( const std::string &Fun, const std::string &rsMessage, const VmbErrorType eError )
|
||||
: m_eError(eError)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_sMsg = Fun + ": " + rsMessage;
|
||||
} catch(...){}
|
||||
}
|
||||
|
||||
virtual ~Exception() throw()
|
||||
{
|
||||
}
|
||||
|
||||
VmbErrorType GetError() const
|
||||
{
|
||||
return m_eError;
|
||||
}
|
||||
|
||||
std::string GetMessageStr() const
|
||||
{
|
||||
return m_sMsg;
|
||||
}
|
||||
|
||||
// Translates Vimba error codes to readable error messages
|
||||
std::string ErrorCodeToMessage( VmbErrorType eErr )
|
||||
{
|
||||
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
569
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/LookUpTable.cpp
Normal file
569
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/LookUpTable.cpp
Normal file
@@ -0,0 +1,569 @@
|
||||
/*=============================================================================
|
||||
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: LookUpTable.cpp
|
||||
|
||||
Description: The LookUpTable example will demonstrate how to use
|
||||
the look up table feature of the 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 <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "LookUpTable.h"
|
||||
#include "Csv.h"
|
||||
#include "Exception.h"
|
||||
#include "VimbaFeatures.h"
|
||||
#include "VimbaCPP/Include/VimbaCPP.h"
|
||||
|
||||
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
namespace
|
||||
{ // toolset to handle network byte order, for production, use htons ntohs for int16
|
||||
static const union
|
||||
{
|
||||
VmbUint8_t bytes[4];
|
||||
VmbUint32_t v;
|
||||
} host_byte_order = {{0,1,2,3}};
|
||||
enum
|
||||
{
|
||||
byte_oder_little_endian = 0x03020100ul,
|
||||
byte_oder_big_endian = 0x01000302ul,
|
||||
};
|
||||
|
||||
inline UcharVector ConvertToNetworkInt16( const UcharVector &d)
|
||||
{
|
||||
if (host_byte_order.v == byte_oder_little_endian)
|
||||
{
|
||||
UcharVector tmp( d );
|
||||
for( size_t i = 0 ;i < tmp.size(); i +=2)
|
||||
{
|
||||
VmbUint16_t *p = reinterpret_cast<VmbUint16_t*>( &tmp[i] );
|
||||
*p = ((*p>>8) & 0xff) | ((*p<<8) & 0xff00);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
inline UcharVector ConvertFromNetworkInt16( const UcharVector &d)
|
||||
{
|
||||
return ConvertToNetworkInt16( d );
|
||||
}
|
||||
}
|
||||
bool LookUpTableCollection::HasLookUpTable(CameraPtr pCamera )
|
||||
{
|
||||
return VimbaFeature::HasFeature( pCamera, "LUTSelector");
|
||||
}
|
||||
LookUpTableCollection::LookUpTableCollection( CameraPtr pCamera )
|
||||
: m_pCamera( pCamera )
|
||||
{
|
||||
//Check parameters
|
||||
if( NULL == m_pCamera )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"LookUpTableCollection failed camera pointer NULL.", VmbErrorBadParameter );
|
||||
}
|
||||
|
||||
|
||||
VmbInt64_t nCount = GetCount( );
|
||||
if( 0 == nCount )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"LookUpTableCollection no entries.", VmbErrorNotFound );
|
||||
}
|
||||
// for each lookup table create a control
|
||||
for( int i = 0; i < nCount; i++ )
|
||||
{
|
||||
m_tables.push_back( LookUpTableControl( m_pCamera, i ));
|
||||
}
|
||||
}
|
||||
|
||||
//Get look up table count
|
||||
VmbInt64_t LookUpTableCollection::GetCount( )
|
||||
{
|
||||
// number of LUTs is the number of enum values fo the "LUTSelector" Feature
|
||||
VimbaFeatureEnum LutSelector( m_pCamera, "LUTSelector" );
|
||||
return LutSelector.ValueCount();
|
||||
}
|
||||
|
||||
//Get look up table control
|
||||
LookUpTableControl LookUpTableCollection::GetControl( VmbInt64_t nIndex )
|
||||
{
|
||||
VimbaFeatureEnum LutSelector( m_pCamera, "LUTSelector" ); //< get enum feature for supported LUTs
|
||||
StringVector Values = LutSelector.GetValues(); //< get list of supported LUTs
|
||||
if( static_cast<size_t>(nIndex) >= Values.size() ) //< test index for out of range
|
||||
{
|
||||
throw Exception( __FUNCTION__,"selected index out of range",VmbErrorBadParameter );
|
||||
}
|
||||
std::string SelectedValue = Values[ static_cast<size_t>( nIndex ) ];
|
||||
if( !LutSelector.IsAvailable( SelectedValue ) )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"selected LUT is not available", VmbErrorBadParameter );
|
||||
}
|
||||
LutSelector.SetStringValue( SelectedValue ); //< activate the LUT at nIndex
|
||||
|
||||
return m_tables[ static_cast<size_t>( nIndex ) ]; //< get stored LUT control
|
||||
}
|
||||
|
||||
//Get look up table active index
|
||||
VmbInt64_t LookUpTableCollection::GetActiveIndex( )
|
||||
{
|
||||
VimbaFeatureEnum LutSelector( m_pCamera, "LUTSelector" ); //< get enum feture for supported luts
|
||||
const StringVector SupportedLuts = LutSelector.GetValues(); //< get list of supported LUTs
|
||||
std::string CurrentLut = LutSelector.GetStringValue( ); //< get the currently selected LUT
|
||||
StringVector::const_iterator find_pos = std::find( SupportedLuts.begin(), SupportedLuts.end(), CurrentLut );//< find current vallue in list
|
||||
if( SupportedLuts.end() == find_pos )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not find current selected lut index",VmbErrorNotFound );
|
||||
}
|
||||
return std::distance( SupportedLuts.begin(), find_pos );
|
||||
}
|
||||
|
||||
LookUpTableControl::LookUpTableControl( CameraPtr pCamera, VmbInt64_t nIndex )
|
||||
: m_pCamera( pCamera )
|
||||
, m_nIndex( nIndex )
|
||||
|
||||
{
|
||||
//Check parameters
|
||||
if( NULL == m_pCamera )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"LookUpTableControl failed.", VmbErrorBadParameter );
|
||||
}
|
||||
}
|
||||
|
||||
//Enable look up table
|
||||
void LookUpTableControl::Enable( VmbBool_t bEnable )
|
||||
{
|
||||
VimbaFeatureBool LutEnable( m_pCamera, "LUTEnable" ); //< create bool feature for lut enable
|
||||
LutEnable( bEnable ); //< set state to feature
|
||||
}
|
||||
|
||||
//Is look up table enabled
|
||||
VmbBool_t LookUpTableControl::IsEnabled( ) const
|
||||
{
|
||||
VimbaFeatureBool LutEnable( m_pCamera,"LUTEnable" ); //< create bool feature for Lut enable
|
||||
return LutEnable(); //< return current value
|
||||
}
|
||||
|
||||
//Get look up table index
|
||||
VmbInt64_t LookUpTableControl::GetIndex( ) const
|
||||
{
|
||||
VimbaFeatureInt LutIndex( m_pCamera, "LUTIndex" ); //< get feature for LUT index
|
||||
return LutIndex(); // return current index
|
||||
}
|
||||
|
||||
//Get value count
|
||||
VmbInt64_t LookUpTableControl::GetValueCount( ) const
|
||||
{
|
||||
VimbaFeatureInt LutSize ( m_pCamera,"LUTSize"); //< get feature for LUT size in bytes
|
||||
VimbaFeatureInt LutBitDepthOut ( m_pCamera, "LUTBitDepthOut"); //< get feature for output bits per lut values
|
||||
VmbInt64_t nLUTBytePerValue = LutBitDepthOut() > 8 ? 2 : 1; //< calculate bytes used its either 2 bytes if larger than 8bits or 1 byte
|
||||
|
||||
return LutSize() / nLUTBytePerValue; //< lut are elements without padding consecutive in memory
|
||||
}
|
||||
|
||||
//Get look up table value
|
||||
VmbInt64_t LookUpTableControl::GetValue( ) const
|
||||
{
|
||||
VimbaFeatureInt LutValue( m_pCamera, "LUTValue" ); //< get feature for lUT element value this depends on LUTIndex
|
||||
return LutValue(); //< return current value
|
||||
}
|
||||
|
||||
//Set look up table value
|
||||
void LookUpTableControl::SetValue( VmbInt64_t nValue )
|
||||
{
|
||||
VimbaFeatureInt LutValue( m_pCamera,"LUTValue" ); //< get feature for LUT element value this depends on LUTIndex
|
||||
LutValue( nValue ); //< set new value
|
||||
}
|
||||
|
||||
|
||||
//Get bit depth in
|
||||
VmbInt64_t LookUpTableControl::GetBitDepthIn( ) const
|
||||
{
|
||||
VimbaFeatureInt LutBitDepthIn( m_pCamera, "LUTBitDepthIn" ); //< get feature for input bit depth of LUT
|
||||
return LutBitDepthIn(); //< return bit depth
|
||||
}
|
||||
|
||||
//Get bit depth out
|
||||
VmbInt64_t LookUpTableControl::GetBitDepthOut( ) const
|
||||
{
|
||||
VimbaFeatureInt LutBitDepthOut( m_pCamera,"LUTBitDepthOut" ); //< get feature for output bit depth of LUT
|
||||
return LutBitDepthOut(); // return bit dept
|
||||
}
|
||||
|
||||
|
||||
//Download look up table
|
||||
void LookUpTableControl::Download()
|
||||
{
|
||||
// if any kind of LUT is implemented we should find the LUTSelector feature
|
||||
if( VmbBoolTrue != VimbaFeature::HasFeature( m_pCamera,"LUTSelector" ) )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"no LUT feature implemented",VmbErrorNotFound );
|
||||
}
|
||||
// try reading LUT with FileAccess
|
||||
if( VmbBoolTrue == VimbaFeature::HasFeature( m_pCamera, "FileSelector" ) )
|
||||
{
|
||||
VimbaFeatureEnum LutSelector ( m_pCamera, "LUTSelector"); //< selector feature for lookup table
|
||||
VimbaFeatureEnum FileSelector( m_pCamera, "FileSelector"); //< file selector
|
||||
VimbaFeatureEnum FileOpenMode( m_pCamera, "FileOpenMode"); //< selector for file open mode
|
||||
FileSelector.SetStringValue ( std::string("LUT") + LutSelector.GetStringValue()); //< get the lookup table name and set it to file selector
|
||||
|
||||
if( VmbBoolTrue != FileOpenMode.IsAvailable( "Read" ) ) //< test if LUT feature is readable, Firewire does not support LUT read
|
||||
{
|
||||
throw Exception( __FUNCTION__,"camera does not support LUT download to host computer", VmbErrorNotSupported );
|
||||
}
|
||||
FileOpenMode.SetStringValue( "Read" ); //< set the open mode to read
|
||||
|
||||
VimbaFeatureInt LutSize( m_pCamera,"LUTSizeBytes" ); //< integer feature for bytes of lookup table
|
||||
m_data.resize( static_cast<size_t>( LutSize() ) ); //< get the bytes
|
||||
|
||||
VimbaFeatureEnum FileOperationSelector ( m_pCamera, "FileOperationSelector"); //< file operation selector to selector the file command
|
||||
VimbaFeatureCommand FileOperationExecute ( m_pCamera, "FileOperationExecute"); //< file operation command executer
|
||||
VimbaFeatureRaw FileAccessBuffer ( m_pCamera, "FileAccessBuffer"); //< raw data feature to access file buffer
|
||||
VimbaFeatureInt FileAccessOffset ( m_pCamera, "FileAccessOffset"); //< integer feature to get the data offset into the buffer
|
||||
VimbaFeatureInt FileAccessLength ( m_pCamera, "FileAccessLength"); //< integer feature for length of file access
|
||||
VimbaFeatureEnum FileOperationStatus ( m_pCamera, "FileOperationStatus"); //< enumeration value for state of file operation
|
||||
VimbaFeatureInt FileOperationResult ( m_pCamera, "FileOperationResult"); //< integer for file operation result
|
||||
VimbaFeatureEnum FileStatus ( m_pCamera, "FileStatus"); //< file state feature
|
||||
VimbaFeatureInt FileSize ( m_pCamera, "FileSize"); //< file size feature
|
||||
|
||||
|
||||
FileOperationSelector.SetStringValue( "Open" ); //< set open command for file access
|
||||
FileOperationExecute.Run(); //< execute command
|
||||
|
||||
//File size
|
||||
VmbInt64_t nFileSize = FileSize( ); //< get lut file size
|
||||
|
||||
|
||||
FileOperationSelector.SetStringValue( "Read" ); //< set file operation to read
|
||||
|
||||
VmbInt64_t nFileAccessOffset = 0; //< set start offset
|
||||
VmbInt64_t nFileAccessLength = min( LutSize(), FileAccessLength.Max() ); //< determine if we can read the lut in one go, or are limited by max access length
|
||||
UcharVector data( static_cast<size_t>( nFileAccessLength ) ); //< prepare the temporary data buffer
|
||||
|
||||
do
|
||||
{
|
||||
FileAccessLength( nFileAccessLength ); //< set the amount of data we want to read
|
||||
FileOperationExecute.Run(); //< commit the read request
|
||||
|
||||
|
||||
if( FileOperationStatus.GetStringValue( ) != "Success" ) //< test if read failed
|
||||
{
|
||||
throw Exception( __FUNCTION__,"reading LUT failed", VmbErrorOther );
|
||||
}
|
||||
|
||||
FileAccessBuffer.GetBuffer( data ); //< if read succeeded we can read the raw buffer
|
||||
data = ConvertFromNetworkInt16( data );
|
||||
copy( data.begin(), data.end(), m_data.begin() + ( size_t )nFileAccessOffset ); //< copy it from temp storage to internal data buffer
|
||||
|
||||
nFileAccessOffset = FileAccessOffset( ); //< get the new file offset
|
||||
|
||||
nFileAccessLength = min( nFileSize - nFileAccessOffset, FileAccessLength.Max() ); //< get the next file length
|
||||
}
|
||||
while( nFileSize != nFileAccessOffset );
|
||||
|
||||
//Select close as file operation
|
||||
FileOperationSelector.SetStringValue( "Close" ); //< set file operation to close
|
||||
FileOperationExecute.Run(); //< commit the close operation
|
||||
|
||||
if( FileOperationStatus.GetStringValue() != "Success" ) //< test if close succeeded
|
||||
{
|
||||
throw Exception( __FUNCTION__,"lut file operation failed", VmbErrorOther );
|
||||
}
|
||||
}
|
||||
// try reading LUT address for GigE (indicator for direct memory access)
|
||||
else if( VmbBoolTrue == VimbaFeature::HasFeature( m_pCamera, "LUTAddress" ) )
|
||||
{
|
||||
VimbaFeatureInt LutSize( m_pCamera,"LUTSizeBytes" ); //< get feature for lut byte size
|
||||
m_data.resize( static_cast<size_t>( LutSize() ) ); //< prepare storage for LUT data
|
||||
|
||||
VimbaFeatureInt LutAddress (m_pCamera, "LUTAddress"); //< try to get the LUT address feature
|
||||
VmbInt64_t nLUTAddress = LutAddress(); //< store address
|
||||
VmbUint32_t nCompletedReads = 0;
|
||||
VmbErrorType err = m_pCamera->ReadMemory( nLUTAddress, m_data, nCompletedReads );
|
||||
if( VmbErrorSuccess != err )
|
||||
{
|
||||
throw Exception( __FUNCTION__,": could not read memory from camera",err );
|
||||
}
|
||||
m_data = ConvertFromNetworkInt16( m_data );
|
||||
}
|
||||
// if non of the buffer read features are available try to read it value by value
|
||||
else
|
||||
{
|
||||
VimbaFeatureInt LUTIndex( m_pCamera, "LUTIndex" ); //< get the LUTIndex feature to control the index of the current value
|
||||
VimbaFeatureInt LUTValue( m_pCamera, "LUTValue" ); //< get the LUTValue feature to access the current value
|
||||
VimbaFeatureInt LutSize ( m_pCamera, "LUTSizeBytes" ); //< get the LUTSizeBytes feature to get LUT size info
|
||||
|
||||
m_data.resize( static_cast<size_t>( LutSize() ) ); //< resize storage for LUT data
|
||||
|
||||
VmbInt64_t nLUTBitDepthOut = GetBitDepthOut( ); //< get bits per LUT value needed
|
||||
|
||||
//Evaluate number of LUT entries
|
||||
VmbInt64_t nLUTBytePerValue = ( nLUTBitDepthOut > 8 ) ? 2 : 1; //< determine what size the LUT values occupy
|
||||
VmbInt64_t nLUTEntries = LutSize() / nLUTBytePerValue; //< entries are stored consecutive without padding
|
||||
|
||||
//Get LUT values by iteration over indexes
|
||||
int iter = 0;
|
||||
for( VmbInt64_t i = 0; i < nLUTEntries ; i++ )
|
||||
{
|
||||
LUTIndex( i ); //< set index
|
||||
VmbInt64_t nValue = LUTValue( ); //< get current value
|
||||
switch( nLUTBytePerValue )
|
||||
{
|
||||
case 1:
|
||||
m_data[iter++] = static_cast<VmbUint8_t>( nValue );
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
VmbUint16_t * p = (VmbUint16_t*)( &m_data[iter] );
|
||||
*p = static_cast<VmbUint16_t>( nValue );
|
||||
iter +=2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Upload look up table
|
||||
void LookUpTableControl::Upload()
|
||||
{
|
||||
//Look up table raw data empty
|
||||
if( m_data.empty() )
|
||||
{
|
||||
throw Exception( __FUNCTION__,": lut data vector is empty", VmbErrorOther );
|
||||
}
|
||||
|
||||
if( VmbBoolTrue == VimbaFeature::HasFeature( m_pCamera, "FileSelector" ) )
|
||||
{
|
||||
|
||||
//Evaluate size of LUT
|
||||
VimbaFeatureInt LUTSize ( m_pCamera, "LUTSizeBytes");
|
||||
//file access control
|
||||
VimbaFeatureEnum FileOperationSelector ( m_pCamera, "FileOperationSelector");
|
||||
VimbaFeatureCommand FileOperationExecute ( m_pCamera, "FileOperationExecute" );
|
||||
VimbaFeatureEnum FileOpenMode ( m_pCamera, "FileOpenMode" );
|
||||
VimbaFeatureRaw FileAccessBuffer ( m_pCamera, "FileAccessBuffer" );
|
||||
VimbaFeatureInt FileAccessOffset ( m_pCamera, "FileAccessOffset" );
|
||||
VimbaFeatureInt FileAccessLength ( m_pCamera, "FileAccessLength" );
|
||||
VimbaFeatureEnum FileOperationStatus ( m_pCamera, "FileOperationStatus" );
|
||||
|
||||
VimbaFeatureInt FileOperationResult ( m_pCamera, "FileOperationResult" );
|
||||
VimbaFeatureEnum FileStatus ( m_pCamera, "FileStatus" );
|
||||
VimbaFeatureInt FileSize ( m_pCamera, "FileSize" );
|
||||
VimbaFeatureEnum FileSelector ( m_pCamera, "FileSelector" );
|
||||
VimbaFeatureEnum LUTSelector ( m_pCamera, "LUTSelector" );
|
||||
|
||||
FileSelector.SetStringValue( std::string( "LUT" )+LUTSelector.GetStringValue() );
|
||||
if( FileOpenMode.IsAvailable( "Write" ) )
|
||||
{
|
||||
FileOpenMode.SetStringValue( "Write" );
|
||||
FileOperationSelector.SetStringValue( "Open" );
|
||||
FileOperationExecute.Run();
|
||||
VmbInt64_t nFileSize = FileSize( );
|
||||
if( m_data.size() != nFileSize )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"LUT to upload does not seam to have the correct size for this camera",VmbErrorBadParameter );
|
||||
}
|
||||
//File access length
|
||||
VmbInt64_t nMaxFileAccessLength = FileAccessLength.Max( );
|
||||
FileOperationSelector.SetStringValue( "Write" );
|
||||
|
||||
VmbInt64_t nFileAccessOffset = 0;
|
||||
VmbInt64_t nFileAccessLength = min( nFileSize, nMaxFileAccessLength );
|
||||
UcharVector data( (size_t)nFileAccessLength );
|
||||
do
|
||||
{
|
||||
//Set FileAccessLength
|
||||
FileAccessLength( nFileAccessLength );
|
||||
//Fill buffer
|
||||
copy( &m_data[(size_t)nFileAccessOffset ], &m_data[(size_t)( nFileAccessLength+nFileAccessOffset-1 ) ], data.begin() );
|
||||
data = ConvertToNetworkInt16( data );
|
||||
FileAccessBuffer( data );
|
||||
//Execute file operation
|
||||
FileOperationExecute.Run( );
|
||||
//Get file operation status
|
||||
if( FileOperationStatus.GetStringValue() != "Success" )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"writing data failed",VmbErrorOther );
|
||||
}
|
||||
nFileAccessOffset =FileAccessOffset();
|
||||
|
||||
nFileAccessLength = min( nFileSize - nFileAccessOffset, nMaxFileAccessLength );
|
||||
}
|
||||
while( nFileSize != nFileAccessOffset );
|
||||
FileOperationSelector.SetStringValue( "Close" );
|
||||
FileOperationExecute.Run();
|
||||
//Get file operation status
|
||||
if( FileOperationStatus.GetStringValue() != "Success" )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not close file", VmbErrorOther );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( VmbBoolTrue == VimbaFeature::HasFeature( m_pCamera,"LUTIndex" ) )
|
||||
{
|
||||
//Get LUT address for GigE (indicator for direct memory access)
|
||||
VimbaFeatureInt LUTAddress( m_pCamera, "LUTAddress" ); //< get feature for lut address
|
||||
VmbUint32_t nCompletedWrites = 0;
|
||||
UcharVector network_data( ConvertToNetworkInt16( m_data ) ); //< expect our camera to be big endian device, so if we are intel little endian we have to swap
|
||||
m_pCamera->WriteMemory( LUTAddress() , network_data, nCompletedWrites ); //< write data direct to camera
|
||||
}
|
||||
//Camera doesn't support direct memory access for LUT
|
||||
else
|
||||
{
|
||||
//Used LUT index and value as indicator for GigE
|
||||
VimbaFeatureInt LUTIndex( m_pCamera, "LUTIndex" ); //< get lUT index feature to set current index
|
||||
VimbaFeatureInt LUTValue( m_pCamera, "LUTValue" ); //< get LUT value feature to set current value
|
||||
VimbaFeatureInt LUTSize ( m_pCamera, "LUTSizeBytes"); //< get feature for size of LUT in bytes
|
||||
if( m_data.size() != LUTSize() ) //< compare data size to LUT size
|
||||
{
|
||||
throw Exception( __FUNCTION__,"data size is not equal lut size, they are incompatible",VmbErrorBadParameter );
|
||||
}
|
||||
//Evaluate number of LUT entries
|
||||
VmbInt64_t nLUTBytePerValue = ( GetBitDepthOut() > 8 ) ? 2 : 1; //< determine if LUT values take one or two bytes
|
||||
VmbInt64_t nLUTEntries = LUTSize() / nLUTBytePerValue; //< calculate lement count, LUT values are unpadded and consecutive in memory
|
||||
//Set LUT values by iteration over indexes
|
||||
int iter( 0 );
|
||||
VmbInt64_t nValue( 0 );
|
||||
for( VmbInt64_t i = 0; i < nLUTEntries ; i++ )
|
||||
{
|
||||
LUTIndex( i ); //< set current index
|
||||
switch( nLUTBytePerValue )
|
||||
{
|
||||
case 1:
|
||||
nValue = m_data[iter++]; //< copy 8bit value
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
VmbUint16_t* p = (VmbUint16_t*)(&m_data[iter]); //< interpret data as host byte order uint 16
|
||||
nValue = *p;
|
||||
iter +=2;
|
||||
}
|
||||
}
|
||||
LUTValue( nValue ); //< write data to camera
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Load look up table from Csv
|
||||
void LookUpTableControl::LoadFromCsv( const std::string &FileName, int nIndex )
|
||||
{
|
||||
|
||||
//Evaluate size of LUT
|
||||
VmbInt64_t nLUTBitDepthOut = GetBitDepthOut( ); //< get output bit depth of LUT
|
||||
VmbInt64_t nLUTBytePerValue = nLUTBitDepthOut > 8 ? 2 : 1; //< determine if LUT values take one or two byte
|
||||
// Load LUT from CSV
|
||||
CsvLoad load( FileName ); //< import the LUT from CSV file
|
||||
std::vector<std::string> row;
|
||||
while( load.Row( row ) ) //< load rows until none left
|
||||
{
|
||||
if( row.size() <= ( size_t )nIndex ) //< test if index in range
|
||||
{
|
||||
throw Exception( __FUNCTION__,"index for the csv file is out of bounds",VmbErrorBadParameter );
|
||||
}
|
||||
|
||||
int nData; //< coonvert string to int
|
||||
std::stringstream ss( row[nIndex] );
|
||||
ss >> nData;
|
||||
|
||||
char data[2]; //< pack data for storage
|
||||
if( 2 == nLUTBytePerValue )
|
||||
{
|
||||
VmbUint16_t *p = ( VmbUint16_t* )( data );
|
||||
*p = static_cast<VmbUint16_t>( nData );
|
||||
}
|
||||
else
|
||||
{
|
||||
data[0] = static_cast<VmbUint8_t>( nData&0xFF );
|
||||
}
|
||||
|
||||
copy( data, data + nLUTBytePerValue, std::back_inserter( m_data ) ); //< append data to internal storage
|
||||
}
|
||||
}
|
||||
|
||||
//Save look up table to CSV
|
||||
void LookUpTableControl::SaveToCsv( const std::string &FileName )
|
||||
{
|
||||
|
||||
//Raw data empty
|
||||
if( m_data.empty() )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"no data to write to csv file", VmbErrorOther );
|
||||
}
|
||||
|
||||
//Evaluate size of LUT
|
||||
VimbaFeatureInt LUTSize( m_pCamera, "LUTSizeBytes" ); //< get feature for LUT size in bytes
|
||||
|
||||
VmbInt64_t nLUTBitDepthOut = GetBitDepthOut( ); //< get output bit depth of LUT
|
||||
VmbInt64_t nLUTBytePerValue = nLUTBitDepthOut > 8 ? 2 : 1; //< determine if LUT values take one or two bytes
|
||||
VmbInt64_t nLUTEntries = LUTSize()/nLUTBytePerValue; //< calculate LUT element count, LUT values are unpadded and consecutive
|
||||
if( m_data.size() != LUTSize() ) //< if lut size and data size miss match they are not compatible
|
||||
{
|
||||
throw Exception( __FUNCTION__,"data does not equal the current cameras LUT",VmbErrorBadParameter );
|
||||
}
|
||||
// Save LUT data to CSV
|
||||
|
||||
CsvSave save( FileName ); //< create CSV file
|
||||
{
|
||||
for( int i = 0; i < nLUTEntries; i++ ) //< for each LUT value
|
||||
{
|
||||
int data ; //< unpack data to int
|
||||
if( 2 == nLUTBytePerValue )
|
||||
{
|
||||
data = *( ( VmbUint16_t* )( &m_data[i*2] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
data = m_data[i];
|
||||
}
|
||||
stringstream ss; //< stream int to string
|
||||
ss << data;
|
||||
save.Row( ss.str() ); //< write a csv row
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Load look up table from flash
|
||||
void LookUpTableControl::LoadFromFlash()
|
||||
{
|
||||
VimbaFeatureCommand LUTLoad = CreateOneOf<VimbaFeatureCommand>( m_pCamera, "LUTLoad", "LUTLoadAll" ); // there are two possible names for this feature
|
||||
LUTLoad.Run();
|
||||
}
|
||||
|
||||
//Save look up table to flash
|
||||
void LookUpTableControl::SaveToFlash()
|
||||
{
|
||||
VimbaFeatureCommand LUTSave = CreateOneOf<VimbaFeatureCommand>( m_pCamera, "LUTSave", "LUTSaveAll" ); //< there are two possible names for this feature
|
||||
LUTSave.Run();
|
||||
}
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
120
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/LookUpTable.h
Normal file
120
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/LookUpTable.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/*=============================================================================
|
||||
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: LookUpTable.h
|
||||
|
||||
Description: The LookUpTable example will demonstrate how to use
|
||||
the look up table feature of the 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_EXAMPLES_LOOKUPTABLE
|
||||
#define AVT_VMBAPI_EXAMPLES_LOOKUPTABLE
|
||||
|
||||
#include "VimbaCPP/Include/VimbaCPP.h"
|
||||
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class LookUpTableControl
|
||||
{
|
||||
private:
|
||||
CameraPtr m_pCamera;
|
||||
VmbInt64_t m_nIndex;
|
||||
UcharVector m_data;
|
||||
|
||||
public:
|
||||
//ctor
|
||||
LookUpTableControl( CameraPtr pCamera, VmbInt64_t nIndex );
|
||||
|
||||
//Enable
|
||||
void Enable( VmbBool_t bEnable );
|
||||
|
||||
//Is enabled
|
||||
VmbBool_t IsEnabled() const;
|
||||
|
||||
//Get index
|
||||
VmbInt64_t GetIndex( ) const;
|
||||
|
||||
//Get value count
|
||||
VmbInt64_t GetValueCount( ) const;
|
||||
|
||||
//Get Value
|
||||
VmbInt64_t GetValue( ) const;
|
||||
|
||||
//Set Value
|
||||
void SetValue( VmbInt64_t nValue );
|
||||
|
||||
//Get bit depth in
|
||||
VmbInt64_t GetBitDepthIn( ) const;
|
||||
|
||||
//Get bit depth out
|
||||
VmbInt64_t GetBitDepthOut( ) const;
|
||||
|
||||
//Download look up table from internal memory into the camera
|
||||
void Download();
|
||||
|
||||
//Upload the selected look up table into internal memory of the camera
|
||||
void Upload();
|
||||
|
||||
|
||||
//Load from Csv
|
||||
void LoadFromCsv( const std::string &FileName, int nIndex );
|
||||
|
||||
//Save to Csv
|
||||
void SaveToCsv( const std::string &FileName );
|
||||
|
||||
//Load from flash
|
||||
void LoadFromFlash();
|
||||
|
||||
//Save to flash
|
||||
void SaveToFlash();
|
||||
};
|
||||
|
||||
class LookUpTableCollection
|
||||
{
|
||||
private:
|
||||
CameraPtr m_pCamera;
|
||||
std::vector<LookUpTableControl> m_tables;
|
||||
|
||||
public:
|
||||
//ctor
|
||||
LookUpTableCollection( CameraPtr pCamera );
|
||||
|
||||
// test for Lookup table support
|
||||
static bool HasLookUpTable( CameraPtr pCamera);
|
||||
|
||||
//Get count
|
||||
VmbInt64_t GetCount( );
|
||||
|
||||
// Get control
|
||||
LookUpTableControl GetControl( VmbInt64_t nIndex );
|
||||
|
||||
//Get active index
|
||||
VmbInt64_t GetActiveIndex( );
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
849
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/VimbaFeatures.h
Normal file
849
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/VimbaFeatures.h
Normal file
@@ -0,0 +1,849 @@
|
||||
#ifndef AVT_VIMBA_FEATURES_H_
|
||||
#define AVT_VIMBA_FEATURES_H_
|
||||
/*=============================================================================
|
||||
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: VimbaFeatures.h
|
||||
|
||||
Description: Helper for features.
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
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 <vector>
|
||||
|
||||
#include "Exception.h"
|
||||
#include "VimbaCPP/Include/VimbaCPP.h"
|
||||
|
||||
namespace AVT{
|
||||
namespace VmbAPI{
|
||||
namespace Examples{
|
||||
|
||||
using AVT::VmbAPI::StringVector;
|
||||
//
|
||||
// basic feature.
|
||||
//
|
||||
class VimbaFeature
|
||||
{
|
||||
FeaturePtr m_Feature;
|
||||
public:
|
||||
|
||||
//
|
||||
// Method: VimbaFeature
|
||||
//
|
||||
// Purpose: constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature to wrap
|
||||
//
|
||||
VimbaFeature(const FeaturePtr &feature)
|
||||
: m_Feature( feature )
|
||||
{ }
|
||||
//
|
||||
// Method: VimbaFeature
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name name of the feature
|
||||
//
|
||||
VimbaFeature(const CameraPtr &cam, const std::string &name)
|
||||
{
|
||||
if( cam.get() == NULL )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"camera pointer is null",VmbErrorBadParameter);
|
||||
}
|
||||
VmbErrorType Result = cam->GetFeatureByName( name.c_str() , m_Feature);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__,std::string("could not get vimba feature :")+name, Result);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: GetType
|
||||
//
|
||||
// Purpose: get feature data type.
|
||||
//
|
||||
VmbFeatureDataType GetType() const
|
||||
{
|
||||
VmbFeatureDataType DataType;
|
||||
VmbErrorType Result = m_Feature->GetDataType( DataType);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__, "could not get feature data type", Result);
|
||||
}
|
||||
return DataType;
|
||||
}
|
||||
//
|
||||
// Method: HasFeature
|
||||
//
|
||||
// Purpose: static test if a feature is implemented.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to ask
|
||||
// param[in] name feature name
|
||||
//
|
||||
static VmbBool_t HasFeature( const CameraPtr &cam, const std::string &name)
|
||||
{
|
||||
if( cam.get() == NULL )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"camera pointer is null",VmbErrorBadParameter);
|
||||
}
|
||||
FeaturePtr dummy;
|
||||
VmbErrorType Result = cam->GetFeatureByName(name.c_str(), dummy);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
if( VmbErrorNotFound == Result)
|
||||
{
|
||||
return VmbBoolFalse;
|
||||
}
|
||||
throw Exception(__FUNCTION__,"could not get feature",Result);
|
||||
}
|
||||
return VmbBoolTrue;
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose : get the const feature pointer.
|
||||
//
|
||||
const FeaturePtr& operator()() const { return m_Feature; }
|
||||
//
|
||||
// Method: operator()
|
||||
//
|
||||
// Purpose:get the feature pointer.
|
||||
//
|
||||
FeaturePtr& operator()() { return m_Feature; }
|
||||
};
|
||||
//
|
||||
// integer feature
|
||||
//
|
||||
class VimbaFeatureInt
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureInt
|
||||
//
|
||||
// Purpose: constructor from feature pointer.
|
||||
// [in] feature feature pointer
|
||||
//
|
||||
VimbaFeatureInt(const FeaturePtr &feature)
|
||||
: m_Feature( feature)
|
||||
{
|
||||
if( VmbFeatureDataInt != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureInt
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name feature name
|
||||
//
|
||||
VimbaFeatureInt(const CameraPtr &cam, const std::string &name)
|
||||
: m_Feature( cam, name)
|
||||
{
|
||||
if( VmbFeatureDataInt != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose: get feature int value.
|
||||
//
|
||||
VmbInt64_t operator()() const
|
||||
{
|
||||
VmbInt64_t Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get value for feature", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: operator( VmbInt64_t)
|
||||
//
|
||||
// Purpose: set feature int value.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] Value value to set
|
||||
//
|
||||
void operator()( VmbInt64_t Value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set feature value", Result);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: Min
|
||||
//
|
||||
// Purpose: get feature minimum value.
|
||||
//
|
||||
VmbInt64_t Min() const
|
||||
{
|
||||
VmbInt64_t MinValue,MaxValue;
|
||||
VmbErrorType Result = m_Feature()->GetRange(MinValue,MaxValue);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get integer feature range",Result);
|
||||
}
|
||||
return MinValue;
|
||||
}
|
||||
//
|
||||
// Method: Max
|
||||
//
|
||||
// Purpose: get feature maximum value.
|
||||
//
|
||||
VmbInt64_t Max() const
|
||||
{
|
||||
VmbInt64_t MinValue,MaxValue;
|
||||
VmbErrorType Result = m_Feature()->GetRange(MinValue,MaxValue);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get integer feature range",Result);
|
||||
}
|
||||
return MaxValue;
|
||||
}
|
||||
//
|
||||
// Method: Increment()
|
||||
//
|
||||
// Purpose: get the increment to advance an integer feature
|
||||
// Value = Min() + n * Increment() <= Max()
|
||||
//
|
||||
VmbInt64_t Increment() const
|
||||
{
|
||||
VmbInt64_t IncValue;
|
||||
VmbErrorType Result = m_Feature()->GetIncrement( IncValue );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get integer feature increment",Result);
|
||||
}
|
||||
return IncValue;
|
||||
}
|
||||
};
|
||||
//
|
||||
// Vimba bool feature.
|
||||
//
|
||||
class VimbaFeatureBool
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureBool
|
||||
//
|
||||
// Purpose:constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature pointer
|
||||
//
|
||||
VimbaFeatureBool(const FeaturePtr &feature)
|
||||
: m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataBool != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureBool
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name name of the feature
|
||||
//
|
||||
VimbaFeatureBool(const CameraPtr &cam, const std::string &name)
|
||||
: m_Feature( cam, name)
|
||||
{
|
||||
if( VmbFeatureDataBool != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose: get feature bool value.
|
||||
//
|
||||
VmbBool_t operator()() const
|
||||
{
|
||||
VmbBool_t Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get value for feature", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: operator()
|
||||
//
|
||||
// Purpose: set feature bool value.
|
||||
//
|
||||
void operator()( VmbBool_t Value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set feature value", Result);
|
||||
}
|
||||
}
|
||||
};
|
||||
//
|
||||
// Vimba float feature
|
||||
//
|
||||
class VimbaFeatureFloat
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureFloat
|
||||
//
|
||||
// Purpose:constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature pointer
|
||||
//
|
||||
VimbaFeatureFloat(const FeaturePtr &feature)
|
||||
: m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataFloat != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureFloat
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name name of the feature
|
||||
//
|
||||
VimbaFeatureFloat(const CameraPtr &cam, const std::string &name)
|
||||
: m_Feature( cam, name)
|
||||
{
|
||||
if( VmbFeatureDataFloat != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose: get feature float value.
|
||||
//
|
||||
double operator()() const
|
||||
{
|
||||
double Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get value for feature", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: operator()
|
||||
//
|
||||
// Purpose: set feature float value.
|
||||
//
|
||||
void operator()( double Value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set feature value", Result);
|
||||
}
|
||||
}
|
||||
double Min() const
|
||||
{
|
||||
double MinValue, MaxValue;
|
||||
VmbErrorType Result = m_Feature()->GetRange( MinValue, MaxValue );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not get range for float feature", Result );
|
||||
}
|
||||
return MinValue;
|
||||
}
|
||||
double Max() const
|
||||
{
|
||||
double MinValue, MaxValue;
|
||||
VmbErrorType Result = m_Feature()->GetRange( MinValue, MaxValue );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not get range for float feature", Result );
|
||||
}
|
||||
return MaxValue;
|
||||
}
|
||||
};
|
||||
//
|
||||
// feature enum.
|
||||
//
|
||||
class VimbaFeatureEnum
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureEnum()
|
||||
//
|
||||
// Purpose: constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature pointer
|
||||
//
|
||||
VimbaFeatureEnum(const FeaturePtr &feature)
|
||||
: m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataEnum != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureEnum
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name feature name
|
||||
//
|
||||
VimbaFeatureEnum(const CameraPtr &cam, const std::string &name)
|
||||
: m_Feature( cam, name )
|
||||
{
|
||||
if( VmbFeatureDataEnum != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Methods: GetValues
|
||||
//
|
||||
// Purpose:get all supported feature value strings.
|
||||
//
|
||||
AVT::VmbAPI::StringVector GetValues() const
|
||||
{
|
||||
StringVector Values;
|
||||
VmbErrorType Result = m_Feature()->GetValues( Values );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not get values",Result);
|
||||
}
|
||||
return Values;
|
||||
}
|
||||
//
|
||||
// Method: GetEntries
|
||||
//
|
||||
// Purpose: get enum entries
|
||||
//
|
||||
EnumEntryVector GetEntries( ) const
|
||||
{
|
||||
EnumEntryVector Values;
|
||||
VmbErrorType Result = m_Feature()->GetEntries( Values) ;
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__, "could not get entry values for enum feature", Result);
|
||||
}
|
||||
return Values;
|
||||
}
|
||||
//
|
||||
// Method: ValueCount
|
||||
//
|
||||
// Purpose: get number of supported feature values.
|
||||
//
|
||||
VmbInt64_t ValueCount() const
|
||||
{
|
||||
return static_cast< VmbInt64_t>( GetValues().size() );
|
||||
}
|
||||
//
|
||||
// Method: IsAvailable
|
||||
//
|
||||
// Purpose: test if string value is currently available.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] Value string value to test
|
||||
//
|
||||
VmbBool_t IsAvailable( const std::string &Value)
|
||||
{
|
||||
VmbBool_t Available;
|
||||
VmbErrorType Result = m_Feature()->IsValueAvailable( Value.c_str(), Available );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not read enums available flag",Result);
|
||||
}
|
||||
return Available;
|
||||
}
|
||||
//
|
||||
// Method: IsAvailable
|
||||
//
|
||||
// Purpose: test if integer feature value is available.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] Value integer feature value to test
|
||||
//
|
||||
VmbBool_t IsAvailable( VmbInt64_t Value)
|
||||
{
|
||||
VmbBool_t Available;
|
||||
VmbErrorType Result = m_Feature()->IsValueAvailable( Value, Available );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not read enums available flag",Result);
|
||||
}
|
||||
return Available;
|
||||
}
|
||||
//
|
||||
// Method: GetStringValue
|
||||
//
|
||||
// Purpose:get current feature value as string.
|
||||
//
|
||||
std::string GetStringValue() const
|
||||
{
|
||||
std::string Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get string value", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: SetStringValue
|
||||
//
|
||||
// Purpose: set new feature value from string.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] Value string value to set
|
||||
//
|
||||
void SetStringValue( const std::string &Value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( Value.c_str() );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set string value",Result);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: GetEntry
|
||||
//
|
||||
// Purpose: get current enum value as EnumEntry
|
||||
//
|
||||
EnumEntry GetEntry() const
|
||||
{
|
||||
EnumEntry Value;
|
||||
VmbErrorType Result = m_Feature()->GetEntry( Value, GetStringValue().c_str() );
|
||||
if( VmbErrorSuccess != Result )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not get enum feature entry", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose: get current integer value.
|
||||
//
|
||||
VmbInt64_t operator()() const
|
||||
{
|
||||
VmbInt64_t Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get value for feature", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
//
|
||||
// Method: operator()
|
||||
//
|
||||
// Purpose: set new integer value.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] Value new value to set
|
||||
//
|
||||
void operator()( VmbInt64_t Value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( Value );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set feature value", Result);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Vimba string feature
|
||||
class VimbaFeatureString
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
VimbaFeatureString( const FeaturePtr & feature)
|
||||
: m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataString != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"wrong feature data type", VmbErrorWrongType );
|
||||
}
|
||||
}
|
||||
VimbaFeatureString( const CameraPtr & cam, const std::string &name)
|
||||
:m_Feature( cam, name )
|
||||
{
|
||||
if( VmbFeatureDataString != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"wrong feature data type", VmbErrorWrongType );
|
||||
}
|
||||
}
|
||||
std::string operator()() const
|
||||
{
|
||||
std::string Value;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Value );
|
||||
if( VmbErrorSuccess != Result )
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not get value for string feature", Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
void operator()( const std::string & value)
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->SetValue( value.c_str() );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception( __FUNCTION__,"could not set string feature value" , Result );
|
||||
}
|
||||
}
|
||||
};
|
||||
//
|
||||
// feature command
|
||||
//
|
||||
class VimbaFeatureCommand
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureCommand
|
||||
//
|
||||
// Purpose: constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature pointer to use
|
||||
//
|
||||
VimbaFeatureCommand( const FeaturePtr &feature)
|
||||
:m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataCommand != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureCommand
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name name of the feature
|
||||
//
|
||||
VimbaFeatureCommand( const CameraPtr &cam, const std::string &name)
|
||||
:m_Feature( cam, name)
|
||||
{
|
||||
if( VmbFeatureDataCommand != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: Run
|
||||
//
|
||||
// Purpose: run command.
|
||||
//
|
||||
void Run()
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->RunCommand();
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not run feature command",Result);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: IsDone
|
||||
//
|
||||
// Purpose:test if command has finished.
|
||||
//
|
||||
VmbBool_t IsDone() const
|
||||
{
|
||||
VmbBool_t Value;
|
||||
VmbErrorType Result = m_Feature()->IsCommandDone( Value);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not get is done state of feature command",Result);
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
};
|
||||
//
|
||||
// raw buffer feature.
|
||||
//
|
||||
class VimbaFeatureRaw
|
||||
{
|
||||
VimbaFeature m_Feature;
|
||||
public:
|
||||
//
|
||||
// Method: VimbaFeatureRaw
|
||||
//
|
||||
// Purpose: constructor from feature pointer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] feature feature pointer to use
|
||||
//
|
||||
VimbaFeatureRaw( const FeaturePtr &feature)
|
||||
:m_Feature( feature )
|
||||
{
|
||||
if( VmbFeatureDataRaw != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: VimbaFeatureRaw
|
||||
//
|
||||
// Purpose: constructor from camera and feature name.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name feature name
|
||||
//
|
||||
VimbaFeatureRaw( const CameraPtr &cam, const std::string &name)
|
||||
:m_Feature( cam, name)
|
||||
{
|
||||
if( VmbFeatureDataRaw != m_Feature.GetType() )
|
||||
{
|
||||
throw Exception(__FUNCTION__,"wrong feature data type", VmbErrorWrongType);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: GetBuffer
|
||||
//
|
||||
// Purpose: get raw buffer, reuses supplied data vector .
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [out] data returns read data
|
||||
//
|
||||
void GetBuffer( UcharVector &data) const
|
||||
{
|
||||
VmbErrorType Result = m_Feature()->GetValue( data );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not read raw data feature",Result);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Method: operator() const
|
||||
//
|
||||
// Purpose: get raw data buffer.
|
||||
//
|
||||
UcharVector operator()() const
|
||||
{
|
||||
UcharVector Data;
|
||||
VmbErrorType Result = m_Feature()->GetValue( Data );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not read raw data feature",Result);
|
||||
}
|
||||
return Data;
|
||||
}
|
||||
//
|
||||
// Method: operator( UcharVector )
|
||||
//
|
||||
// Purpose: set raw data buffer.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// [in] data data to set
|
||||
//
|
||||
void operator()( const UcharVector & Data)
|
||||
{
|
||||
VmbErrorType Result =m_Feature()->SetValue( Data );
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
throw Exception(__FUNCTION__,"could not set raw feature data",Result);
|
||||
}
|
||||
}
|
||||
};
|
||||
//
|
||||
// Method: CreateOneOf
|
||||
//
|
||||
// Purpose: create a feature from two possible names.
|
||||
// Parameters:
|
||||
//
|
||||
// [in] cam camera to get feature from
|
||||
// [in] name_one first name to try
|
||||
// [in] name_two second name to try
|
||||
//
|
||||
template <typename FEATURE_TYPE>
|
||||
FEATURE_TYPE CreateOneOf(const CameraPtr &cam, const std::string& name_one, const std::string &name_two)
|
||||
{
|
||||
FeaturePtr feature;
|
||||
VmbErrorType Result = cam->GetFeatureByName( name_one.c_str(), feature);
|
||||
if( VmbErrorSuccess != Result)
|
||||
{
|
||||
if( VmbErrorNotFound == Result)
|
||||
{
|
||||
return FEATURE_TYPE( cam, name_two);
|
||||
}
|
||||
throw Exception(__FUNCTION__,"could not generate feature",Result);
|
||||
}
|
||||
return FEATURE_TYPE(feature);
|
||||
}
|
||||
}}}
|
||||
#endif
|
||||
639
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/program.cpp
Normal file
639
Vimba_6_0/VimbaCPP/Examples/LookUpTable/Source/program.cpp
Normal file
@@ -0,0 +1,639 @@
|
||||
/*=============================================================================
|
||||
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 LookUpTable 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 <cstring>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "LookUpTable.h"
|
||||
#include "Exception.h"
|
||||
|
||||
#include "Common/StreamSystemInfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum Mode
|
||||
{
|
||||
ModeUnknown = 0,
|
||||
ModeSave = 1,
|
||||
ModeLoad = 2,
|
||||
ModeSaveCSV = 3,
|
||||
ModeLoadCSV = 4,
|
||||
ModeEnable = 7,
|
||||
ModeIsEnabled = 8,
|
||||
ModeSetValue = 9,
|
||||
ModeGetValue = 10,
|
||||
ModeBitIn = 11,
|
||||
ModeBitOut = 12,
|
||||
ModeCount = 13
|
||||
};
|
||||
|
||||
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[] )
|
||||
{
|
||||
cout << "///////////////////////////////////////\n";
|
||||
cout << "/// Vimba API Look Up Table Example ///\n";
|
||||
cout << "///////////////////////////////////////\n\n";
|
||||
|
||||
VmbErrorType err = VmbErrorSuccess;
|
||||
|
||||
string cameraID;
|
||||
string fileName;
|
||||
string controlIndex;
|
||||
bool bValue = false;
|
||||
VmbInt64_t nValue = 0;
|
||||
string parameter;
|
||||
Mode eMode = ModeUnknown;
|
||||
bool printHelp = false;
|
||||
|
||||
//////////////////////
|
||||
//Parse command line//
|
||||
//////////////////////
|
||||
|
||||
for( int i = 1; i < argc; i++ )
|
||||
{
|
||||
char *pParameter = argv[i];
|
||||
if( std::strlen( pParameter ) < 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( pParameter[0] == '/' )
|
||||
{
|
||||
if( std::strcmp( pParameter, "/s" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeSave;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/l" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeLoad;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/sc" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeSaveCSV;
|
||||
}
|
||||
else if( StartsWith( pParameter, "/lc:" ) )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( parameter.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
parameter = pParameter + 4;
|
||||
if( parameter.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
nValue = atoi( parameter.c_str() );
|
||||
|
||||
eMode = ModeLoadCSV;
|
||||
}
|
||||
else if( StartsWith( pParameter, "/lc" ) )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( parameter.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
nValue = 0;
|
||||
eMode = ModeLoadCSV;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/bi" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeBitIn;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/bo" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeBitOut;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/n" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeCount;
|
||||
}
|
||||
else if( StartsWith( pParameter, "/e:" ) )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( parameter.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
parameter = pParameter + 3;
|
||||
if( parameter.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( std::strcmp( parameter.c_str(), "on" ) == 0 )
|
||||
{
|
||||
bValue = true;
|
||||
}
|
||||
else if( std::strcmp( parameter.c_str(), "off" ) == 0 )
|
||||
{
|
||||
bValue = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Could not set look up table enable. Wrong parameter!\n";
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
eMode = ModeEnable;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/e" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeIsEnabled;
|
||||
}
|
||||
else if( StartsWith( pParameter, "/v:" ) )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( parameter.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
parameter = pParameter + 3;
|
||||
if( parameter.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
nValue = atoi( parameter.c_str() );
|
||||
|
||||
eMode = ModeSetValue;
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/v" ) == 0 )
|
||||
{
|
||||
if( ModeUnknown != eMode )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
eMode = ModeGetValue;
|
||||
}
|
||||
else if( StartsWith( pParameter, "/f:" ) )
|
||||
{
|
||||
if( (ModeUnknown != eMode) &&
|
||||
(ModeSaveCSV != eMode) &&
|
||||
(ModeLoadCSV != eMode) )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( fileName.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
fileName = pParameter + 3;
|
||||
if( fileName.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( StartsWith( pParameter, "/i:" ) )
|
||||
{
|
||||
if( controlIndex.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
controlIndex = pParameter + 3;
|
||||
if( controlIndex.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( std::strcmp( pParameter, "/h" ) == 0 )
|
||||
{
|
||||
if( (cameraID.empty() == false)
|
||||
|| (ModeUnknown != eMode)
|
||||
|| (true == printHelp))
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
printHelp = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cameraID.empty() == false )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
cameraID = pParameter;
|
||||
}
|
||||
}
|
||||
|
||||
//Write out an error if we could not parse the command line
|
||||
if( VmbErrorBadParameter == err )
|
||||
{
|
||||
cout << "Invalid parameters!\n\n";
|
||||
printHelp = true;
|
||||
}
|
||||
|
||||
//Print out help and end program
|
||||
if( true == printHelp )
|
||||
{
|
||||
cout << "Usage: LookUpTable [CameraID] [/i:Index] [/h] [/{s|l|sc|lc:Column|u|d|v(:Value)|e(:Enable)|bi|bo|n}] [/f:FileName]\n";
|
||||
cout << "Parameters: CameraID ID of the camera to use\n";
|
||||
cout << " (using first camera if not specified)\n";
|
||||
cout << " /i:Index Set look up table index\n";
|
||||
cout << " /h Print out help\n";
|
||||
cout << " /s Save look up table to flash\n";
|
||||
cout << " /l Load look up table from flash\n";
|
||||
cout << " /sc Save look up table to Csv\n";
|
||||
cout << " (Look up table previously downloaded)\n";
|
||||
cout << " /lc:Column Load look up table from Csv using specified column\n";
|
||||
cout << " (default if not specified)\n";
|
||||
cout << " /e:Enable Set look up table enable [on/off]\n";
|
||||
cout << " /e Get look up table enable\n";
|
||||
cout << " (default if not specified)\n";
|
||||
cout << " /v:Value Set look up table value\n";
|
||||
cout << " /v Get look up table value\n";
|
||||
cout << " /bi Get look up table bit depth in\n";
|
||||
cout << " /bo Get look up table bit depth out\n";
|
||||
cout << " /n Get look up table count\n";
|
||||
cout << " /f:FileName File name for operation\n\n";
|
||||
cout << "For example to load a look up table from the csv file C:\\lut.csv and\n"
|
||||
<< "write it to the camera's flash as LUT1 call\n\n";
|
||||
cout << "LookUpTable /i:0 /lc:0 /f:\"C:\\lut.csv\"\n\n";
|
||||
cout << "To load the look up table LUT2 from the camera and write it\n"
|
||||
<< "to the csv file C:\\lut.csv call\n\n";
|
||||
cout << "LookUpTable /i:1 /sc /f:\"C:\\lut.csv\"\n\n";
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
bool bVimbaStarted = false;
|
||||
AVT::VmbAPI::CameraPtr pCamera;
|
||||
AVT::VmbAPI::VimbaSystem& vimbaSystem = AVT::VmbAPI::VimbaSystem::GetInstance();
|
||||
|
||||
try
|
||||
{
|
||||
// Print out version of Vimba
|
||||
std::cout<<"Vimba C++ API Version "<<vimbaSystem<<"\n";
|
||||
|
||||
//Startup API
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
err = vimbaSystem.Startup();
|
||||
if( VmbErrorSuccess != err )
|
||||
{
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not start system.", err );
|
||||
}
|
||||
bVimbaStarted = true;
|
||||
}
|
||||
|
||||
//Open camera
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
if( cameraID.empty() )
|
||||
{
|
||||
//Open first available camera
|
||||
|
||||
//Fetch all cameras known to Vimba
|
||||
AVT::VmbAPI::CameraPtrVector cameras;
|
||||
err = vimbaSystem.GetCameras( cameras );
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
if( cameras.size() > 0 )
|
||||
{
|
||||
for( AVT::VmbAPI::CameraPtrVector::const_iterator iter = cameras.begin();
|
||||
cameras.end() != iter;
|
||||
++iter )
|
||||
{
|
||||
//Check if we can open the camera in full mode
|
||||
VmbAccessModeType eAccessMode = VmbAccessModeNone;
|
||||
err = (*iter)->GetPermittedAccess( eAccessMode );
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
if( (VmbAccessModeFull == (VmbAccessModeFull & eAccessMode)) ||
|
||||
((cameras.end() - 1) == iter) )
|
||||
{
|
||||
//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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( VmbErrorSuccess != err )
|
||||
{
|
||||
err = VmbErrorNotFound;
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not open any camera.", err );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = VmbErrorNotFound;
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not open any camera.", err );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not list cameras.", err );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Open specific camera
|
||||
err = vimbaSystem.OpenCameraByID( cameraID.c_str(), VmbAccessModeFull, pCamera );
|
||||
if( VmbErrorSuccess != err )
|
||||
{
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not open camera.", err );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
cout << "Camera ID: " << cameraID << "\n\n";
|
||||
if( VmbBoolTrue == AVT::VmbAPI::Examples::LookUpTableCollection::HasLookUpTable( pCamera) )
|
||||
{
|
||||
|
||||
AVT::VmbAPI::Examples::LookUpTableCollection collection( pCamera );
|
||||
|
||||
|
||||
VmbInt64_t nIndex;
|
||||
|
||||
if( controlIndex.empty() == false )
|
||||
{
|
||||
nIndex = atoi( controlIndex.c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
nIndex = collection.GetActiveIndex( );
|
||||
if( VmbErrorSuccess != err )
|
||||
{
|
||||
throw AVT::VmbAPI::Examples::Exception( "Could not get active index of look up table collection.", err );
|
||||
}
|
||||
}
|
||||
|
||||
AVT::VmbAPI::Examples::LookUpTableControl control( pCamera, nIndex );
|
||||
control = collection.GetControl( nIndex );
|
||||
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
switch( eMode )
|
||||
{
|
||||
default:
|
||||
case ModeIsEnabled:
|
||||
{
|
||||
//Is look up table enabled
|
||||
cout << "Get look up table enable was successful. Enable = " << control.IsEnabled( ) <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeLoad:
|
||||
{
|
||||
//Load look up table from flash
|
||||
control.LoadFromFlash();
|
||||
cout << "Look up table successfully loaded from flash.\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeSave:
|
||||
{
|
||||
//Save look up table to flash
|
||||
control.SaveToFlash();
|
||||
cout << "Look up table successfully saved to flash.\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeSaveCSV:
|
||||
{
|
||||
//Download LUT
|
||||
control.Download();
|
||||
//Save look up table to file
|
||||
control.SaveToCsv( fileName.c_str() );
|
||||
cout << "Look up table successfully saved to CSV.\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeLoadCSV:
|
||||
{
|
||||
//Load look up table from file
|
||||
control.LoadFromCsv( fileName, (int)nValue );
|
||||
control.Upload();
|
||||
cout << "Look up table successfully loaded from CSV.\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeEnable:
|
||||
{
|
||||
//Set look up table enable
|
||||
control.Enable( bValue );
|
||||
cout << "Look up table was enabled successfully.\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeBitIn:
|
||||
{
|
||||
//Get bit depth in of look up table
|
||||
cout << "Get look up table 'bit depth in' was successful. BitDepthIn = " << control.GetBitDepthIn( ) <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeBitOut:
|
||||
{
|
||||
//Get bit depth out of look up table
|
||||
cout << "Get look up table 'bit depth out' was successful. BitDepthOut = " << control.GetBitDepthOut( ) <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeSetValue:
|
||||
{
|
||||
//Set look up table value
|
||||
control.SetValue( nValue );
|
||||
cout << "Look up table value was set successfully." <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeGetValue:
|
||||
{
|
||||
//Get look up table value
|
||||
cout << "Get look up table value was successful. Value = " << control.GetValue() <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
case ModeCount:
|
||||
{
|
||||
//Get look up table count
|
||||
cout << "Get look up table count was successful. Count = " << collection.GetCount( ) <<"\n";
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Camera does not support LookUp Table Feature\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
catch( AVT::VmbAPI::Examples::Exception& ex )
|
||||
{
|
||||
cout << ex.GetMessageStr() << " VimbaException: " << ex.GetError() << " = " << ex.ErrorCodeToMessage( ex.GetError() ) <<"\n";
|
||||
}
|
||||
|
||||
//Close camera
|
||||
if( NULL != pCamera )
|
||||
{
|
||||
pCamera->Close();
|
||||
}
|
||||
|
||||
//Shutdown API
|
||||
if( true == bVimbaStarted )
|
||||
{
|
||||
vimbaSystem.Shutdown();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
Reference in New Issue
Block a user