Basler相机抓取图像并保存 Pylon

使用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);

你可能感兴趣的:(tensorflow)