AVT相机arm版本SDK

This commit is contained in:
zhangpeng
2025-04-30 09:26:04 +08:00
parent 837c870f18
commit 78a1c63a95
705 changed files with 148770 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
PROJECT_NAME = SynchronousGrab
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)/VimbaC.mk
SOURCE_DIR = $(PROJECT_DIR)/Source
COMMON_DIR = $(EXAMPLES_DIR)/Common
INCLUDE_DIRS = -I$(SOURCE_DIR) \
-I$(EXAMPLES_DIR) \
LIBS = $(VIMBAC_LIBS)
DEFINES =
CFLAGS = $(COMMON_CFLAGS) \
$(VIMBAC_CFLAGS)
OBJ_FILES = $(OBJ_DIR)/Bitmap.o \
$(OBJ_DIR)/SynchronousGrab.o \
$(OBJ_DIR)/program.o \
$(OBJ_DIR)/PrintVimbaVersion.o \
$(OBJ_DIR)/ErrorCodeToMessage.o \
$(OBJ_DIR)/DiscoverGigECameras.o
DEPENDENCIES = VimbaC
$(OBJ_DIR)/%.o: $(COMMON_DIR)/%.c $(OBJ_DIR)
$(CXX) -c $(INCLUDE_DIRS) $(DEFINES) $(CFLAGS) -o $@ $<
$(OBJ_DIR)/%.o: $(SOURCE_DIR)/%.c $(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)

View File

@@ -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.c
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>
#define THREE_CHANNEL 0xC
#define BMP_HEADER_SIZE 54
#define 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 = 0; // Number of colors of our image
unsigned char nPadLength = 0; // The padding we need to align the bitmap ALIGNMENT_SIZE
unsigned long nPaletteSize = 0; // The size of the bitmap's palette
unsigned long nHeaderSize = 0; // The size of the bitmap's header
unsigned long nFileSize = 0; // The size of the bitmap file
unsigned char* pBitmapBuffer = 0; // A buffer we use for creating the bitmap
unsigned char* pCurBitmapBuf = 0; // A cursor to move over "pBitmapBuffer"
unsigned char* pCurSrc = 0; // A cursor to move over the given buffer "pBuffer"
unsigned long px = 0; // A single pixel for storing transformed color information
unsigned long x = 0; // The horizontal position within our image
unsigned long y = 0; // The vertical position within our image
unsigned long i = 0; // 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;
}

View File

@@ -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

View File

