AVT相机arm版本SDK
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
PROJECT_NAME = SynchronousGrabConsole
|
||||
|
||||
PROJECT_DIR = ../..
|
||||
EXAMPLES_DIR = $(PROJECT_DIR)/../..
|
||||
VIMBASDK_DIR = $(EXAMPLES_DIR)/../..
|
||||
MAKE_INCLUDE_DIR = $(CURDIR)/$(EXAMPLES_DIR)/Build/Make
|
||||
|
||||
include $(MAKE_INCLUDE_DIR)/Common.mk
|
||||
|
||||
CONFIG_DIR = $(ARCH)_$(WORDSIZE)bit
|
||||
BIN_FILE = $(PROJECT_NAME)
|
||||
BIN_DIR = binary/$(CONFIG_DIR)
|
||||
OBJ_DIR = object/$(CONFIG_DIR)
|
||||
BIN_PATH = $(BIN_DIR)/$(BIN_FILE)
|
||||
|
||||
all: $(BIN_PATH)
|
||||
|
||||
include $(MAKE_INCLUDE_DIR)/VimbaCPP.mk
|
||||
|
||||
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||
-I$(EXAMPLES_DIR) \
|
||||
|
||||
LIBS = $(VIMBACPP_LIBS)
|
||||
|
||||
DEFINES =
|
||||
|
||||
CFLAGS = $(COMMON_CFLAGS) \
|
||||
$(VIMBACPP_CFLAGS)
|
||||
|
||||
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||
$(OBJ_DIR)/Bitmap.o \
|
||||
$(OBJ_DIR)/program.o
|
||||
|
||||
DEPENDENCIES = VimbaCPP
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJ_DIR)
|
||||
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN_PATH): $(DEPENDENCIES) $(OBJ_FILES) $(BIN_DIR)
|
||||
$(CXX) $(ARCH_CFLAGS) -o $(BIN_PATH) $(OBJ_FILES) $(LIBS) -Wl,-rpath,'$$ORIGIN'
|
||||
|
||||
clean:
|
||||
$(RM) binary -r -f
|
||||
$(RM) object -r -f
|
||||
|
||||
$(OBJ_DIR):
|
||||
$(MKDIR) -p $(OBJ_DIR)
|
||||
|
||||
$(BIN_DIR):
|
||||
$(MKDIR) -p $(BIN_DIR)
|
||||
@@ -0,0 +1,181 @@
|
||||
/*=============================================================================
|
||||
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.cpp
|
||||
|
||||
Description: Implementation file for the ApiController helper class that
|
||||
demonstrates how to implement a synchronous single 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 {
|
||||
|
||||
enum { NUM_FRAMES = 3, };
|
||||
|
||||
ApiController::ApiController()
|
||||
// Get a reference to the Vimba singleton
|
||||
: m_system ( VimbaSystem::GetInstance() )
|
||||
{
|
||||
}
|
||||
|
||||
ApiController::~ApiController()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
// Calls the API convenience function to start single image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to work on
|
||||
// [out] rpFrame The frame that will be filled. Does not need to be initialized.
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::AcquireSingleImage( const std::string &rStrCameraID, FramePtr &rpFrame )
|
||||
{
|
||||
// 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 == m_pCamera->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ))
|
||||
{
|
||||
if ( VmbErrorSuccess == pCommandFeature->RunCommand() )
|
||||
{
|
||||
bool bIsCommandDone = false;
|
||||
do
|
||||
{
|
||||
if ( VmbErrorSuccess != pCommandFeature->IsCommandDone( bIsCommandDone ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while ( false == bIsCommandDone );
|
||||
}
|
||||
}
|
||||
FeaturePtr pFormatFeature;
|
||||
// Set pixel format. For the sake of simplicity we only support Mono and BGR in this example.
|
||||
res = m_pCamera->GetFeatureByName( "PixelFormat", pFormatFeature );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Try to set BGR
|
||||
res = pFormatFeature->SetValue( VmbPixelFormatRgb8 );
|
||||
if ( VmbErrorSuccess != res )
|
||||
{
|
||||
// Fall back to Mono
|
||||
res = pFormatFeature->SetValue( VmbPixelFormatMono8 );
|
||||
}
|
||||
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Acquire
|
||||
res = m_pCamera->AcquireSingleImage( rpFrame, 5000 );
|
||||
}
|
||||
}
|
||||
|
||||
m_pCamera->Close();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// 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();
|
||||
}
|
||||
|
||||
//
|
||||
// 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 );
|
||||
}
|
||||
|
||||
//
|
||||
// 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,112 @@
|
||||
/*=============================================================================
|
||||
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: Implementation file for the ApiController helper class that
|
||||
demonstrates how to implement a synchronous single 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"
|
||||
|
||||
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
|
||||
// Calls the API convenience function to start single image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to work on
|
||||
// [out] rpFrame The frame that will be filled. Does not need to be initialized.
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType AcquireSingleImage( const std::string &rStrCameraID, FramePtr &rpFrame );
|
||||
|
||||
//
|
||||
// Gets all cameras known to Vimba
|
||||
//
|
||||
// Returns:
|
||||
// A vector of camera shared pointers
|
||||
//
|
||||
CameraPtrVector GetCameraList();
|
||||
|
||||
//
|
||||
// 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;
|
||||
};
|
||||
|
||||
}}} // namespace AVT::VmbAPI::Examples
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,267 @@
|
||||
/*=============================================================================
|
||||
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: Bitmap.cpp
|
||||
|
||||
Description: The bitmap class represents a MS(R) Windows(TM) bitmap version 3
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Bitmap.h"
|
||||
|
||||
enum { THREE_CHANNEL = 0xC,};
|
||||
enum { BMP_HEADER_SIZE = 54, };
|
||||
enum { ALIGNMENT_SIZE = 4, };
|
||||
|
||||
//
|
||||
// Creates a MS Windows bitmap with header and color palette.
|
||||
// Fills it with the content of the given byte buffer
|
||||
//
|
||||
// Parameters:
|
||||
// [out] pBitmap A pointer to an AVTBitmap that will get filled
|
||||
// [in] pBuffer The buffer that will be used to fill the created bitmap
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTCreateBitmap( AVTBitmap * const pBitmap, const void* pBuffer )
|
||||
{
|
||||
unsigned char nNumColors; // Number of colors of our image
|
||||
unsigned char nPadLength; // The padding we need to align the bitmap ALIGNMENT_SIZE
|
||||
unsigned long nPaletteSize = 0; // The size of the bitmap's palette
|
||||
unsigned long nHeaderSize; // The size of the bitmap's header
|
||||
unsigned long nFileSize; // The size of the bitmap file
|
||||
unsigned char* pBitmapBuffer; // A buffer we use for creating the bitmap
|
||||
unsigned char* pCurBitmapBuf; // A cursor to move over "pBitmapBuffer"
|
||||
unsigned char* pCurSrc; // A cursor to move over the given buffer "pBuffer"
|
||||
unsigned long px; // A single pixel for storing transformed color information
|
||||
unsigned long x; // The horizontal position within our image
|
||||
unsigned long y; // The vertical position within our image
|
||||
unsigned long i; // Counter for some iteration
|
||||
|
||||
// The bitmap header
|
||||
char fileHeader[14] = { 'B','M', // Default
|
||||
0,0,0,0, // File size
|
||||
0,0,0,0, // Reserved
|
||||
0,0,0,0 }; // Offset to image content
|
||||
char infoHeader[40] = { 40,0,0,0, // Size of info header
|
||||
0,0,0,0, // Width
|
||||
0,0,0,0, // Height
|
||||
1,0, // Default
|
||||
0, 0 }; // bpp
|
||||
|
||||
if ( NULL == pBitmap
|
||||
|| 0 == pBitmap->bufferSize
|
||||
|| 0 == pBitmap->width
|
||||
|| 0 == pBitmap->height )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( pBitmap->colorCode == (pBitmap->colorCode & THREE_CHANNEL) )
|
||||
{
|
||||
nNumColors = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
nNumColors = 1;
|
||||
}
|
||||
|
||||
// Bitmap padding always is a multiple of four Bytes. If data is not we need to pad with zeros.
|
||||
nPadLength = (pBitmap->width * nNumColors) % ALIGNMENT_SIZE;
|
||||
if ( 0 != nPadLength )
|
||||
{
|
||||
nPadLength = ALIGNMENT_SIZE - nPadLength;
|
||||
}
|
||||
|
||||
if ( ColorCodeRGB24 != pBitmap->colorCode )
|
||||
{
|
||||
nPaletteSize = 256;
|
||||
}
|
||||
|
||||
nHeaderSize = BMP_HEADER_SIZE + nPaletteSize * 4;
|
||||
pBitmapBuffer = (unsigned char*)malloc( nHeaderSize + pBitmap->bufferSize + (nPadLength * pBitmap->height) );
|
||||
nFileSize = nHeaderSize + pBitmap->bufferSize + (nPadLength * pBitmap->height);
|
||||
|
||||
// File size
|
||||
fileHeader[ 2] = (char)(nFileSize);
|
||||
fileHeader[ 3] = (char)(nFileSize >> 8);
|
||||
fileHeader[ 4] = (char)(nFileSize >> 16);
|
||||
fileHeader[ 5] = (char)(nFileSize >> 24);
|
||||
// Offset to image content
|
||||
fileHeader[10] = (char)(nHeaderSize);
|
||||
fileHeader[11] = (char)(nHeaderSize >> 8);
|
||||
fileHeader[12] = (char)(nHeaderSize >> 16);
|
||||
fileHeader[13] = (char)(nHeaderSize >> 24);
|
||||
|
||||
// Width
|
||||
infoHeader[ 4] = (char)(pBitmap->width);
|
||||
infoHeader[ 5] = (char)(pBitmap->width >> 8);
|
||||
infoHeader[ 6] = (char)(pBitmap->width >> 16);
|
||||
infoHeader[ 7] = (char)(pBitmap->width >> 24);
|
||||
// Height (has to be negative for a top down image)
|
||||
infoHeader[ 8] = (char)(-(long)pBitmap->height);
|
||||
infoHeader[ 9] = (char)(-(long)pBitmap->height >> 8);
|
||||
infoHeader[10] = (char)(-(long)pBitmap->height >> 16);
|
||||
infoHeader[11] = (char)(-(long)pBitmap->height >> 24);
|
||||
// bpp
|
||||
infoHeader[14] = 8 * nNumColors;
|
||||
// Image size
|
||||
infoHeader[20] = (char)(pBitmap->bufferSize);
|
||||
infoHeader[21] = (char)(pBitmap->bufferSize >> 8);
|
||||
infoHeader[22] = (char)(pBitmap->bufferSize >> 16);
|
||||
infoHeader[23] = (char)(pBitmap->bufferSize >> 24);
|
||||
// Palette size
|
||||
infoHeader[32] = (char)(nPaletteSize);
|
||||
infoHeader[33] = (char)(nPaletteSize >> 8);
|
||||
infoHeader[34] = (char)(nPaletteSize >> 16);
|
||||
infoHeader[35] = (char)(nPaletteSize >> 24);
|
||||
// Used colors
|
||||
infoHeader[36] = (char)(nPaletteSize);
|
||||
infoHeader[37] = (char)(nPaletteSize >> 8);
|
||||
infoHeader[38] = (char)(nPaletteSize >> 16);
|
||||
infoHeader[39] = (char)(nPaletteSize >> 24);
|
||||
|
||||
// Write header
|
||||
pCurBitmapBuf = pBitmapBuffer;
|
||||
memcpy( pCurBitmapBuf, fileHeader, 14 );
|
||||
pCurBitmapBuf += 14;
|
||||
memcpy( pCurBitmapBuf, infoHeader, 40 );
|
||||
pCurBitmapBuf += 40;
|
||||
for(i = 0; i < nPaletteSize; ++i)
|
||||
{
|
||||
pCurBitmapBuf[0] = (char)(i);
|
||||
pCurBitmapBuf[1] = (char)(i);
|
||||
pCurBitmapBuf[2] = (char)(i);
|
||||
pCurBitmapBuf[3] = 0;
|
||||
pCurBitmapBuf += 4;
|
||||
}
|
||||
|
||||
// RGB -> BGR (a Windows bitmap is BGR)
|
||||
if ( ColorCodeRGB24 == pBitmap->colorCode )
|
||||
{
|
||||
pCurSrc = (unsigned char*)pBuffer;
|
||||
for ( y=0; y<pBitmap->height; ++y, pCurBitmapBuf+=nPadLength )
|
||||
{
|
||||
for ( x = 0;
|
||||
x < pBitmap->width;
|
||||
++x,
|
||||
pCurSrc += 3,
|
||||
pCurBitmapBuf += 3 )
|
||||
{
|
||||
px = 0;
|
||||
// Create a 4 Byte structure to store ARGB (we don't use A)
|
||||
px = px | (pCurSrc[0] << 16) | (pCurSrc[1] << 8) | pCurSrc[2];
|
||||
// Due to endianess ARGB is stored as BGRA
|
||||
// and we only have to write the first three Bytes
|
||||
memcpy( pCurBitmapBuf, &px, 3 );
|
||||
}
|
||||
// Add padding at the end of each row
|
||||
memset( pCurBitmapBuf, 0, nPadLength );
|
||||
}
|
||||
pBitmap->colorCode = ColorCodeBGR24;
|
||||
}
|
||||
// Mono8
|
||||
else
|
||||
{
|
||||
if ( 0 == nPadLength )
|
||||
{
|
||||
memcpy( pCurBitmapBuf, pBuffer, pBitmap->bufferSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
pCurSrc = (unsigned char*)pBuffer;
|
||||
for ( y=0;
|
||||
y<pBitmap->height;
|
||||
++y,
|
||||
pCurSrc += pBitmap->width * nNumColors )
|
||||
{
|
||||
// Write a single row of colored pixels
|
||||
memcpy( pCurBitmapBuf, pCurSrc, pBitmap->width * nNumColors );
|
||||
pCurBitmapBuf += pBitmap->width * nNumColors;
|
||||
// Write padding pixels
|
||||
memset( pCurBitmapBuf, 0, nPadLength );
|
||||
pCurBitmapBuf += nPadLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pBitmap->buffer = pBitmapBuffer;
|
||||
pBitmap->bufferSize = nFileSize;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Releases (frees) a given bitmap
|
||||
//
|
||||
// Parameters:
|
||||
// [in, out] pBitmap The bitmap whose memory will be freed
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTReleaseBitmap( AVTBitmap * const pBitmap )
|
||||
{
|
||||
if ( NULL != pBitmap
|
||||
&& NULL != pBitmap->buffer
|
||||
&& 0 < pBitmap->bufferSize )
|
||||
{
|
||||
free( pBitmap->buffer );
|
||||
pBitmap->buffer = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Writes a given bitmap to file
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pBitmap The AVTBitmap to write to file
|
||||
// [in] pFileName The destination (complete path) where to write the bitmap to
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTWriteBitmapToFile( AVTBitmap const * const pBitmap, char const * const pFileName )
|
||||
{
|
||||
FILE *file;
|
||||
if ( NULL != pBitmap
|
||||
&& NULL != pBitmap->buffer
|
||||
&& NULL != pFileName )
|
||||
{
|
||||
file = fopen(pFileName, "wb");
|
||||
fwrite(pBitmap->buffer, 1, pBitmap->bufferSize, file );
|
||||
fclose(file);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*=============================================================================
|
||||
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: Bitmap.h
|
||||
|
||||
Description: The bitmap class represents a MS(R) Windows(TM) bitmap version 3
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
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_BITMAP_H
|
||||
#define AVT_BITMAP_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ColorCodeMono8 = 1,
|
||||
ColorCodeMono16 = 2,
|
||||
ColorCodeBGR24 = 4,
|
||||
ColorCodeRGB24 = 8
|
||||
} ColorCode;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void* buffer;
|
||||
unsigned long bufferSize;
|
||||
unsigned long width;
|
||||
unsigned long height;
|
||||
ColorCode colorCode;
|
||||
} AVTBitmap;
|
||||
|
||||
//
|
||||
// Creates a MS Windows bitmap with header and color palette.
|
||||
// Fills it with the content of the given byte buffer
|
||||
//
|
||||
// Parameters:
|
||||
// [out] pBitmap A pointer to an AVTBitmap that will get filled
|
||||
// [in] pBuffer The buffer that will be used to fill the created bitmap
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTCreateBitmap( AVTBitmap * const pBitmap, const void* pBuffer );
|
||||
|
||||
//
|
||||
// Releases (frees) a given bitmap
|
||||
//
|
||||
// Parameters:
|
||||
// [in, out] pBitmap The bitmap whose memory will be freed
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTReleaseBitmap( AVTBitmap * const pBitmap );
|
||||
|
||||
//
|
||||
// Writes a given bitmap to file
|
||||
//
|
||||
// Parameters:
|
||||
// [in] pBitmap The AVTBitmap to write to file
|
||||
// [in] pFileName The destination (complete path) where to write the bitmap to
|
||||
//
|
||||
// Returns:
|
||||
// 0 in case of error
|
||||
// 1 in case of success
|
||||
//
|
||||
unsigned char AVTWriteBitmapToFile( AVTBitmap const * const pBitmap, char const * const pFileName );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,287 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2013 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 SynchronousGrabConsole
|
||||
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 "ApiController.h"
|
||||
#include "Bitmap.h"
|
||||
|
||||
unsigned char StartsWith(const char *pString, const char *pStart)
|
||||
{
|
||||
if(NULL == pString)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(NULL == pStart)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(std::strlen(pString) < std::strlen(pStart))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(std::memcmp(pString, pStart, std::strlen(pStart)) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
VmbErrorType err = VmbErrorSuccess;
|
||||
|
||||
char * pCameraID = NULL; // The ID of the camera to use
|
||||
const char * pFileName = NULL; // The filename for the bitmap to save
|
||||
bool bPrintHelp = false; // Output help?
|
||||
int i; // Counter for some iteration
|
||||
char * pParameter; // The command line parameter
|
||||
|
||||
std::cout << "//////////////////////////////////////////\n";
|
||||
std::cout << "/// Vimba API Synchronous Grab Example ///\n";
|
||||
std::cout << "//////////////////////////////////////////\n\n";
|
||||
|
||||
//////////////////////
|
||||
//Parse command line//
|
||||
//////////////////////
|
||||
|
||||
for( i = 1; i < argc; ++i )
|
||||
{
|
||||
pParameter = argv[i];
|
||||
if( 0 > std::strlen( pParameter ))
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
if( '/' == pParameter[0] )
|
||||
{
|
||||
if( StartsWith( pParameter, "/f:" ))
|
||||
{
|
||||
if( NULL != pFileName )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
pFileName = pParameter + 3;
|
||||
if( 0 >= std::strlen( pFileName ))
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( 0 == std::strcmp( pParameter, "/h" ))
|
||||
{
|
||||
if( ( NULL != pCameraID )
|
||||
|| ( NULL != pFileName )
|
||||
|| ( bPrintHelp ))
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
bPrintHelp = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( NULL != pCameraID )
|
||||
{
|
||||
err = VmbErrorBadParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
pCameraID = pParameter;
|
||||
}
|
||||
}
|
||||
|
||||
//Write out an error if we could not parse the command line
|
||||
if ( VmbErrorBadParameter == err )
|
||||
{
|
||||
std::cout << "Invalid parameters!\n\n";
|
||||
bPrintHelp = true;
|
||||
}
|
||||
|
||||
//Print out help and end program
|
||||
if ( bPrintHelp )
|
||||
{
|
||||
std::cout << "Usage: SynchronousGrab [CameraID] [/h] [/f:FileName]\n";
|
||||
std::cout << "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n";
|
||||
std::cout << " /h Print out help\n";
|
||||
std::cout << " /f:FileName File name for operation\n";
|
||||
std::cout << " (default \"SynchronousGrab.bmp\" if not specified)\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( NULL == pFileName )
|
||||
{
|
||||
pFileName = "SynchronousGrab.bmp";
|
||||
}
|
||||
|
||||
AVT::VmbAPI::Examples::ApiController apiController;
|
||||
|
||||
std::cout << "Vimba C++ API Version " << apiController.GetVersion() << "\n";
|
||||
|
||||
VmbFrameStatusType status = VmbFrameStatusIncomplete;
|
||||
err = apiController.StartUp();
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
std::string strCameraID;
|
||||
if ( NULL == pCameraID )
|
||||
{
|
||||
AVT::VmbAPI::CameraPtrVector cameras = apiController.GetCameraList();
|
||||
if ( cameras.size() <= 0 )
|
||||
{
|
||||
err = VmbErrorNotFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = cameras[0]->GetID( strCameraID );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
strCameraID = pCameraID;
|
||||
}
|
||||
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
std::cout << "Camera ID:" << strCameraID.c_str() << "\n\n";
|
||||
|
||||
AVT::VmbAPI::FramePtr pFrame;
|
||||
err = apiController.AcquireSingleImage( strCameraID, pFrame );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
err = pFrame->GetReceiveStatus( status );
|
||||
if ( VmbErrorSuccess == err
|
||||
&& VmbFrameStatusComplete == status )
|
||||
{
|
||||
VmbPixelFormatType ePixelFormat = VmbPixelFormatMono8;
|
||||
err = pFrame->GetPixelFormat( ePixelFormat );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
if ( ( VmbPixelFormatMono8 != ePixelFormat )
|
||||
&& ( VmbPixelFormatRgb8 != ePixelFormat ))
|
||||
{
|
||||
err = VmbErrorInvalidValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
VmbUint32_t nImageSize = 0;
|
||||
err = pFrame->GetImageSize( nImageSize );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbUint32_t nWidth = 0;
|
||||
err = pFrame->GetWidth( nWidth );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbUint32_t nHeight = 0;
|
||||
err = pFrame->GetHeight( nHeight );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbUchar_t *pImage = NULL;
|
||||
err = pFrame->GetImage( pImage );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
AVTBitmap bitmap;
|
||||
|
||||
if ( VmbPixelFormatRgb8 == ePixelFormat )
|
||||
{
|
||||
bitmap.colorCode = ColorCodeRGB24;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap.colorCode = ColorCodeMono8;
|
||||
}
|
||||
|
||||
bitmap.bufferSize = nImageSize;
|
||||
bitmap.width = nWidth;
|
||||
bitmap.height = nHeight;
|
||||
|
||||
// Create the bitmap
|
||||
if ( 0 == AVTCreateBitmap( &bitmap, pImage ))
|
||||
{
|
||||
std::cout << "Could not create bitmap.\n";
|
||||
err = VmbErrorResources;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Save the bitmap
|
||||
if ( 0 == AVTWriteBitmapToFile( &bitmap, pFileName ))
|
||||
{
|
||||
std::cout << "Could not write bitmap to file.\n";
|
||||
err = VmbErrorOther;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Bitmap successfully written to file \"" << pFileName << "\"\n" ;
|
||||
// Release the bitmap's buffer
|
||||
if ( 0 == AVTReleaseBitmap( &bitmap ))
|
||||
{
|
||||
std::cout << "Could not release the bitmap.\n";
|
||||
err = VmbErrorInternalFault;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apiController.ShutDown();
|
||||
}
|
||||
|
||||
if ( VmbErrorSuccess != err )
|
||||
{
|
||||
std::string strError = apiController.ErrorCodeToMessage( err );
|
||||
std::cout << "\nAn error occurred: " << strError.c_str() << "\n";
|
||||
}
|
||||
if( VmbFrameStatusIncomplete == status)
|
||||
{
|
||||
std::cout<<"received frame was not complete\n";
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
PROJECT_NAME = SynchronousGrabQt
|
||||
|
||||
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)/Qt.mk
|
||||
|
||||
SOURCE_DIR = $(PROJECT_DIR)/Source
|
||||
INCLUDE_DIRS = -I$(SOURCE_DIR) \
|
||||
-I$(EXAMPLES_DIR) \
|
||||
-I$(OBJ_DIR)
|
||||
|
||||
LIBS = $(VIMBACPP_LIBS) \
|
||||
$(QTCORE_LIBS) \
|
||||
$(QTGUI_LIBS)
|
||||
|
||||
DEFINES =
|
||||
|
||||
CFLAGS = $(COMMON_CFLAGS) \
|
||||
$(VIMBACPP_CFLAGS) \
|
||||
$(QTCORE_CFLAGS) \
|
||||
$(QTGUI_CFLAGS)
|
||||
|
||||
OBJ_FILES = $(OBJ_DIR)/ApiController.o \
|
||||
$(OBJ_DIR)/SynchronousGrab.o \
|
||||
$(OBJ_DIR)/CameraObserver.o \
|
||||
$(OBJ_DIR)/main.o \
|
||||
$(OBJ_DIR)/moc_SynchronousGrab.o \
|
||||
$(OBJ_DIR)/moc_CameraObserver.o \
|
||||
$(OBJ_DIR)/qrc_SynchronousGrab.o
|
||||
|
||||
GEN_HEADERS = $(OBJ_DIR)/ui_SynchronousGrab.h
|
||||
|
||||
DEPENDENCIES = VimbaCPP \
|
||||
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,256 @@
|
||||
/*=============================================================================
|
||||
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 a synchronous single 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 {
|
||||
|
||||
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
|
||||
m_pCameraObserver = new CameraObserver();
|
||||
// Register an observer whose callback routine gets triggered whenever a camera is plugged in or out
|
||||
res = m_system.RegisterCameraListObserver( ICameraListObserverPtr( m_pCameraObserver ));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// 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
|
||||
// Calls the API convenience function to start single image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to work on
|
||||
// [out] rpFrame The frame that will be filled. Does not need to be initialized.
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType ApiController::AcquireSingleImage( const std::string &rStrCameraID, FramePtr &rpFrame )
|
||||
{
|
||||
// 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 == m_pCamera->GetFeatureByName( "GVSPAdjustPacketSize", pCommandFeature ))
|
||||
{
|
||||
if ( VmbErrorSuccess == pCommandFeature->RunCommand() )
|
||||
{
|
||||
bool bIsCommandDone = false;
|
||||
do
|
||||
{
|
||||
if ( VmbErrorSuccess != pCommandFeature->IsCommandDone( bIsCommandDone ))
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while ( false == bIsCommandDone );
|
||||
}
|
||||
}
|
||||
FeaturePtr pFormatFeature;
|
||||
// Save the current width
|
||||
res = m_pCamera->GetFeatureByName( "Width", pFormatFeature );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
res = pFormatFeature->GetValue( m_nWidth );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Save the current height
|
||||
res = m_pCamera->GetFeatureByName( "Height", pFormatFeature );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
pFormatFeature->GetValue( this->m_nHeight );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Set pixel format. For the sake of simplicity we only support Mono and RGB in this example.
|
||||
res = m_pCamera->GetFeatureByName( "PixelFormat", pFormatFeature );
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Try to set RGB
|
||||
res = pFormatFeature->SetValue( VmbPixelFormatRgb8 );
|
||||
if ( VmbErrorSuccess != res )
|
||||
{
|
||||
// Fall back to Mono
|
||||
res = pFormatFeature->SetValue( VmbPixelFormatMono8 );
|
||||
}
|
||||
|
||||
// Read back the currently selected pixel format
|
||||
pFormatFeature->GetValue( m_nPixelFormat );
|
||||
|
||||
if ( VmbErrorSuccess == res )
|
||||
{
|
||||
// Acquire
|
||||
res = m_pCamera->AcquireSingleImage( rpFrame, 2000 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_pCamera->Close();
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
//
|
||||
// Calls the API convenience function to stop image acquisition
|
||||
// Closes the camera
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
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 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 );
|
||||
}
|
||||
|
||||
//
|
||||
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* ApiController::GetCameraObserver()
|
||||
{
|
||||
return m_pCameraObserver;
|
||||
}
|
||||
|
||||
//
|
||||
// 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,152 @@
|
||||
/*=============================================================================
|
||||
Copyright (C) 2012 - 2016 Allied Vision Technologies. All Rights Reserved.
|
||||
|
||||
Redistribution of this file, in original or modified form, without
|
||||
prior written consent of Allied Vision Technologies is prohibited.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
File: ApiController.h
|
||||
|
||||
Description: Implementation file for the ApiController helper class that
|
||||
demonstrates how to implement a synchronous single 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"
|
||||
|
||||
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
|
||||
// Calls the API convenience function to start single image acquisition
|
||||
// Closes the camera in case of failure
|
||||
//
|
||||
// Parameters:
|
||||
// [in] rStrCameraID The ID of the camera to work on
|
||||
// [out] rpFrame The frame that will be filled. Does not need to be initialized.
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
VmbErrorType AcquireSingleImage( const std::string &rStrCameraID, FramePtr &rpFrame );
|
||||
|
||||
//
|
||||
// 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;
|
||||
|
||||
//
|
||||
// Calls the API convenience function to stop image acquisition
|
||||
// Closes the camera
|
||||
//
|
||||
// Returns:
|
||||
// An API status code
|
||||
//
|
||||
CameraPtrVector GetCameraList() const;
|
||||
|
||||
//
|
||||
// Returns the frame observer as QObject pointer to connect their signals to the view's slots
|
||||
//
|
||||
QObject* GetCameraObserver();
|
||||
|
||||
//
|
||||
// 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;
|
||||
// Our camera observer
|
||||
CameraObserver* 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,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,268 @@
|
||||
/*=============================================================================
|
||||
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: SynchronousGrab.cpp
|
||||
|
||||
Description: Qt dialog class for the GUI of the SynchronousGrab 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 "SynchronousGrab.h"
|
||||
using AVT::VmbAPI::FramePtr;
|
||||
using AVT::VmbAPI::CameraPtrVector;
|
||||
|
||||
enum { NUM_COLORS = 3, };
|
||||
enum { BIT_DEPTH = 8, };
|
||||
|
||||
SynchronousGrab::SynchronousGrab(QWidget *parent, Qt::WindowFlags flags)
|
||||
: QMainWindow(parent, flags)
|
||||
, m_pApiController( new ApiController() )
|
||||
{
|
||||
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_pApiController->StartUp();
|
||||
Log( "Starting Vimba", err );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
std::string WindowText("SynchronousGrab (Qt version) Vimba C++ API Version ");
|
||||
WindowText += m_pApiController->GetVersion();
|
||||
this->setWindowTitle( QString::fromStdString(WindowText) );
|
||||
// Connect new camera found event with event handler
|
||||
QObject::connect( m_pApiController->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() );
|
||||
}
|
||||
}
|
||||
|
||||
SynchronousGrab::~SynchronousGrab()
|
||||
{
|
||||
// Before we close the application we stop Vimba
|
||||
m_pApiController->ShutDown();
|
||||
|
||||
delete m_pApiController;
|
||||
m_pApiController = NULL;
|
||||
}
|
||||
|
||||
void SynchronousGrab::OnBnClickedButtonStartstop()
|
||||
{
|
||||
VmbErrorType err;
|
||||
int nRow = ui.m_ListBoxCameras->currentRow();
|
||||
|
||||
if ( -1 < nRow )
|
||||
{
|
||||
// Get the frame
|
||||
FramePtr pFrame;
|
||||
err = m_pApiController->AcquireSingleImage( m_cameras[nRow], pFrame );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
// See if it is not corrupt
|
||||
VmbFrameStatusType eReceiveStatus;
|
||||
err = pFrame->GetReceiveStatus( eReceiveStatus );
|
||||
if ( VmbErrorSuccess == err
|
||||
&& VmbFrameStatusComplete == eReceiveStatus )
|
||||
{
|
||||
// Set up Qt image
|
||||
QImage tmpImage( m_pApiController->GetWidth(),
|
||||
m_pApiController->GetHeight(),
|
||||
VmbPixelFormatRgb8 == m_pApiController->GetPixelFormat() ? QImage::Format_RGB888 : QImage::Format_Indexed8 );
|
||||
|
||||
if(VmbPixelFormatRgb8 != m_pApiController->GetPixelFormat())
|
||||
{
|
||||
tmpImage.setNumColors(256);
|
||||
for(int i = 0; i < 256; i++)
|
||||
{
|
||||
tmpImage.setColor(i, qRgb(i, i, i));
|
||||
}
|
||||
}
|
||||
|
||||
VmbUchar_t *pBuffer;
|
||||
err = pFrame->GetImage( pBuffer );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbUint32_t nSize;
|
||||
err = pFrame->GetImageSize( nSize );
|
||||
if ( VmbErrorSuccess == err )
|
||||
{
|
||||
VmbPixelFormatType ePixelFormat = m_pApiController->GetPixelFormat();
|
||||
if ( VmbPixelFormatMono8 == ePixelFormat
|
||||
|| VmbPixelFormatRgb8 == ePixelFormat )
|
||||
{
|
||||
// Copy it
|
||||
// We need that because Qt might repaint the view after we have released the frame already
|
||||
CopyToImage( pBuffer, tmpImage );
|
||||
|
||||
// Display it
|
||||
QSize s= ui.m_LabelStream->size();
|
||||
ui.m_LabelStream->setPixmap( QPixmap::fromImage( tmpImage ).scaled( s, Qt::KeepAspectRatio) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log( "Starting Acquisition", err );
|
||||
m_bIsStreaming = VmbErrorSuccess == err;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we receive an incomplete image we do nothing
|
||||
err = VmbErrorOther;
|
||||
}
|
||||
}
|
||||
Log( "Acquire single image", err );
|
||||
}
|
||||
else
|
||||
{
|
||||
Log( "Please select a camera." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// 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 SynchronousGrab::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." );
|
||||
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
|
||||
// [out] OutImage The filled Qt image
|
||||
//
|
||||
void SynchronousGrab::CopyToImage( VmbUchar_t *pInBuffer, QImage &OutImage )
|
||||
{
|
||||
VmbUchar_t * pCursor = OutImage.bits();
|
||||
int nHeight = m_pApiController->GetHeight();
|
||||
int nWidth = QImage::Format_Indexed8 == OutImage.format()
|
||||
? m_pApiController->GetWidth()
|
||||
: m_pApiController->GetWidth() * NUM_COLORS;
|
||||
|
||||
if ( OutImage.bytesPerLine() != nWidth )
|
||||
{
|
||||
for ( int y=0; y<nHeight; ++y )
|
||||
{
|
||||
pCursor = OutImage.scanLine( y );
|
||||
for ( int x=0; x<nWidth; ++x )
|
||||
{
|
||||
*pCursor = *pInBuffer;
|
||||
++pCursor;
|
||||
++pInBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy( OutImage.bits(), pInBuffer, nWidth * nHeight );
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Queries and lists all known camera
|
||||
//
|
||||
void SynchronousGrab::UpdateCameraListBox()
|
||||
{
|
||||
// Get all cameras currently connected to Vimba
|
||||
CameraPtrVector cameras = m_pApiController->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 SynchronousGrab::Log( std::string strMsg, VmbErrorType eErr )
|
||||
{
|
||||
strMsg += "..." + m_pApiController->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 SynchronousGrab::Log( std::string strMsg )
|
||||
{
|
||||
ui.m_ListLog->insertItem( 0, QString::fromStdString( strMsg ) );
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*=============================================================================
|
||||
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: SynchronousGrab.cpp
|
||||
|
||||
Description: Qt dialog class for the GUI of the SynchronousGrab 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 SYNCHRONOUSGRABQT_H
|
||||
#define SYNCHRONOUSGRABQT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "ui_SynchronousGrab.h"
|
||||
|
||||
#include "ApiController.h"
|
||||
|
||||
using AVT::VmbAPI::Examples::ApiController;
|
||||
|
||||
class SynchronousGrab : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SynchronousGrab(QWidget *parent = 0, Qt::WindowFlags flags = 0);
|
||||
~SynchronousGrab();
|
||||
|
||||
private:
|
||||
Ui::SynchronousGrabClass ui;
|
||||
// Our controller that wraps API access
|
||||
ApiController * m_pApiController;
|
||||
// A list of known camera IDs
|
||||
std::vector<std::string> m_cameras;
|
||||
// Are we streaming?
|
||||
bool m_bIsStreaming;
|
||||
|
||||
//
|
||||
// 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
|
||||
// [out] OutImage The filled Qt image
|
||||
//
|
||||
void CopyToImage( VmbUchar_t *pInBuffer, QImage &OutImage );
|
||||
|
||||
private slots:
|
||||
void OnBnClickedButtonStartstop();
|
||||
|
||||
//
|
||||
// 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 // SYNCHRONOUSGRABQT_H
|
||||
@@ -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 SynchronousGrab 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 "SynchronousGrab.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
SynchronousGrab w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/SynchronousGrabQt">
|
||||
<file>SynchronousGrab.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SynchronousGrabClass</class>
|
||||
<widget class="QMainWindow" name="SynchronousGrabClass">
|
||||
<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>SynchronousGrab (Qt version)</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="SynchronousGrab.qrc">
|
||||
<normaloff>:/SynchronousGrabQt/SynchronousGrab.png</normaloff>:/SynchronousGrabQt/SynchronousGrab.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>521</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>Acquire Single Image</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>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
<include location="SynchronousGrab.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user