Basler CInstantCamera 使用 例子

// Include files to use the PYLON API.
#include
#include
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 100;

//驱动自带例子
int main(int argc, char* argv[])
{
    int exitCode = 0;
    Pylon::PylonAutoInitTerm autoInitTerm;
    try
    {

        //CTI:通用传输接口,基于GeniCam
        CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
        cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;
        camera.MaxNumBuffer = 5;
        camera.StartGrabbing( c_countOfImagesToGrab);
        CGrabResultPtr ptrGrabResult;
        while ( camera.IsGrabbing())
        {
            camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
            if (ptrGrabResult->GrabSucceeded())
            {
                cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
                cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
                const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
                cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;
                Pylon::DisplayImage(1, ptrGrabResult);
             }
             else
                   cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription();
         }
    }
    catch (GenICam::GenericException &e)
    {
        cerr << "An exception occurred." << endl<< e.GetDescription() << endl;
        exitCode = 1;
    }
    cerr << endl << "Press Enter to exit." << endl;
    while( cin.get() != '\n');
    return exitCode;
}

你可能感兴趣的:(工业相机)