@@ -0,0 +1,318 @@
/*=============================================================================
Copyright (C) 2012 - 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: SynchronousGrab.cpp
Description: The SynchronousGrab example will grab a single image
synchronously and save it to a file using VimbaC.
-------------------------------------------------------------------------------
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 <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <VimbaC/Include/VimbaC.h>
#include "../../Common/PrintVimbaVersion.h"
#include "../../Common/DiscoverGigECameras.h"
#include <SynchronousGrab.h>
#include <Bitmap.h>
//
// Starts Vimba API
// Opens the given camera, if no camera ID was provided, the first camera found will be used
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Acquires one image synchronously
// Writes the image as bitmap to file
// Closes the camera in case of failure
//
// Parameters:
// [in] pCameraID The ID of the camera to work on. Can be NULL.
// [in] pFileName The path of the bitmap where the image is saved to
//
// Returns:
// An API status code
//
VmbError_t SynchronousGrab( const char* pCameraID, const char* pFileName )
{
VmbError_t err = VmbStartup(); // Initialize the Vimba API
VmbCameraInfo_t *pCameras = NULL; // A list of camera details
VmbUint32_t nCount = 0; // Number of found cameras
VmbUint32_t nFoundCount = 0; // Change of found cameras
const VmbUint32_t nTimeout = 2000; // Timeout for Grab
VmbAccessMode_t cameraAccessMode = VmbAccessModeFull;// We open the camera with full access
VmbHandle_t cameraHandle = NULL; // A handle to our camera
VmbBool_t bIsCommandDone = VmbBoolFalse; // Has a command finished execution
VmbFrame_t frame; // The frame we capture
const char* pPixelFormat = NULL; // The pixel format we use for acquisition
VmbInt64_t nPayloadSize = 0; // The size of one frame
AVTBitmap bitmap; // The bitmap we create
PrintVimbaVersion();
if ( VmbErrorSuccess == err )
{
// Is Vimba connected to a GigE transport layer?
DiscoverGigECameras();
// If no camera ID was provided use the first camera found
if ( NULL == pCameraID )
{
// Get the amount of known cameras
err = VmbCamerasList( NULL, 0, &nCount, sizeof *pCameras );
if ( VmbErrorSuccess == err
&& 0 < nCount )
{
pCameras = (VmbCameraInfo_t*)malloc( nCount * sizeof( *pCameras ));
if ( NULL != pCameras )
{
// Actually query all static details of all known cameras without having to open the cameras
// If a new camera was connected since we queried the amount of cameras (nFoundCount > nCount) we can ignore that one
err = VmbCamerasList( pCameras, nCount, &nFoundCount, sizeof *pCameras );
if ( VmbErrorSuccess != err
&& VmbErrorMoreData != err )
{
printf( "Could not list cameras. Error code: %d\n", err );
}
else
{
// Use the first camera
if( nFoundCount != 0)
{
pCameraID = pCameras[0].cameraIdString;
}
else
{
pCameraID = NULL;
err = VmbErrorNotFound;
printf( "Camera lost.\n" );
}
}
free( pCameras );
pCameras = NULL;
}
else
{
printf( "Could not allocate camera list.\n" );
}
}
else
{
printf( "Could not list cameras or no cameras present. Error code: %d\n", err );
}
}
if ( NULL != pCameraID )
{
// Open camera
err = VmbCameraOpen( pCameraID, cameraAccessMode, &cameraHandle );
if ( VmbErrorSuccess == err )
{
printf( "Camera ID: %s\n\n", pCameraID );
// 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)
if ( VmbErrorSuccess == VmbFeatureCommandRun( cameraHandle, "GVSPAdjustPacketSize" ))
{
do
{
if ( VmbErrorSuccess != VmbFeatureCommandIsDone( cameraHandle,
"GVSPAdjustPacketSize",
&bIsCommandDone ))
{
break;
}
} while ( VmbBoolFalse == bIsCommandDone );
}
if ( VmbErrorSuccess == err )
{
// Set pixel format. For the sake of simplicity we only support Mono and RGB in this example.
err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "RGB8Packed" );
if ( VmbErrorSuccess != err )
{
// Fall back to Mono
err = VmbFeatureEnumSet( cameraHandle, "PixelFormat", "Mono8" );
}
// Read back pixel format
VmbFeatureEnumGet( cameraHandle, "PixelFormat", &pPixelFormat );
if ( VmbErrorSuccess == err )
{
// Evaluate frame size
err = VmbFeatureIntGet( cameraHandle, "PayloadSize", &nPayloadSize );
if ( VmbErrorSuccess == err )
{
frame.buffer = (unsigned char*)malloc( (VmbUint32_t)nPayloadSize );
frame.bufferSize = (VmbUint32_t)nPayloadSize;
// Announce Frame
err = VmbFrameAnnounce( cameraHandle, &frame, (VmbUint32_t)sizeof( VmbFrame_t ));
if ( VmbErrorSuccess == err )
{
// Start Capture Engine
err = VmbCaptureStart( cameraHandle );
if ( VmbErrorSuccess == err )
{
// Queue Frame
err = VmbCaptureFrameQueue( cameraHandle, &frame, NULL );
if ( VmbErrorSuccess == err )
{
// Start Acquisition
err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStart" );
if ( VmbErrorSuccess == err )
{
// Capture one frame synchronously
err = VmbCaptureFrameWait( cameraHandle, &frame, nTimeout );
if ( VmbErrorSuccess == err )
{
// Convert the captured frame to a bitmap and save to disk
if ( VmbFrameStatusComplete == frame.receiveStatus )
{
bitmap.bufferSize = frame.imageSize;
bitmap.width = frame.width;
bitmap.height = frame.height;
// We only support Mono and RGB in this example
if ( 0 == strcmp( "RGB8Packed", pPixelFormat ))
{
bitmap.colorCode = ColorCodeRGB24;
}
else
{
bitmap.colorCode = ColorCodeMono8;
}
// Create the bitmap
if ( 0 == AVTCreateBitmap( &bitmap, frame.buffer ))
{
printf( "Could not create bitmap.\n" );
}
else
{
// Save the bitmap
if ( 0 == AVTWriteBitmapToFile( &bitmap, pFileName ))
{
printf( "Could not write bitmap to file.\n" );
}
else
{
printf( "Bitmap successfully written to file \"%s\"\n", pFileName );
// Release the bitmap's buffer
if ( 0 == AVTReleaseBitmap( &bitmap ))
{
printf( "Could not release the bitmap.\n" );
}
}
}
}
else
{
printf( "Frame not successfully received. Error code: %d\n", frame.receiveStatus );
}
}
else
{
printf( "Could not capture frame. Error code: %d\n", err );
}
// Stop Acquisition
err = VmbFeatureCommandRun( cameraHandle,"AcquisitionStop" );
if ( VmbErrorSuccess != err )
{
printf( "Could not stop acquisition. Error code: %d\n", err );
}
}
else
{
printf( "Could not start acquisition. Error code: %d\n", err );
}
}
else
{
printf( "Could not queue frame. Error code: %d\n", err );
}
// Stop Capture Engine
err = VmbCaptureEnd( cameraHandle );
if ( VmbErrorSuccess != err )
{
printf( "Could not end capture. Error code: %d\n", err );
}
}
else
{
printf( "Could not start capture. Error code: %d\n", err );
}
// Revoke frame
err = VmbFrameRevoke( cameraHandle, &frame );
if ( VmbErrorSuccess != err )
{
printf( "Could not revoke frame. Error code: %d\n", err );
}
}
else
{
printf( "Could not announce frame. Error code: %d\n", err );
}
free( frame.buffer );
frame.buffer = NULL;
}
}
else
{
printf( "Could not set pixel format to either RGB or Mono. Error code: %d\n", err );
}
}
else
{
printf( "Could not adjust packet size. Error code: %d\n", err );
}
err = VmbCameraClose ( cameraHandle );
if ( VmbErrorSuccess != err )
{
printf( "Could not close camera. Error code: %d\n", err );
}
}
else
{
printf( "Could not open camera. Error code: %d\n", err );
}
}
VmbShutdown();
}
else
{
printf( "Could not start system. Error code: %d\n", err );
}
return err;
}

View File

@@ -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: SynchronousGrab.h
Description: The SynchronousGrab example will grab a single image
synchronously and save it to a file using VimbaC.
-------------------------------------------------------------------------------
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 SYNCHRONOUS_GRAB_H_
#define SYNCHRONOUS_GRAB_H_
#include <VimbaC/Include/VmbCommonTypes.h>
//
// Starts Vimba API
// Opens the given camera, if no camera ID was provided, the first camera found will be used
// Sets the maximum possible Ethernet packet size
// Adjusts the image format
// Acquires one image synchronously
// Writes the image as bitmap to file
// Closes the camera in case of failure
//
// Parameters:
// [in] pCameraID The ID of the camera to work on. Can be NULL.
// [in] pFileName The path of the bitmap where the image is saved to
//
// Returns:
// An API status code
//
VmbError_t SynchronousGrab ( const char* pCameraID, const char* pFileName );
#endif

View File

@@ -0,0 +1,159 @@
/*=============================================================================
Copyright (C) 2012 - 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 SynchronousGrab example of
VimbaC.
-------------------------------------------------------------------------------
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 <SynchronousGrab.h>
unsigned char StartsWith(const char *pString, const char *pStart)
{
if(NULL == pString)
{
return 0;
}
if(NULL == pStart)
{
return 0;
}
if(strlen(pString) < strlen(pStart))
{
return 0;
}
if(memcmp(pString, pStart, strlen(pStart)) != 0)
{
return 0;
}
return 1;
}
int main( int argc, char* argv[] )
{
VmbError_t err = VmbErrorSuccess;
char* pCameraID = NULL; // The ID of the camera to use
const char* pFileName = NULL; // The filename for the bitmap to save
unsigned char bPrintHelp = 0; // Output help?
int i = 0; // Counter for some iteration
char* pParameter = 0; // The command line parameter
printf( "//////////////////////////////////////////\n" );
printf( "/// Vimba API Synchronous Grab Example ///\n" );
printf( "//////////////////////////////////////////\n\n" );
//////////////////////
//Parse command line//
//////////////////////
for( i = 1; i < argc; ++i )
{
pParameter = argv[i];
if( 0 > strlen( pParameter ))
{
err = VmbErrorBadParameter;
break;
}
if( '/' == pParameter[0] )
{
if( StartsWith( pParameter, "/f:" ))
{
if( NULL != pFileName )
{
err = VmbErrorBadParameter;
break;
}
pFileName = pParameter + 3;
if( 0 >= strlen( pFileName ))
{
err = VmbErrorBadParameter;
break;
}
}
else if( 0 == strcmp( pParameter, "/h" ))
{
if( ( NULL != pCameraID )
|| ( NULL != pFileName )
|| ( bPrintHelp ))
{
err = VmbErrorBadParameter;
break;
}
bPrintHelp = 1;
}
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 )
{
printf( "Invalid parameters!\n\n" );
bPrintHelp = 1;
}
//Print out help and end program
if ( bPrintHelp )
{
printf( "Usage: SynchronousGrab [CameraID] [/h] [/f:FileName]\n" );
printf( "Parameters: CameraID ID of the camera to use (using first camera if not specified)\n" );
printf( " /h Print out help\n" );
printf( " /f:FileName File name for operation\n" );
printf( " (default \"SynchronousGrab.bmp/.dat\" if not specified)\n" );
}
else
{
if ( NULL == pFileName )
{
pFileName = "SynchronousGrab.bmp";
}
err = SynchronousGrab( pCameraID, pFileName );
}
return err;
}