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