AVT相机arm版本SDK
This commit is contained in:
@@ -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