Basler Pylon 簡單抓圖


簡單抓圖步驟:

  • StartGrabbing 開始抓取,狀態 isGrabbing
  • RetrieveResult 接收數據,完成后觸發 StopGrabbing
  • 數據由 CGrabResultPtr 指針接收,狀態 GrabSucceeded
  • runtime 由 PylonInitialize 初始化,並由 PylonTerminate 銷毀

具體代碼如下:

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

 

Name of Class Usable for Device Type Device-specific
Pylon::CInstantCamera (recommended) All cameras No
Pylon::CBaslerUniversalInstantCamera (recommended for novice users) All cameras No
Pylon::CBasler1394InstantCamera IIDC 1394 compliant cameras Yes
Pylon::CBaslerGigEInstantCamera GigE Vision compliant cameras Yes
Pylon::CBaslerUsbInstantCamera USB3 Vision compliant cameras Yes
Pylon::CBaslerCameraLinkInstantCamera Camera Link compliant cameras Yes

 

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();

 

調試時,相機意外中斷,連不上的處理

The device is controlled by another application. Err: An attempt was made to access an address location which is currently/momentary not accessible. (0xE1018006)

設置環境變量 PYLON_GIGE_HEARTBEAT =1000 即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM