AVT相机arm版本SDK
This commit is contained in:
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user