简单抓图步骤:
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 ClassUsable for Device TypeDevice-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() <
cout<< "SizeY:" << ptrGrabResult->GetHeight() <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 即可。