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

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