RawImage CaptureFlycap::getFrame() {
  mutex.lock();
  Error error;
  Image image;
  RawImage result;
  result.setColorFormat(capture_format);
  result.setWidth(0);
  result.setHeight(0);
  result.setTime(0.0);
  result.setData(0);
  error = camera->RetrieveBuffer(&image);
  if (error != PGRERROR_OK) {
    error.PrintErrorTrace();
    mutex.unlock();
    return result;
  }

  stored_image = new Image;
  stored_image->DeepCopy(&image);

  result.setData(stored_image->GetData());
  struct timeval tv;
  gettimeofday(&tv,NULL);
  result.setTime((double)tv.tv_sec + tv.tv_usec*(1.0E-6));
  result.setHeight(stored_image->GetRows());
  result.setWidth(stored_image->GetCols());
  result.setColorFormat(pixelFormatToColorFormat(stored_image->GetPixelFormat()));

  mutex.unlock();
  return result;
}
Example #2
0
void ofApp::PrintError (Error error){
    error.PrintErrorTrace();
}
void PrintError( Error error )
{
    error.PrintErrorTrace();
}
static void PrintErrorAndExit(Error error)
{
    error.PrintErrorTrace();
    exit(0);
}
void CameraPointGrey::PrintError(Error error)
{
    error.PrintErrorTrace();
}
bool CaptureFlycap::startCapture() {
  mutex.lock();
  cam_id_mutex.lock();

  BusManager busMgr;
  Error error;
  unsigned int numCameras;

  int current_id = v_cam_bus->getInt();

  if (current_id >= 0) {
    cam_id = (unsigned int)current_id;
  } else {
    fprintf(stderr, "Flycapture: Invalid cam_id: %d\n", current_id);
    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }
  error = busMgr.GetNumOfCameras(&numCameras);
  if (error != PGRERROR_OK)
  {
    error.PrintErrorTrace();
    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  if(cam_id >= numCameras)
  {
    fprintf(stderr, "Flycapture: Invalid cam_id: %u\n", cam_id);

    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  bool id_active = false;

  for (size_t i = 0; i < active_cam_ids.size(); i++) {
    if (active_cam_ids[i] == cam_id) {
      id_active = true;
      break;
    }
  }

  if (id_active) {
    fprintf(stderr, "Flycapture: cam_id %u is already in use \n", cam_id);

    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  camera = new GigECamera();
  error = busMgr.GetCameraFromIndex(v_cam_bus->getInt(), &guid);
  if (error != PGRERROR_OK) {
    error.PrintErrorTrace();
    delete camera;

    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  error = camera->Connect(&guid);
  if (error != PGRERROR_OK) {
    error.PrintErrorTrace();
    delete camera;
    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  fprintf(stderr,"Connected");
  is_connected = true;

  CameraInfo camInfo;
  error = camera->GetCameraInfo(&camInfo);
  if (error != PGRERROR_OK) {
    error.PrintErrorTrace();
    delete camera;
    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  fprintf(stderr," to %s, Serial Number: %u\n",
          camInfo.modelName,
          camInfo.serialNumber);

  Property auto_exposure;
  auto_exposure.onOff = false;
  auto_exposure.onePush = false;
  auto_exposure.type = FlyCapture2::AUTO_EXPOSURE;
  error = camera->SetProperty(&auto_exposure);
  if (error != PGRERROR_OK) {
    mutex.unlock();
    cam_id_mutex.unlock();
    delete camera;
    error.PrintErrorTrace();
    return false;
  }
  writeAllParameterValues();

  error = camera->StartCapture();
  if (error != PGRERROR_OK) {
    error.PrintErrorTrace();
    delete camera;
    mutex.unlock();
    cam_id_mutex.unlock();
    return false;
  }

  is_capturing = true;

  active_cam_ids.push_back(cam_id);
  mutex.unlock();
  cam_id_mutex.unlock();

  return true;
}
void CaptureFlycap::writeParameterValues(VarList * item) {
  if (!is_connected) {
    mutex.lock();
  }

  Error error;
  string item_name = item->getName();
  if (item_name == "Camera Parameters") {
    vector<VarType *> children = item->getChildren();
    for (unsigned int i=0;i<children.size();i++) {
      bool is_property=false;
      Property prop;

      string param_name = children[i]->getName();
      if (param_name == "Video Mode") {
        if (is_connected && !is_capturing) {
          Mode mode = videoModeFromString(v_videomode->getString());
          error = camera->SetGigEImagingMode(mode);
          if (error != PGRERROR_OK) {
            error.PrintErrorTrace();
            mutex.unlock();
            return;
          }
        }
      } else if (param_name == "Brightness") {
        is_property = true;
        prop.type = FlyCapture2::BRIGHTNESS;
      } else if (param_name == "Shutter") {
        is_property = true;
        prop.type = FlyCapture2::SHUTTER;
      }
      else if (param_name == "Gain") {
        is_property = true;
        prop.type = FlyCapture2::GAIN;
      }
      else if (param_name == "Gamma") {
        is_property = true;
        prop.type = FlyCapture2::GAMMA;
      }
      else if (param_name == "Frame Rate") {
        is_property = true;
        prop.type = FlyCapture2::FRAME_RATE;
      }
      else if (param_name == "White Balance") {
        is_property = true;
        prop.type = FlyCapture2::WHITE_BALANCE;
      }
      if (is_property) {
        prop.onePush = false;
        prop.onOff = true;
        prop.autoManualMode = false;
        prop.absControl = true;

        if (is_connected) {
          if (param_name == "White Balance")  {
            vector<VarType *> grandchildren = children[i]->getChildren();
            VarBool* vOnOff = (VarBool*)grandchildren[0];
            VarInt* vRed = (VarInt*)grandchildren[1];
            VarInt* vBlue = (VarInt*)grandchildren[2];
            prop.onOff = vOnOff->getBool();
            prop.valueA = vRed->getInt();
            prop.valueB = vBlue->getInt();
          }
          else {
            VarDouble* current_double = (VarDouble *)children[i];
            double absvalue = current_double->getDouble();
            prop.absValue = (float)absvalue;
          }

          error = camera->SetProperty(&prop);
          if (error != PGRERROR_OK) {
            mutex.unlock();
            error.PrintErrorTrace();
            return;
          }
        }
      }
    }
  }

  if (settings_changed) {
    if (is_connected) {
      GigEImageSettings imageSettings;
      imageSettings.offsetX = v_xoffset->getInt();
      imageSettings.offsetY = v_yoffset->getInt();
      imageSettings.height = v_height->getInt();
      imageSettings.width = v_width->getInt();
      imageSettings.pixelFormat = colorFormatToPixelFormat(Colors::stringToColorFormat(v_colormode->getString().c_str()));

      error = camera->SetGigEImageSettings(&imageSettings);
      if (error != PGRERROR_OK) {
        error.PrintErrorTrace();
        mutex.unlock();
        return;
      }

      settings_changed = false;
    }
  }

  if(!is_connected){
    mutex.unlock();
  }
}
Example #8
0
void PGRCamera::PrintError( Error error )
{
    error.PrintErrorTrace();
}