Pylon抓取多相机图像

2017-07-19  本文已影响0人  Troll__Zhao
#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;
}
上一篇下一篇

猜你喜欢

热点阅读