Basler Pylon 简单抓图

using namespace Pylon;

Step0:初始化 Pylonruntime

    // Before using any pylon methods, the pylon runtime must be initialized.
    PylonInitialize();
    //Pylon::PylonAutoInitTerm autoInitTerm;

Step1: 创建 Camera 实例

        // Create an instant camera object with the camera device found first.
        IPylonDevice *pDevice = CTlFactory::GetInstance().CreateFirstDevice();
        CInstantCamera camera;
        camera.Attach(pDevice);

 step2:开始抓取

        // Start the grabbing of 1 images.
        // The camera device is parameterized with a default configuration which
        // sets up free-running continuous acquisition.
        camera.StartGrabbing(1);

step3:构造智能指针接收抓取数据

        // This smart pointer will receive the grab result data.
        CGrabResultPtr ptrGrabResult;

step4:判断抓取状态,并接收数据

        // Camera.StopGrabbing() is called automatically by the RetrieveResult() method
        // when c_countOfImagesToGrab images have been retrieved.
        int flag = 0;
        while ( camera.IsGrabbing())
        {
            // Wait for an image and then retrieve it. A timeout of 5000 ms is used.
            camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);

step5:判断抓取结果,并处理

            // Image grabbed successfully?
            if (ptrGrabResult->GrabSucceeded())
            {
                // Access the image data.
                cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
                cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
                const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();

step6:释放 plyon runtime

    // Releases all pylon resources.
    PylonTerminate();

猜你喜欢

转载自www.cnblogs.com/5free/p/11751655.html
今日推荐