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;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
PROJECT_NAME = AsynchronousGrabQt
|
||||
|
||||
PROJECT_DIR = ../..
|
||||
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
||||
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
||||
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
||||
|
||||
include $(MAKE_INCLUDE_DIR)/Common.mk
|
||||
|
||||
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
|
||||
BIN_FILE = $(PROJECT_NAME)
|
||||
BIN_DIR = binary/$(CONFIG_DIR)
|
||||
OBJ_DIR = object/$(CONFIG_DIR)
|
||||
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
||||
|
||||
all: $(BIN_PATH)
|
||||
|
||||
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
||||
include $(MAKE_INCLUDE_DIR)/VimbaImageTransform.mk
|
||||
include $(MAKE_INCLUDE_DIR)/Qt.mk
|
||||
|
||||
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||
|
||||
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||
-I$(EXAMPLES_DIR) \
|
||||
-I$(OBJ_DIR)
|
||||
|
||||
LIBS = $(VIMBACPP_LIBS) \
|
||||
$(VIMBAIMAGETRANSFORM_LIBS) \
|
||||
$(QTCORE_LIBS) \
|
||||
$(QTGUI_LIBS)
|
||||
|
||||
DEFINES =
|
||||
|
||||
CFLAGS = $(COMMON_CFLAGS) \
|
||||
$(VIMBACPP_CFLAGS) \
|
||||
$(VIMBAIMAGETRANSFORM_CFLAGS) \
|
||||
$(QTCORE_CFLAGS) \
|
||||
$(QTGUI_CFLAGS)
|
||||
|
||||
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||
$(OBJ_DIR)/AsynchronousGrab.o \
|
||||
$(OBJ_DIR)/CameraObserver.o \
|
||||
$(OBJ_DIR)/FrameObserver.o \
|
||||
$(OBJ_DIR)/main.o \
|
||||
$(OBJ_DIR)/moc_AsynchronousGrab.o \
|
||||
$(OBJ_DIR)/moc_CameraObserver.o \
|
||||
$(OBJ_DIR)/moc_FrameObserver.o \
|
||||
$(OBJ_DIR)/qrc_AsynchronousGrab.o
|
||||
|
||||
GEN_HEADERS = $(OBJ_DIR)/ui_AsynchronousGrab.h
|
||||
|
||||
DEPENDENCIES = VimbaCPP \
|
||||
VimbaImageTransform \
|
||||
QtCore \
|
||||
QtGui
|
||||
|
||||
$(OBJ_DIR)/moc_%.cpp: $(SOURCE_DIR)/%.h $(OBJ_DIR)
|
||||
$(MOC) -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/ui_%.h: $(SOURCE_DIR)/res/%.ui $(OBJ_DIR)
|
||||
$(UIC) -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/qrc_%.cpp: $(SOURCE_DIR)/res/%.qrc $(OBJ_DIR)
|
||||
$(RCC) -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
|
||||
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.cpp $(OBJ_DIR) $(GEN_HEADERS)
|
||||
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
|
||||
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
|
||||
|
||||
clean:
|
||||
$(RM) binary -r -f
|
||||
$(RM) object -r -f
|
||||
|
||||
$(OBJ_DIR):
|
||||
$(MKDIR) -p $(OBJ_DIR)
|
||||
|
||||
$(BIN_DIR):
|
||||
$(MKDIR) -p $(BIN_DIR)
|
||||
@@ -0,0 +1,340 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: ApiController.cpp
|
||||
|
||||
Description: Implementation file for the ApiController helper class that
|
||||
demonstrates how to implement an asynchronous, continuous image
|
||||
acquisition with VimbaCPP.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <ApiController.h>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include "Common/StreamSystemInfo.h"
|
||||
#include "Common/ErrorCodeToMessage.h"
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
enum { NUM_FRAMES=3, };
|
||||
|
||||
ApiController::ApiController()
|
||||
// Get a reference to the Vimba singleton
|
||||
: m_system( VimbaSystem::GetInstance() )
|
||||
{
|
||||
}
|
||||
|
||||
ApiController::~ApiController()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Translates Vimba error codes to readable error messages
|
||||
//
|
||||
// Parameters:
|
||||
// [in] eErr The error code to be converted to string
|
||||
//
|
||||
// Returns:
|
||||
// A descriptive string representation of the error code
|
||||
//
|
||||
std::string ApiController::ErrorCodeToMessage( VmbErrorType eErr ) const
|
||||
{
|
||||
return AVT::VmbAPI::Examples::ErrorCodeToMessage( eErr );
|
||||
}
|
||||
|
||||
//
|
||||
// Starts the Vimba API and loads all transport layers
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::StartUp()
|
||||
{
|
||||
VmbErrorType res;
|
||||
|
||||
// Start Vimba
|
||||
res = m_system.Startup();
|
||||
if( VmbErrorSuccess == res )
|
||||
{
|
||||
// This will be wrapped in a shared_ptr so we don't delete it
|
||||
SP_SET( m_pCameraObserver , new CameraObserver() );
|
||||
// Register an observer whose callback routine gets triggered whenever a camera is plugged in or out
|
||||
res = m_system.RegisterCameraListObserver( m_pCameraObserver );
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// Shuts down the API
|
||||
//
|
||||
void ApiController::ShutDown()
|
||||
{
|
||||
// Release Vimba
|
||||
m_system.Shutdown();
|
||||
}
|
||||
/*** helper function to set image size to a value that is dividable by modulo 2 and a multiple of the increment.
|
||||
\note this is needed because VimbaImageTransform does not support odd values for some input formats
|
||||
*/
|
||||
inline VmbErrorType SetValueIntMod2( const CameraPtr &camera, const std::string &featureName, VmbInt64_t &storage )
|
||||
{
|
||||
VmbErrorType res;
|
||||
FeaturePtr pFeature;
|
||||
VmbInt64_t minValue = 0;
|
||||
VmbInt64_t maxValue = 0;
|
||||
VmbInt64_t incrementValue = 0;
|
||||
|
||||
res = SP_ACCESS( camera )->GetFeatureByName( featureName.c_str(), pFeature );
|
||||
if( VmbErrorSuccess != res )
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
res = SP_ACCESS( pFeature )->GetRange( minValue, maxValue );
|
||||
if( VmbErrorSuccess != res )
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
res = SP_ACCESS( pFeature )->GetIncrement( incrementValue);
|
||||
if( VmbErrorSuccess != res)
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
maxValue = maxValue - ( maxValue % incrementValue );
|
||||
if( maxValue % 2 != 0)
|
||||
{
|
||||
maxValue -= incrementValue;
|
||||
}
|
||||
|
||||
res = SP_ACCESS( pFeature )->SetValue( maxValue );
|
||||
if( VmbErrorSuccess != res )
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
storage = maxValue;
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// Opens the given camera
|
||||
// Sets the maximum possible Ethernet packet size
|
||||
// Adjusts the image format
|
||||
// Sets up the observer that will be notified on every incoming frame
|
||||
// Calls the API convenience function to start image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::StartContinuousImageAcquisition( const std::string &rStrCameraID )
|
||||
{
|
||||
// Open the desired camera by its ID
|
||||
VmbErrorType res = m_system.OpenCameraByID( rStrCameraID.c_str(), VmbAccessModeFull, m_pCamera );
|
||||
if( VmbErrorSuccess == res )
|
||||
{
|
||||
// Set the GeV packet size to the highest possible value
|
||||
// (In this example we do not test whether this cam actually is a GigE cam)
|
||||
FeaturePtr pCommandFeature;
|
||||
if( VmbErrorSuccess == SP_ACCESS( m_pCamera )->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ) )
|
||||
{
|
||||
if( VmbErrorSuccess == SP_ACCESS( pCommandFeature )->RunCommand() )
|
||||
{
|
||||
bool bIsCommandDone = false;
|
||||
do
|
||||
{
|
||||
if( VmbErrorSuccess != SP_ACCESS( pCommandFeature )->IsCommandDone( bIsCommandDone ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while( false == bIsCommandDone );
|
||||
}
|
||||
}
|
||||
res = SetValueIntMod2( m_pCamera,"Width", m_nWidth );
|
||||
if( VmbErrorSuccess == res )
|
||||
{
|
||||
res = SetValueIntMod2( m_pCamera, "Height", m_nHeight );
|
||||
if( VmbErrorSuccess == res )
|
||||
{
|
||||
// Store currently selected image format
|
||||
FeaturePtr pFormatFeature;
|
||||
res = SP_ACCESS( m_pCamera )->GetFeatureByName( "PixelFormat", pFormatFeature );
|
||||
if( VmbErrorSuccess == res )
|
||||
{
|
||||
res = SP_ACCESS( pFormatFeature )->GetValue( m_nPixelFormat );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Create a frame observer for this camera (This will be wrapped in a shared_ptr so we don't delete it)
|
||||
SP_SET( m_pFrameObserver , new FrameObserver( m_pCamera ) );
|
||||
// Start streaming
|
||||
res = SP_ACCESS( m_pCamera )->StartContinuousImageAcquisition( NUM_FRAMES, m_pFrameObserver );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( VmbErrorSuccess != res )
|
||||
{
|
||||
// If anything fails after opening the camera we close it
|
||||
SP_ACCESS( m_pCamera )->Close();
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// Calls the API convenience function to stop image acquisition
|
||||
// Closes the camera
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::StopContinuousImageAcquisition()
|
||||
{
|
||||
// Stop streaming
|
||||
SP_ACCESS( m_pCamera )->StopContinuousImageAcquisition();
|
||||
|
||||
// Close camera
|
||||
return m_pCamera->Close();
|
||||
}
|
||||
|
||||
//
|
||||
// Gets all cameras known to Vimba
|
||||
//
|
||||
// Returns:
|
||||
// A vector of camera shared pointers
|
||||
//
|
||||
CameraPtrVector ApiController::GetCameraList()
|
||||
{
|
||||
CameraPtrVector cameras;
|
||||
// Get all known cameras
|
||||
if( VmbErrorSuccess == m_system.GetCameras( cameras ) )
|
||||
{
|
||||
// And return them
|
||||
return cameras;
|
||||
}
|
||||
return CameraPtrVector();
|
||||
}
|
||||
|
||||
//
|
||||
// Gets the width of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The width as integer
|
||||
//
|
||||
int ApiController::GetWidth() const
|
||||
{
|
||||
return static_cast<int>(m_nWidth);
|
||||
}
|
||||
|
||||
//
|
||||
// Gets the height of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The height as integer
|
||||
//
|
||||
int ApiController::GetHeight() const
|
||||
{
|
||||
return static_cast<int>(m_nHeight);
|
||||
}
|
||||
|
||||
//
|
||||
// Gets the pixel format of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The pixel format as enum
|
||||
//
|
||||
VmbPixelFormatType ApiController::GetPixelFormat() const
|
||||
{
|
||||
return static_cast<VmbPixelFormatType>(m_nPixelFormat);
|
||||
}
|
||||
|
||||
//
|
||||
// Gets the oldest frame that has not been picked up yet
|
||||
//
|
||||
// Returns:
|
||||
// A frame shared pointer
|
||||
//
|
||||
FramePtr ApiController::GetFrame()
|
||||
{
|
||||
return SP_DYN_CAST( m_pFrameObserver, FrameObserver )->GetFrame();
|
||||
}
|
||||
|
||||
//
|
||||
// Clears all remaining frames that have not been picked up
|
||||
//
|
||||
void ApiController::ClearFrameQueue()
|
||||
{
|
||||
SP_DYN_CAST( m_pFrameObserver,FrameObserver )->ClearFrameQueue();
|
||||
}
|
||||
|
||||
//
|
||||
// Queues a given frame to be filled by the API
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pFrame The frame to queue
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::QueueFrame( FramePtr pFrame )
|
||||
{
|
||||
return SP_ACCESS( m_pCamera )->QueueFrame( pFrame );
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* ApiController::GetCameraObserver()
|
||||
{
|
||||
return SP_DYN_CAST( m_pCameraObserver, CameraObserver ).get();
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* ApiController::GetFrameObserver()
|
||||
{
|
||||
return SP_DYN_CAST( m_pFrameObserver, FrameObserver ).get();
|
||||
}
|
||||
|
||||
//
|
||||
// Gets the version of the Vimba API
|
||||
//
|
||||
// Returns:
|
||||
// The version as string
|
||||
//
|
||||
std::string ApiController::GetVersion() const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << m_system;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
@@ -0,0 +1,191 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: ApiController.h
|
||||
|
||||
Description: Implementation file for the ApiController helper class that
|
||||
demonstrates how to implement an asynchronous, continuous image
|
||||
acquisition with VimbaCPP.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef AVT_VMBAPI_EXAMPLES_APICONTROLLER
|
||||
#define AVT_VMBAPI_EXAMPLES_APICONTROLLER
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <VimbaCPP/Include/VimbaCPP.h>
|
||||
|
||||
#include <CameraObserver.h>
|
||||
#include <FrameObserver.h>
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class ApiController
|
||||
{
|
||||
public:
|
||||
ApiController();
|
||||
~ApiController();
|
||||
|
||||
//
|
||||
// Starts the Vimba API and loads all transport layers
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType StartUp();
|
||||
|
||||
//
|
||||
// Shuts down the API
|
||||
//
|
||||
void ShutDown();
|
||||
|
||||
//
|
||||
// Opens the given camera
|
||||
// Sets the maximum possible Ethernet packet size
|
||||
// Adjusts the image format
|
||||
// Sets up the observer that will be notified on every incoming frame
|
||||
// Calls the API convenience function to start image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to open as reported by Vimba
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType StartContinuousImageAcquisition( const std::string &rStrCameraID );
|
||||
|
||||
//
|
||||
// Calls the API convenience function to stop image acquisition
|
||||
// Closes the camera
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType StopContinuousImageAcquisition();
|
||||
|
||||
//
|
||||
// Gets the width of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The width as integer
|
||||
//
|
||||
int GetWidth() const;
|
||||
|
||||
//
|
||||
// Gets the height of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The height as integer
|
||||
//
|
||||
int GetHeight() const;
|
||||
|
||||
//
|
||||
// Gets the pixel format of a frame
|
||||
//
|
||||
// Returns:
|
||||
// The pixel format as enum
|
||||
//
|
||||
VmbPixelFormatType GetPixelFormat() const;
|
||||
|
||||
//
|
||||
// Gets all cameras known to Vimba
|
||||
//
|
||||
// Returns:
|
||||
// A vector of camera shared pointers
|
||||
//
|
||||
CameraPtrVector GetCameraList();
|
||||
|
||||
//
|
||||
// Gets the oldest frame that has not been picked up yet
|
||||
//
|
||||
// Returns:
|
||||
// A frame shared pointer
|
||||
//
|
||||
FramePtr GetFrame();
|
||||
|
||||
//
|
||||
// Queues a given frame to be filled by the API
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pFrame The frame to queue
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType QueueFrame( FramePtr pFrame );
|
||||
|
||||
//
|
||||
// Clears all remaining frames that have not been picked up
|
||||
//
|
||||
void ClearFrameQueue();
|
||||
|
||||
//
|
||||
// Returns the camera observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* GetCameraObserver();
|
||||
|
||||
//
|
||||
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* GetFrameObserver();
|
||||
|
||||
//
|
||||
// Translates Vimba error codes to readable error messages
|
||||
//
|
||||
// Parameters:
|
||||
// [in] eErr The error code to be converted to string
|
||||
//
|
||||
// Returns:
|
||||
// A descriptive string representation of the error code
|
||||
//
|
||||
std::string ErrorCodeToMessage( VmbErrorType eErr ) const;
|
||||
|
||||
//
|
||||
// Gets the version of the Vimba API
|
||||
//
|
||||
// Returns:
|
||||
// The version as string
|
||||
//
|
||||
std::string GetVersion() const;
|
||||
private:
|
||||
// A reference to our Vimba singleton
|
||||
VimbaSystem& m_system;
|
||||
// The currently streaming camera
|
||||
CameraPtr m_pCamera;
|
||||
// Every camera has its own frame observer
|
||||
IFrameObserverPtr m_pFrameObserver;
|
||||
// Our camera observer
|
||||
ICameraListObserverPtr m_pCameraObserver;
|
||||
// The current pixel format
|
||||
VmbInt64_t m_nPixelFormat;
|
||||
// The current width
|
||||
VmbInt64_t m_nWidth;
|
||||
// The current height
|
||||
VmbInt64_t m_nHeight;
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,354 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2017 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: AsynchronousGrab.cpp
|
||||
|
||||
Description: Qt dialog class for the GUI of the AsynchronousGrab example of
|
||||
VimbaCPP.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "AsynchronousGrab.h"
|
||||
#include "VmbTransform.h"
|
||||
#define NUM_COLORS 3
|
||||
#define BIT_DEPTH 8
|
||||
|
||||
using AVT::VmbAPI::FramePtr;
|
||||
using AVT::VmbAPI::CameraPtrVector;
|
||||
|
||||
AsynchronousGrab::AsynchronousGrab( QWidget *parent, Qt::WindowFlags flags )
|
||||
: QMainWindow( parent, flags )
|
||||
, m_bIsStreaming( false )
|
||||
{
|
||||
ui.setupUi( this );
|
||||
ui.m_LabelStream->setAlignment(Qt::AlignCenter );
|
||||
// Connect GUI events with event handlers
|
||||
QObject::connect( ui.m_ButtonStartStop, SIGNAL( clicked() ), this, SLOT( OnBnClickedButtonStartstop() ) );
|
||||
|
||||
// Start Vimba
|
||||
VmbErrorType err = m_ApiController.StartUp();
|
||||
setWindowTitle( QString( "AsynchronousGrab (Qt version) Vimba C++ API Version " )+ QString::fromStdString( m_ApiController.GetVersion() ) );
|
||||
Log( "Starting Vimba", err );
|
||||
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
// Connect new camera found event with event handler
|
||||
QObject::connect( m_ApiController.GetCameraObserver(), SIGNAL( CameraListChangedSignal(int) ), this, SLOT( OnCameraListChanged(int) ) );
|
||||
|
||||
// Initially get all connected cameras
|
||||
UpdateCameraListBox();
|
||||
std::stringstream strMsg;
|
||||
strMsg << "Cameras found..." << m_cameras.size();
|
||||
Log(strMsg.str() );
|
||||
}
|
||||
}
|
||||
|
||||
AsynchronousGrab::~AsynchronousGrab()
|
||||
{
|
||||
// if we are streaming stop streaming
|
||||
if( true == m_bIsStreaming )
|
||||
{
|
||||
OnBnClickedButtonStartstop();
|
||||
}
|
||||
|
||||
// Before we close the application we stop Vimba
|
||||
m_ApiController.ShutDown();
|
||||
}
|
||||
|
||||
void AsynchronousGrab::OnBnClickedButtonStartstop()
|
||||
{
|
||||
VmbErrorType err;
|
||||
int nRow = ui.m_ListBoxCameras->currentRow();
|
||||
|
||||
if( -1 < nRow )
|
||||
{
|
||||
if( false == m_bIsStreaming )
|
||||
{
|
||||
// Start acquisition
|
||||
err = m_ApiController.StartContinuousImageAcquisition( m_cameras[nRow] );
|
||||
// Set up Qt image
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
m_Image = QImage( m_ApiController.GetWidth(),
|
||||
m_ApiController.GetHeight(),
|
||||
QImage::Format_RGB888 );
|
||||
|
||||
QObject::connect( m_ApiController.GetFrameObserver(), SIGNAL( FrameReceivedSignal(int) ), this, SLOT( OnFrameReady(int) ) );
|
||||
}
|
||||
Log( "Starting Acquisition", err );
|
||||
m_bIsStreaming = VmbErrorSuccess == err;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bIsStreaming = false;
|
||||
// Stop acquisition
|
||||
err = m_ApiController.StopContinuousImageAcquisition();
|
||||
// Clear all frames that we have not picked up so far
|
||||
m_ApiController.ClearFrameQueue();
|
||||
m_Image = QImage();
|
||||
Log( "Stopping Acquisition", err );
|
||||
}
|
||||
|
||||
if( false == m_bIsStreaming )
|
||||
{
|
||||
ui.m_ButtonStartStop->setText( QString( "Start Image Acquisition" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.m_ButtonStartStop->setText( QString( "Stop Image Acquisition" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
|
||||
//
|
||||
// Parameters:
|
||||
// [in] status The frame receive status (complete, incomplete, ...)
|
||||
//
|
||||
void AsynchronousGrab::OnFrameReady( int status )
|
||||
{
|
||||
if( true == m_bIsStreaming )
|
||||
{
|
||||
// Pick up frame
|
||||
FramePtr pFrame = m_ApiController.GetFrame();
|
||||
if( SP_ISNULL( pFrame ) )
|
||||
{
|
||||
Log("frame pointer is NULL, late frame ready message");
|
||||
return;
|
||||
}
|
||||
// See if it is not corrupt
|
||||
if( VmbFrameStatusComplete == status )
|
||||
{
|
||||
VmbUchar_t *pBuffer;
|
||||
VmbErrorType err = SP_ACCESS( pFrame )->GetImage( pBuffer );
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbUint32_t nSize;
|
||||
err = SP_ACCESS( pFrame )->GetImageSize( nSize );
|
||||
if( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbPixelFormatType ePixelFormat = m_ApiController.GetPixelFormat();
|
||||
if( ! m_Image.isNull() )
|
||||
{
|
||||
// Copy it
|
||||
// We need that because Qt might repaint the view after we have released the frame already
|
||||
if( ui.m_ColorProcessingCheckBox->checkState()== Qt::Checked )
|
||||
{
|
||||
static const VmbFloat_t Matrix[] = { 8.0f, 0.1f, 0.1f, // this matrix just makes a quick color to mono conversion
|
||||
0.1f, 0.8f, 0.1f,
|
||||
0.0f, 0.0f, 1.0f };
|
||||
if( VmbErrorSuccess != CopyToImage( pBuffer,ePixelFormat, m_Image, Matrix ) )
|
||||
{
|
||||
ui.m_ColorProcessingCheckBox->setChecked( false );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyToImage( pBuffer,ePixelFormat, m_Image );
|
||||
}
|
||||
|
||||
// Display it
|
||||
const QSize s = ui.m_LabelStream->size() ;
|
||||
ui.m_LabelStream->setPixmap( QPixmap::fromImage( m_Image ).scaled(s,Qt::KeepAspectRatio ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we receive an incomplete image we do nothing but logging
|
||||
Log( "Failure in receiving image", VmbErrorOther );
|
||||
}
|
||||
|
||||
// And queue it to continue streaming
|
||||
m_ApiController.QueueFrame( pFrame );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
|
||||
//
|
||||
// Parameters:
|
||||
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
|
||||
//
|
||||
void AsynchronousGrab::OnCameraListChanged( int reason )
|
||||
{
|
||||
bool bUpdateList = false;
|
||||
|
||||
// We only react on new cameras being found and known cameras being unplugged
|
||||
if( AVT::VmbAPI::UpdateTriggerPluggedIn == reason )
|
||||
{
|
||||
Log( "Camera list changed. A new camera was discovered by Vimba." );
|
||||
bUpdateList = true;
|
||||
}
|
||||
else if( AVT::VmbAPI::UpdateTriggerPluggedOut == reason )
|
||||
{
|
||||
Log( "Camera list changed. A camera was disconnected from Vimba." );
|
||||
if( true == m_bIsStreaming )
|
||||
{
|
||||
OnBnClickedButtonStartstop();
|
||||
}
|
||||
bUpdateList = true;
|
||||
}
|
||||
|
||||
if( true == bUpdateList )
|
||||
{
|
||||
UpdateCameraListBox();
|
||||
}
|
||||
|
||||
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
|
||||
}
|
||||
|
||||
//
|
||||
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pInbuffer The byte buffer as received from the cam
|
||||
// [in] ePixelFormat The pixel format of the frame
|
||||
// [out] OutImage The filled Qt image
|
||||
//
|
||||
VmbErrorType AsynchronousGrab::CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix /*= NULL */ )
|
||||
{
|
||||
const int nHeight = m_ApiController.GetHeight();
|
||||
const int nWidth = m_ApiController.GetWidth();
|
||||
|
||||
VmbImage SourceImage,DestImage;
|
||||
VmbError_t Result;
|
||||
SourceImage.Size = sizeof( SourceImage );
|
||||
DestImage.Size = sizeof( DestImage );
|
||||
|
||||
Result = VmbSetImageInfoFromPixelFormat( ePixelFormat, nWidth, nHeight, & SourceImage );
|
||||
if( VmbErrorSuccess != Result )
|
||||
{
|
||||
Log( "Could not set source image info", static_cast<VmbErrorType>( Result ) );
|
||||
return static_cast<VmbErrorType>( Result );
|
||||
}
|
||||
QString OutputFormat;
|
||||
const int bytes_per_line = pOutImage.bytesPerLine();
|
||||
switch( pOutImage.format() )
|
||||
{
|
||||
default:
|
||||
Log( "unknown output format",VmbErrorBadParameter );
|
||||
return VmbErrorBadParameter;
|
||||
case QImage::Format_RGB888:
|
||||
if( nWidth*3 != bytes_per_line )
|
||||
{
|
||||
Log( "image transform does not support stride",VmbErrorWrongType );
|
||||
return VmbErrorWrongType;
|
||||
}
|
||||
OutputFormat = "RGB24";
|
||||
break;
|
||||
}
|
||||
Result = VmbSetImageInfoFromString( OutputFormat.toStdString().c_str(), OutputFormat.length(),nWidth,nHeight, &DestImage );
|
||||
if( VmbErrorSuccess != Result )
|
||||
{
|
||||
Log( "could not set output image info",static_cast<VmbErrorType>( Result ) );
|
||||
return static_cast<VmbErrorType>( Result );
|
||||
}
|
||||
SourceImage.Data = pInBuffer;
|
||||
DestImage.Data = pOutImage.bits();
|
||||
// do color processing?
|
||||
if( NULL != Matrix )
|
||||
{
|
||||
VmbTransformInfo TransformParameter;
|
||||
Result = VmbSetColorCorrectionMatrix3x3( Matrix, &TransformParameter );
|
||||
if( VmbErrorSuccess == Result )
|
||||
{
|
||||
Result = VmbImageTransform( &SourceImage, &DestImage, &TransformParameter,1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
Log( "could not set matrix t o transform info ", static_cast<VmbErrorType>( Result ) );
|
||||
return static_cast<VmbErrorType>( Result );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = VmbImageTransform( &SourceImage, &DestImage,NULL,0 );
|
||||
}
|
||||
if( VmbErrorSuccess != Result )
|
||||
{
|
||||
Log( "could not transform image", static_cast<VmbErrorType>( Result ) );
|
||||
return static_cast<VmbErrorType>( Result );
|
||||
}
|
||||
return static_cast<VmbErrorType>( Result );
|
||||
}
|
||||
|
||||
//
|
||||
// Queries and lists all known camera
|
||||
//
|
||||
void AsynchronousGrab::UpdateCameraListBox()
|
||||
{
|
||||
// Get all cameras currently connected to Vimba
|
||||
CameraPtrVector cameras = m_ApiController.GetCameraList();
|
||||
|
||||
// Simply forget about all cameras known so far
|
||||
ui.m_ListBoxCameras->clear();
|
||||
m_cameras.clear();
|
||||
|
||||
// And query the camera details again
|
||||
for( CameraPtrVector::const_iterator iter = cameras.begin();
|
||||
cameras.end() != iter;
|
||||
++iter )
|
||||
{
|
||||
std::string strCameraName;
|
||||
std::string strCameraID;
|
||||
if( VmbErrorSuccess != (*iter)->GetName( strCameraName ) )
|
||||
{
|
||||
strCameraName = "[NoName]";
|
||||
}
|
||||
// If for any reason we cannot get the ID of a camera we skip it
|
||||
if( VmbErrorSuccess == (*iter)->GetID( strCameraID ) )
|
||||
{
|
||||
ui.m_ListBoxCameras->addItem( QString::fromStdString( strCameraName + " " +strCameraID ) );
|
||||
m_cameras.push_back( strCameraID );
|
||||
}
|
||||
}
|
||||
|
||||
ui.m_ButtonStartStop->setEnabled( 0 < m_cameras.size() || m_bIsStreaming );
|
||||
}
|
||||
|
||||
//
|
||||
// Prints out a given logging string, error code and the descriptive representation of that error code
|
||||
//
|
||||
// Parameters:
|
||||
// [in] strMsg A given message to be printed out
|
||||
// [in] eErr The API status code
|
||||
//
|
||||
void AsynchronousGrab::Log( std::string strMsg, VmbErrorType eErr )
|
||||
{
|
||||
strMsg += "..." + m_ApiController.ErrorCodeToMessage( eErr );
|
||||
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
|
||||
}
|
||||
|
||||
//
|
||||
// Prints out a given logging string
|
||||
//
|
||||
// Parameters:
|
||||
// [in] strMsg A given message to be printed out
|
||||
//
|
||||
void AsynchronousGrab::Log( std::string strMsg)
|
||||
{
|
||||
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: AsynchronousGrab.h
|
||||
|
||||
Description: Qt dialog class for the GUI of the AsynchronousGrab example of
|
||||
VimbaCPP.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef ASYNCHRONOUSGRABQT_H
|
||||
#define ASYNCHRONOUSGRABQT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "ui_AsynchronousGrab.h"
|
||||
|
||||
#include <ApiController.h>
|
||||
|
||||
using AVT::VmbAPI::Examples::ApiController;
|
||||
|
||||
class AsynchronousGrab : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AsynchronousGrab( QWidget *parent = 0, Qt::WindowFlags flags = 0 );
|
||||
~AsynchronousGrab();
|
||||
|
||||
private:
|
||||
// The Qt GUI
|
||||
Ui::AsynchronousGrabClass ui;
|
||||
// Our controller that wraps API access
|
||||
ApiController m_ApiController;
|
||||
// A list of known camera IDs
|
||||
std::vector<std::string> m_cameras;
|
||||
// Are we streaming?
|
||||
bool m_bIsStreaming;
|
||||
// Our Qt image to display
|
||||
QImage m_Image;
|
||||
|
||||
//
|
||||
// Queries and lists all known camera
|
||||
//
|
||||
void UpdateCameraListBox();
|
||||
|
||||
//
|
||||
// Prints out a given logging string, error code and the descriptive representation of that error code
|
||||
//
|
||||
// Parameters:
|
||||
// [in] strMsg A given message to be printed out
|
||||
// [in] eErr The API status code
|
||||
//
|
||||
void Log( std::string strMsg, VmbErrorType eErr );
|
||||
|
||||
//
|
||||
// Prints out a given logging string
|
||||
//
|
||||
// Parameters:
|
||||
// [in] strMsg A given message to be printed out
|
||||
//
|
||||
void Log( std::string strMsg);
|
||||
|
||||
//
|
||||
// Copies the content of a byte buffer to a Qt image with respect to the image's alignment
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pInbuffer The byte buffer as received from the cam
|
||||
// [in] ePixelFormat The pixel format of the frame
|
||||
// [out] OutImage The filled Qt image
|
||||
//
|
||||
VmbErrorType CopyToImage( VmbUchar_t *pInBuffer, VmbPixelFormat_t ePixelFormat, QImage &pOutImage, const float *Matrix = NULL );
|
||||
|
||||
private slots:
|
||||
// The event handler for starting / stopping acquisition
|
||||
void OnBnClickedButtonStartstop();
|
||||
|
||||
//
|
||||
// This event handler (Qt slot) is triggered through a Qt signal posted by the frame observer
|
||||
//
|
||||
// Parameters:
|
||||
// [in] status The frame receive status (complete, incomplete, ...)
|
||||
//
|
||||
void OnFrameReady( int status );
|
||||
|
||||
//
|
||||
// This event handler (Qt slot) is triggered through a Qt signal posted by the camera observer
|
||||
//
|
||||
// Parameters:
|
||||
// [in] reason The reason why the callback of the observer was triggered (plug-in, plug-out, ...)
|
||||
//
|
||||
void OnCameraListChanged( int reason );
|
||||
};
|
||||
|
||||
#endif // ASYNCHRONOUSGRABQT_H
|
||||
@@ -0,0 +1,52 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: CameraObserver.cpp
|
||||
|
||||
Description: The camera observer that is used for notifications from VimbaCPP
|
||||
regarding a change in the camera list.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <CameraObserver.h>
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
//
|
||||
// This is our callback routine that will be executed every time a camera was plugged in or out
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pCam The camera that triggered the callback
|
||||
// [in] reason The reason why the callback was triggered
|
||||
//
|
||||
void CameraObserver::CameraListChanged( CameraPtr pCam, UpdateTriggerType reason )
|
||||
{
|
||||
if ( UpdateTriggerPluggedIn == reason
|
||||
|| UpdateTriggerPluggedOut == reason )
|
||||
{
|
||||
// Emit the new camera signal
|
||||
emit CameraListChangedSignal( reason );
|
||||
}
|
||||
}
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
@@ -0,0 +1,66 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: CameraObserver.h
|
||||
|
||||
Description: The camera observer that is used for notifications from VimbaCPP
|
||||
regarding a change in the camera list.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
|
||||
#define AVT_VMBAPI_EXAMPLES_CAMERAOBSERVER
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <VimbaCPP/Include/VimbaCPP.h>
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class CameraObserver : public QObject, public ICameraListObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//
|
||||
// This is our callback routine that will be executed every time a camera was plugged in or out
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pCam The camera that triggered the callback
|
||||
// [in] reason The reason why the callback was triggered
|
||||
//
|
||||
virtual void CameraListChanged( CameraPtr pCamera, UpdateTriggerType reason );
|
||||
|
||||
signals:
|
||||
//
|
||||
// The camera list changed event (Qt signal) that notifies about a camera change and its reason
|
||||
//
|
||||
// Parameters:
|
||||
// [out] reason The reason why this event was fired
|
||||
//
|
||||
void CameraListChangedSignal( int reason );
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,105 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: FrameObserver.cpp
|
||||
|
||||
Description: The frame observer that is used for notifications from VimbaCPP
|
||||
regarding the arrival of a newly acquired frame.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include <FrameObserver.h>
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
//
|
||||
// This is our callback routine that will be executed on every received frame.
|
||||
// Triggered by the API.
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pFrame The frame returned from the API
|
||||
//
|
||||
void FrameObserver::FrameReceived( const FramePtr pFrame )
|
||||
{
|
||||
bool bQueueDirectly = true;
|
||||
VmbFrameStatusType eReceiveStatus;
|
||||
|
||||
if( 0 != receivers(SIGNAL(FrameReceivedSignal(int)) )
|
||||
&& VmbErrorSuccess == pFrame->GetReceiveStatus( eReceiveStatus ) )
|
||||
{
|
||||
// Lock the frame queue
|
||||
m_FramesMutex.lock();
|
||||
// Add frame to queue
|
||||
m_Frames.push( pFrame );
|
||||
// Unlock frame queue
|
||||
m_FramesMutex.unlock();
|
||||
// Emit the frame received signal
|
||||
emit FrameReceivedSignal( eReceiveStatus );
|
||||
bQueueDirectly = false;
|
||||
}
|
||||
|
||||
// If any error occurred we queue the frame without notification
|
||||
if( true == bQueueDirectly )
|
||||
{
|
||||
m_pCamera->QueueFrame( pFrame );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// After the view has been notified about a new frame it can pick it up.
|
||||
// It is then removed from the internal queue
|
||||
//
|
||||
// Returns:
|
||||
// A shared pointer to the latest frame
|
||||
//
|
||||
FramePtr FrameObserver::GetFrame()
|
||||
{
|
||||
// Lock the frame queue
|
||||
m_FramesMutex.lock();
|
||||
// Pop frame from queue
|
||||
FramePtr res;
|
||||
if( !m_Frames.empty() )
|
||||
{
|
||||
res = m_Frames.front();
|
||||
m_Frames.pop();
|
||||
}
|
||||
// Unlock frame queue
|
||||
m_FramesMutex.unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// Clears the internal (double buffering) frame queue
|
||||
//
|
||||
void FrameObserver::ClearFrameQueue()
|
||||
{
|
||||
// Lock the frame queue
|
||||
m_FramesMutex.lock();
|
||||
// Clear the frame queue and release the memory
|
||||
std::queue<FramePtr> empty;
|
||||
std::swap( m_Frames, empty );
|
||||
// Unlock the frame queue
|
||||
m_FramesMutex.unlock();
|
||||
}
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
@@ -0,0 +1,97 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: FrameObserver.h
|
||||
|
||||
Description: The frame observer that is used for notifications from VimbaCPP
|
||||
regarding the arrival of a newly acquired frame.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
|
||||
#define AVT_VMBAPI_EXAMPLES_FRAMEOBSERVER
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
|
||||
#include <VimbaCPP/Include/VimbaCPP.h>
|
||||
|
||||
namespace AVT {
|
||||
namespace VmbAPI {
|
||||
namespace Examples {
|
||||
|
||||
class FrameObserver : public QObject, virtual public IFrameObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//
|
||||
// We pass the camera that will deliver the frames to the constructor
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pCamera The camera the frame was queued at
|
||||
//
|
||||
FrameObserver( CameraPtr pCamera ) : IFrameObserver( pCamera ) {;}
|
||||
|
||||
//
|
||||
// This is our callback routine that will be executed on every received frame.
|
||||
// Triggered by the API.
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pFrame The frame returned from the API
|
||||
//
|
||||
virtual void FrameReceived( const FramePtr pFrame );
|
||||
|
||||
//
|
||||
// After the view has been notified about a new frame it can pick it up.
|
||||
// It is then removed from the internal queue
|
||||
//
|
||||
// Returns:
|
||||
// A shared pointer to the latest frame
|
||||
//
|
||||
FramePtr GetFrame();
|
||||
|
||||
//
|
||||
// Clears the internal (double buffering) frame queue
|
||||
//
|
||||
void ClearFrameQueue();
|
||||
|
||||
private:
|
||||
// Since a Qt signal cannot contain a whole frame
|
||||
// the frame observer stores all FramePtr
|
||||
std::queue<FramePtr> m_Frames;
|
||||
QMutex m_FramesMutex;
|
||||
|
||||
signals:
|
||||
//
|
||||
// The frame received event (Qt signal) that notifies about a new incoming frame
|
||||
//
|
||||
// Parameters:
|
||||
// [out] status The frame receive status
|
||||
//
|
||||
void FrameReceivedSignal( int status );
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,37 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: main.cpp
|
||||
|
||||
Description: The main entry point of the AsynchronousGrab example of VimbaCPP.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include "AsynchronousGrab.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
QApplication a( argc, argv );
|
||||
AsynchronousGrab w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/AsynchronousGrabQt">
|
||||
<file>AsynchronousGrab.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AsynchronousGrabClass</class>
|
||||
<widget class="QMainWindow" name="AsynchronousGrabClass">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1040</width>
|
||||
<height>780</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>1040</width>
|
||||
<height>780</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1040</width>
|
||||
<height>780</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>AsynchronousGrab (Qt version)</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="AsynchronousGrab.qrc">
|
||||
<normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</normaloff>:/AsynchronousGrabQt/AsynchronousGrab.png</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QListWidget" name="m_ListBoxCameras">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>10</y>
|
||||
<width>261</width>
|
||||
<height>491</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="m_ListLog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>580</y>
|
||||
<width>1041</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="m_ButtonStartStop">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>540</y>
|
||||
<width>261</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start Image Acquisition</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="m_LabelStream">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>270</x>
|
||||
<y>10</y>
|
||||
<width>771</width>
|
||||
<height>561</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QCheckBox" name="m_ColorProcessingCheckBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>140</x>
|
||||
<y>510</y>
|
||||
<width>121</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>ColorProcessing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
<include location="AsynchronousGrab.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user