basler运用pylon开发步骤

1、首先需要初始化Pylon,即调用PylonInitialize();
2、在一个try{} catch(){}语句中进行打开相机的相关操作。
3、调用相机的传输层工厂类定义一个工厂类的引用,并初始化它,也就是CTlFactory& tlFactory = CTlFactory::GetInstance();
4、得到所有连接的pylon相机,DeviceInfoList_t devices; tlFactory.EnumerateDevices(devices);
5、创建一个相机实例数组,CInstantCameraArray cameras(min(devices.size(), c_maxCamerasToUse));
6、在一个for循环当中把所有检测到的相机附加到相机实例数组当中,cameras[i].Attach(tlFactory.CreateDevice(device[i]));
7、两个相机开始抓取图像,病定义一个存取抓取结果的变量,cameras.StartGrabbing(); CGrabResultPtr ptrGrabResult;
8、for循环控制抓取的图片数量,在循环内定义一个可以标志相机序列的变量,然后通过cameras数组访问相机的相关数据即可
9、最后终止Pylon相机,即调用PylonTerminate

#include <pylon/PylonIncludes.h>
using namespace Pylon;
using namespace std;
static const uint32_t c_countOfImagesToGrab = 10;
static const size_t c_maxCamerasToUse = 2;
int main(int argc, char* argv[])
{
int exitCode = 0;
PylonInitialize();
try {
CTlFactory& tlFactory = CTlFactory::GetInstance();
DeviceInfoList_t devices; if ( tlFactory.EnumerateDevices(devices) == 0 )
{
throw RUNTIME_EXCEPTION( “No camera present.”);
}
CInstantCameraArray cameras( min( devices.size(), c_maxCamerasToUse));
cout << "devices.size(): " << devices.size() << endl;
for ( size_t i = 0; i < cameras.GetSize(); ++i)
{
cameras[ i ].Attach( tlFactory.CreateDevice( devices[ i ]));
cout << "Using device " << cameras[ i ].GetDeviceInfo().GetModelName() << endl;
}
for( uint32_t i = 0; i < c_countOfImagesToGrab && cameras.IsGrabbing(); ++i)
{
cameras.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);
intptr_t cameraContextValue = ptrGrabResult->GetCameraContext();
cout << "Camera " << cameraContextValue << ": " << cameras[ cameraContextValu].GetDeviceInfo().GetModelName() << endl;
cout << "GrabSucceeded: " << ptrGrabResult->GrabSucceeded() << endl;
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;
}
}
catch (const GenericException &e)
{
cerr << “An exception occurred.” << endl << e.GetDescription() << endl;
exitCode = 1;
}
cerr << endl << “Press Enter to exit.” << endl;
while( cin.get() != ‘\n’);
PylonTerminate(); return exitCode;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值