Basler相機抓取影象並儲存 Pylon
阿新 • • 發佈:2019-01-02
使用Pylon獲取相機圖片主要使用函式PylonDeviceGrabSingleFrame(PYLON_DEVICE_HANDLE hDev, size_t channel, void * pBuffer, size_t bufferSize, PylonGrabResult_t *pGrabResult, _Bool *pReady, uint32_t timeout);其中channel自己設定(0),pGrabResult,pReady為返回值,pGrabResult為儲存圖片資訊的結構體。timeout為等待圖片獲取的時間,不能控制獲取圖片的速度,超時則丟擲異常。(若channel為0,FPS大約為5,timeout設定為200以下無法獲得圖片)。
儲存圖片使用PylonImagePersistenceSave(EPylonImageFileFormat imageFileFormat, const char* pFilename, const void * pBuffer, size_t bufferSize, EPylonPixelType pixelType, uint32_t width, uint32_t height, size_t paddingX, EPylonImageOrientation orientation, PylonImagePersistenceOptions_t* pOptions);函式。其中pOptions一般設為NULL
size_t numDevices; /* Number of available devices. */
PYLON_DEVICE_HANDLE hDev; /* Handle for the pylon device. */
const int numGrabs = 10; /* Number of images to grab. */
int32_t payloadSize; /* Size of an image frame in bytes. */
unsigned char* imgBuf; /* Buffer used for g
/* Before using any pylon methods, the pylon runtime must be initialized. */
PylonInitialize();
/* Enumerate all camera devices. You must call
PylonEnumerateDevices() before creating a device! */
PylonEnumerateDevices( &numDevices ); //獲取numDevics
PylonCreateDeviceByIndex( 0, &hDev ); //獲取hDev
PylonDeviceOpen( hDev, PYLONC_ACCESS_MODE_CONTROL | PYLONC_ACCESS_MODE_STREAM ); //開啟相機
PylonDeviceGetIntegerFeatureInt32( hDev, "PayloadSize", &payloadSize );
imgBuf = (unsigned char*) malloc( payloadSize );
PylonDeviceGrabSingleFrame( hDev, 0, imgBuf, payloadSize, &grabResult, &bufferReady, 500);
PylonImagePersistenceSave(ImageFileFormat_Png, "Image.png", grabResult.pBuffer, payloadSize, PixelType_Mono8, grabResult.SizeX, grabResult.SizeY, grabResult.PaddingX, 0, NULL);