Exemple #1
0
bool Camera::setup()
{
  ///////////////////////////////////////////////////////
  // Get a camera:
  FlyCapture2::Error error;
  FlyCapture2::BusManager busMgr;

  unsigned int N;
  if ((error = busMgr.GetNumOfCameras(&N)) != PGRERROR_OK)
    ROS_ERROR (error.GetDescription ());
  if (camSerNo == 0)
  {
    if ((error = busMgr.GetCameraFromIndex(0, &guid_)) != PGRERROR_OK)
      PRINT_ERROR_AND_RETURN_FALSE;
    ROS_INFO ("did busMgr.GetCameraFromIndex(0, &guid)");
  }
  else
  {
    if ((error = busMgr.GetCameraFromSerialNumber(camSerNo, &guid_)) != PGRERROR_OK)
      PRINT_ERROR_AND_RETURN_FALSE;
  }
  ROS_INFO ("Setup: Camera GUID = %u %u %u %u", guid_.value[0], guid_.value[1], guid_.value[2], guid_.value[3]);

  ROS_INFO ("Setup successful");
  return true;

}
/*!
  \return Return the number of cameras connected on the bus.
*/
unsigned int vpFlyCaptureGrabber::getNumCameras()
{
  unsigned int numCameras;
  FlyCapture2::BusManager busMgr;
  FlyCapture2::Error error = busMgr.GetNumOfCameras(&numCameras);
  if (error != FlyCapture2::PGRERROR_OK) {
    numCameras = 0;
  }
  return numCameras;
}
Exemple #3
0
void printCameras()
{
  FlyCapture2::BusManager busMgr;
  unsigned int cameraNum;
  if(!check_success(busMgr.GetNumOfCameras(&cameraNum))) return;
  ROS_INFO ("Found %d cameras", cameraNum);
  for (unsigned int i = 0; i < cameraNum; i++)
  {
    unsigned int serNo;
    if(check_success(busMgr.GetCameraSerialNumberFromIndex(i, &serNo))) {
      ROS_INFO ("Camera %u: S/N %u", i, serNo);
    }
  }
}
vector<CameraInfo> CameraPointGrey::getCameraList(){
    
    FlyCapture2::Error error;

    FlyCapture2::BusManager busManager;
    unsigned int numCameras;
    error = busManager.GetNumOfCameras(&numCameras);

    vector<CameraInfo> ret;

    if (error != FlyCapture2::PGRERROR_OK){
        PrintError(error);
        return ret;
    }

    for (unsigned int i=0; i < numCameras; i++){
        FlyCapture2::PGRGuid guid;
        error = busManager.GetCameraFromIndex(i, &guid);
        if (error != FlyCapture2::PGRERROR_OK)
            PrintError(error);

        // Connect to camera
        FlyCapture2::Camera cam;
        error = cam.Connect(&guid);
        if (error != FlyCapture2::PGRERROR_OK)
            PrintError( error );

        // Get the camera information
        FlyCapture2::CameraInfo camInfo;
        error = cam.GetCameraInfo(&camInfo);
        if (error != FlyCapture2::PGRERROR_OK)
            PrintError( error );

        CameraInfo camera;
        camera.busID = camInfo.nodeNumber;
        camera.model = camInfo.modelName;
        camera.vendor = "Point Grey Research";

        ret.push_back(camera);
    }

    return ret;
}
void TrackerDataSource::list_serial_numbers(){
  std::cout << "Serial numbers of cameras on the system: \n";
  FlyCapture2::BusManager busMgr;
  FlyCapture2::PGRGuid guid;
  unsigned int n_cams;
  FlyCapture2::CameraInfo camInfo;

  busMgr.GetNumOfCameras(&n_cams);

  FlyCapture2::Camera *this_camera = new FlyCapture2::Camera();

  for(int i = 0; i < n_cams; i++){

    busMgr.GetCameraFromIndex(i, &guid);

    this_camera->Connect( &guid );

    this_camera->GetCameraInfo( &camInfo );
    std::cout << "Camera " << i
              << " serial number: " << camInfo.serialNumber
              << std::endl;

    this_camera->Disconnect();
  }

  delete this_camera;

  std::cout << "Serial numbers requested in config file" << std::endl;
  for(int g = 0; g < opt.group_size(); g++){
    for(int c = 0; c < opt.group(g).cam_size(); c++){
      std::cout << "Group " << g << " camera " << c
                << " serial number: " << opt.group(g).cam(c).serial_number()
                << std::endl;
    }
  }


}
Exemple #6
0
void init()
{
  FlyCapture2::Error error;
  FlyCapture2::BusManager busMgr;
  for (int tries = 0; tries < 5; ++tries)
  {
    if ((error = busMgr.GetNumOfCameras(&cameraNum)) != PGRERROR_OK)
      ROS_ERROR (error.GetDescription ());
    if (cameraNum)
    {
      ROS_INFO ("Found %d cameras", cameraNum);
      unsigned int serNo;
      for (unsigned int i = 0; i < cameraNum; i++)
      {
        if ((error = busMgr.GetCameraSerialNumberFromIndex(i, &serNo)) != PGRERROR_OK)
          ROS_ERROR (error.GetDescription ());
        else
          ROS_INFO ("Camera %u: S/N %u", i, serNo);
      }
    }
    return;
    usleep(200000);
  }
}
// Fill out physical_cameras_p vector
int TrackerDataSource::init_cameras(){

  // we don't yet know whether we're reading from camera or file
  file_sources = BOU_UNSET;

  FlyCapture2::BusManager busMgr;
  FlyCapture2::Error      error;
  unsigned int n_cams;
  ptgr_err( busMgr.GetNumOfCameras(&n_cams) );
  if(n_cams < 1){
    std::cerr << "No cameras found.\n";
    return -1;
  }

  int n_software_cams = 0;
  for(int g = 0; g < opt.group_size(); g++){
    for(int c = 0; c < opt.group(g).cam_size(); c++){

      n_software_cams++;

      bool_or_unset this_cam_from_file =
        opt.group(g).cam(c).has_input_file_name() ?  BOU_TRUE  : BOU_FALSE ;

      // Complain if some cameras want input files and others don't
      if( (this_cam_from_file != file_sources) && (file_sources != BOU_UNSET) ){
        std::cerr << "Configuration error: group " << g << " camera " << c
                  << " has input_file settings inconsistent with other cameras.";
      } else {
        file_sources = this_cam_from_file;
      }

      if(file_sources == BOU_FALSE){

        // Get guid
        FlyCapture2::PGRGuid guid;
        ptgr_err( error =
                  busMgr.GetCameraFromSerialNumber(opt.group(g).cam(c).serial_number(),
                                                   &guid) );
        if(error != FlyCapture2::PGRERROR_OK){
          std::cerr << "Error getting guid from serial number "
                    << opt.group(g).cam(c).serial_number()
                    << std::endl;
          list_serial_numbers();
        }

        // Connect
        FlyCapture2::Camera *this_camera_p = new FlyCapture2::Camera ();
        ptgr_err( error = this_camera_p->Connect( &guid ) );
        if(error != FlyCapture2::PGRERROR_OK){
          std::cerr << "Error connecting to camera with serial number "
                    << opt.group(g).cam(c).serial_number() << std::endl;
        }

        // Find videomode
        // I don't know the type of these macros, auto for now TODO: fix type
        auto the_mode = FlyCapture2::VIDEOMODE_640x480Y8;
        auto the_rate = FlyCapture2::FRAMERATE_30;
        if( FRAME_WIDTH == 640 && FRAME_HEIGHT == 480 ){
          the_mode = FlyCapture2::VIDEOMODE_640x480Y8;
        } else {
          std::cerr << "Unsupported image size\n";
        }
        if( FRAME_RATE == 30 ){
          the_rate = FlyCapture2::FRAMERATE_30;
        } else if (FRAME_RATE == 15) {
          the_rate = FlyCapture2::FRAMERATE_15;
        } else {
          std::cerr << "Unsupported frame rate\n";
        }


        // Setup camera
        ptgr_err( error = this_camera_p->
                  SetVideoModeAndFrameRate(the_mode, the_rate) );
        if( error != FlyCapture2::PGRERROR_OK ){
          std::cerr << "Error in setup for camera with serial number "
                    << opt.group(g).cam(c).serial_number() << std::endl;
        }

        // Register camera with tracker
        // Insert a pair into the camera listing map
        // camera_pointer -> image_pointer
        physical_cameras_p[this_camera_p] = (*frames)[g][c];

        // Initialize the capture
        // Build the camera list in the way that flycapture2 wants it: pointer array
        std::map<FlyCapture2::Camera*, ArteFrame*>::iterator it;
        int n_cams = physical_cameras_p.size();
        ppCameras = new FlyCapture2::Camera*[n_cams];
        it = physical_cameras_p.begin();
        for(int i = 0; i < n_cams; i++){
          ppCameras[i] = it->first;
          it++;
        }


      } // endif this camera really is camera soure

      if(file_sources == BOU_TRUE){

        // Create the opencv file capture
        CvCapture *this_file_capture =
          cvCreateFileCapture( opt.group(g).cam(c).input_file_name().c_str() );
        if(!this_file_capture){
          std::cerr << "TrackerDataSource error opening file "
                    << opt.group(g).cam(c).input_file_name().c_str() << std::endl;
        }

        // Register the file capture with tracker
        simulated_cameras_p[this_file_capture] = (*frames)[g][c];

      } // endif this camera has file source

    } // done with this camera
  } // done with this camera group


}
Exemple #8
0
//! \brief Connect cameras and return camera objects
//!
//! \return unsigned int &numCameras
//! \return FlyCapture2::Camera** &ppCameras
//!
//!
void prepareCameras(unsigned int &numCameras,
                    FlyCapture2::Camera** &ppCameras)
{

    FlyCapture2::Error error;


    //!<
    //!< Get camera bus
    //!<

    FlyCapture2::BusManager busMgr;

    error = busMgr.GetNumOfCameras( &numCameras );
    PRINT_ERROR( error );
    std::cout << "Number of cameras detected: " << numCameras << std::endl;

    if ( numCameras < 1 )
    {
        std::cerr << "Insufficient number of cameras... press Enter to exit." << std::endl;
        getchar();
        exit(-1);
    }



    ppCameras = new FlyCapture2::Camera* [ numCameras ];


    //!<
    //!< Connect to all detected cameras and attempt to set them to a common video mode and frame rate
    //!<

    for ( unsigned int i = 0; i < numCameras; i++)
    {
        ppCameras[i] = new FlyCapture2::Camera();

        std::cout << "setting camera " << i << std::endl;

        FlyCapture2::PGRGuid guid;
        error = busMgr.GetCameraFromIndex( i, &guid );
        PRINT_ERROR( error );

        //!< Connect to a camera
        error = ppCameras[i]->Connect( &guid );
        PRINT_ERROR( error );


        PrintCameraInfo( ppCameras[i] );

        PrintCameraPropertyInfo( ppCameras[i] );



        //!< Set all cameras to a specific mode and frame rate so they can be synchronized
        error = ppCameras[i]->SetVideoModeAndFrameRate(FlyCapture2::VIDEOMODE_640x480Y8, //!< size of 640x480, format Mono8bit (Y8)
                                                       FlyCapture2::FRAMERATE_30 );
        PRINT_ERROR_MSG( error,
                        "Error starting cameras. \n"
                        "This example requires cameras to be able to set to 640x480 Y8 at 30fps. \n"
                        "If your camera does not support this mode, please edit the source code and recompile the application. \n"
                        "Press Enter to exit. \n");
    }


    std::cout << "all camera set to specific mode." << std::endl;


    error = FlyCapture2::Camera::StartSyncCapture( numCameras, (const FlyCapture2::Camera**)ppCameras );
    PRINT_ERROR_MSG( error,
                    "Error starting cameras. \n"
                    "This example requires cameras to be able to set to 640x480 Y8 at 30fps. \n"
                    "If your camera does not support this mode, please edit the source code and recompile the application. \n"
                    "Press Enter to exit. \n");

    std::cout << "StartSyncCapture." << std::endl;

}