美文网首页
Pylon抓取多相机图像

Pylon抓取多相机图像

作者: Troll__Zhao | 来源:发表于2017-07-19 21:05 被阅读0次
    • 首先需要初始化Pylon,即调用PylonInitialize();

    • 在一个try{} catch(){}语句中进行相关的操作。

    • 调用相机的传输层工厂类定义一个工厂类的引用,并初始化它,也就是CTlFactory& tlFactory = CTlFactory::GetInstance();

    • 得到所有连接的pylon相机,DeviceInfoList_t devices; tlFactory.EnumerateDevices(devices);

    • 创建一个相机实例数组,CInstantCameraArray cameras(min(devices.size(), c_maxCamerasToUse));

    • 在一个for循环当中把所有检测到的相机附加到相机实例数组当中,cameras[i].Attach(tlFactory.CreateDevice(device[i]));

    • 两个相机开始抓取图像,病定义一个存取抓取结果的变量,cameras.StartGrabbing(); CGrabResultPtr ptrGrabResult;

    • for循环控制抓取的图片数量,在循环内定义一个可以标志相机序列的变量,然后通过cameras数组访问相机的相关数据即可

    • 最后终止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[ cameraContextValue ].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;
    }
    

    相关文章

      网友评论

          本文标题:Pylon抓取多相机图像

          本文链接:https://www.haomeiwen.com/subject/lxjrkxtx.html