示例#1
0
int capture_single(capture_t *cap, const int index, capture_frame_t *frame)
{
  dc1394camera_t *cam = cap->cameras[index];
  dc1394error_t err;
  dc1394video_frame_t *vframe = NULL;
  uint32_t frames_behind = 0;

  if (cap->prefer_one_shot && cam->one_shot_capable == DC1394_TRUE) {
    err = dc1394_video_set_one_shot(cam, DC1394_ON);
    DC1394_WRN(err, "could not set one shot mode.");
    if (err != DC1394_SUCCESS) {
      return CAPTURE_ERROR;
    }
  }

  err = dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_WAIT, &vframe);
  DC1394_WRN(err, "could not dequeue frame.");
  if (err != DC1394_SUCCESS) {
    return CAPTURE_ERROR;
  }
  frames_behind = vframe->frames_behind;

  /* copy the image to frame->raw_data */
  s_copy_frame(vframe, frame);

  err = dc1394_capture_enqueue(cam, vframe);
  DC1394_WRN(err, "could not enqueue frame.");
  if (err != DC1394_SUCCESS) {
    return CAPTURE_ERROR;
  }

  /* drop behind frames if drop_frame is enable */
  if (cap->drop_frames) {
    while (frames_behind-- > 0) {
      err = dc1394_capture_dequeue(cam, DC1394_CAPTURE_POLICY_WAIT, &vframe);
      DC1394_WRN(err, "could not dequeue frame.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
      
      err = dc1394_capture_enqueue(cam, vframe);
      DC1394_WRN(err, "could not enqueue frame.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
    }
  }

  return CAPTURE_SUCCESS;
}
示例#2
0
static dc1394framerate_t s_get_appropriate_framerate(dc1394camera_t *cam, dc1394video_mode_t mode, dc1394framerate_t framerate)
{
  dc1394framerates_t framerates;
  dc1394framerate_t selected_framerate;
  dc1394error_t err;
  unsigned int i;

  err = dc1394_video_get_supported_framerates(cam, mode, &framerates);
  DC1394_WRN(err, "failed to get framerates");
  if (err != DC1394_SUCCESS) {
    return framerate;
  }

  selected_framerate = (dc1394framerate_t)0;
  for (i = 0; i < framerates.num; ++i) {
    if (selected_framerate < framerates.framerates[i] && framerates.framerates[i] <= framerate) {
      selected_framerate = framerates.framerates[i];
    }
  }

  if (selected_framerate == 0) {
    return framerate;
  }

  return selected_framerate;
}
示例#3
0
int capture_init(capture_t *cap, const int verbose_mode)
{
  dc1394error_t err;

  /* initialize cap */
  cap->num_cameras = 0;
  cap->dc1394_cxt  = NULL;
  cap->camera_list = NULL;
  cap->num_active  = 0;
  cap->cameras     = NULL;

  cap->dc1394_cxt = dc1394_new();
  if (cap->dc1394_cxt == NULL) {
    return CAPTURE_ERROR;
  }

  err = dc1394_camera_enumerate(cap->dc1394_cxt, &cap->camera_list);
  DC1394_WRN(err, "Failed to enumerate cameras");
  if (err != DC1394_SUCCESS) {
    return CAPTURE_ERROR;
  }

  if (verbose_mode) {
    fprintf(stderr, "%d camers(s) found.\n", cap->camera_list->num);
  }

  cap->num_cameras = cap->camera_list->num;

  cap->num_buffers = 4;
  cap->prefer_one_shot = 0;
  cap->prefer_bmode = 0;
  cap->verbose = verbose_mode;

  return CAPTURE_SUCCESS;
}
示例#4
0
IplImage *dc1394_capture_get_iplimage(dc1394camera_t *camera)
{
    dc1394error_t err;
    dc1394video_frame_t *frame;
    IplImage *img;

    err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
    DC1394_WRN(err,"Could not capture a frame");

    img = dc1394_frame_get_iplimage(frame);

    err = dc1394_capture_enqueue(camera, frame);
    DC1394_WRN(err,"releasing buffer");

    return img;
}
示例#5
0
vector<CameraInfo> CameraIIDC::getCameraList(){
    
    dc1394_t *context = dc1394_new();
    
    dc1394camera_list_t *camera_list;
    dc1394error_t err;
    err = dc1394_camera_enumerate(context, &camera_list);
    DC1394_WRN(err,"libdc1394: Failed to enumerate cameras!");

    vector<CameraInfo> ret;
    
    for (unsigned int i=0; i<camera_list->num; i++) {
        CameraInfo info;
        dc1394camera_t *cam;
        cam = dc1394_camera_new(context, camera_list->ids[i].guid);

        //info.vendor = std::string(cam->vendor ? cam->vendor : "");
        info.vendor = "IIDC";
        info.model = string(cam->model ? cam->model : "");
        info.busID = (unsigned int)cam->guid;
        
        dc1394_camera_free(cam);
        ret.push_back(info);
    }
    
    dc1394_camera_free_list(camera_list);
    dc1394_free(context);
    
    return ret;
}
示例#6
0
static int s_activate_camera(capture_t *cap, const int index)
{
  s_flush_buffer(cap, index);

  if ((!cap->prefer_one_shot) || cap->cameras[index]->one_shot_capable != DC1394_TRUE) {
    dc1394error_t err;

    /* use continuous transmission mode */
    err = dc1394_video_set_transmission(cap->cameras[index], DC1394_ON);
    DC1394_WRN(err, "could not start iso transmission");
    if (err != DC1394_SUCCESS) {
      return CAPTURE_ERROR;
    }
  }

  return CAPTURE_SUCCESS;
}
void Libdc1394Grabber::enumerateDevices()
{
    dc1394error_t err;

    if(!dc1394) {
        initDc1394System();
    }

    /* List cameras */
    if(cameraList == NULL) {
        err=dc1394_camera_enumerate (dc1394, &cameraList);
        DC1394_WRN(err,"Failed to enumerate cameras");
        if(err == DC1394_SUCCESS) {
            numCameras = cameraList->num;
        }
    }
}
示例#8
0
int capture_multi(capture_t *cap, capture_frame_t *frames)
{
  int i;
  dc1394error_t err;
  dc1394video_frame_t **vframes = NULL;
  uint32_t frames_behind = 0;

  vframes = (dc1394video_frame_t **)malloc(sizeof(dc1394video_frame_t *) * cap->num_active);
  if (vframes == NULL) {
    return CAPTURE_ERROR;
  }

  for (i = 0; i < cap->num_active; ++i) {
    if (cap->prefer_one_shot && cap->cameras[i]->one_shot_capable) {
      err = dc1394_video_set_one_shot(cap->cameras[i], DC1394_ON);
      DC1394_WRN(err, "could not set one shot mode.");
      if (err != DC1394_SUCCESS) {
        return CAPTURE_ERROR;
      }
    }
  }

  for (i = 0; i < cap->num_active; ++i) {
    err = dc1394_capture_dequeue(cap->cameras[i], DC1394_CAPTURE_POLICY_WAIT, &vframes[i]);
    DC1394_WRN(err, "could not dequeue frame.");
    if (err != DC1394_SUCCESS) {
      free(vframes);
      return CAPTURE_ERROR;
    }
  }

  /* find the minimum number of behind frames */
  frames_behind = vframes[0]->frames_behind;
  for (i = 1; i < cap->num_active; ++i) {
    if (frames_behind > vframes[i]->frames_behind) {
      frames_behind = vframes[i]->frames_behind;
    }
  }

  /* copy the image to frame->raw_data */
  for (i = 0; i < cap->num_active; ++i) {
    s_copy_frame(vframes[i], &frames[i]);
  }

  for (i = 0; i < cap->num_active; ++i) {
    err = dc1394_capture_enqueue(cap->cameras[i], vframes[i]);
    DC1394_WRN(err, "could not enqueue frame.");
    if (err != DC1394_SUCCESS) {
      free(vframes);
      return CAPTURE_ERROR;
    }
  }

  /* drop behind frames if drop_frame is enable */
  if (cap->drop_frames != 0) {
    while (frames_behind-- > 0) {
      for (i = 0; i < cap->num_active; ++i) {
        err = dc1394_capture_dequeue(cap->cameras[i], DC1394_CAPTURE_POLICY_WAIT, &vframes[i]);
        DC1394_WRN(err, "could not dequeue frame.");
        if (err != DC1394_SUCCESS) {
          free(vframes);
          return CAPTURE_ERROR;
        }
      }
      
      for (i = 0; i < cap->num_active; ++i) {
        err = dc1394_capture_enqueue(cap->cameras[i], vframes[i]);
        DC1394_WRN(err, "could not enqueue frame.");    
        if (err != DC1394_SUCCESS) {
          free(vframes);
          return CAPTURE_ERROR;
        }
      }
    }
  }

  free(vframes);

  return CAPTURE_SUCCESS;
}
示例#9
0
int capture_setup(capture_t *cap, const char *conf_file)
{
  conf_param_t param = CONF_PARAM_INIT_VAL;
  int i, num_found;

  /* read configulation from a specified file */
  if (s_read_conf_file(conf_file, &param) < 1) {
    return CAPTURE_ERROR;
  }


  /* allocate memory */
  cap->cameras = (dc1394camera_t **)malloc(sizeof(dc1394camera_t *) * param.num_cameras);
  if (cap->cameras == NULL) {
    return CAPTURE_ERROR;
  }

  cap->num_active = 0;
  num_found = 0;
  for (i = 0; i < param.num_cameras; ++i) {
    dc1394error_t err;

    cap->cameras[num_found] = dc1394_camera_new(cap->dc1394_cxt, param.settings[i].uid);

    if (cap->cameras[num_found] == NULL) {
      if (cap->verbose) {
        fprintf(stderr, "camera 0x%0"PRIx64" not found.\n", param.settings[i].uid);
      }
      continue;
    }

    if (cap->verbose) {
      fprintf(stderr, "GUID[%d]: 0x%0"PRIx64"\n", i, cap->cameras[num_found]->guid);
    }

#if 0
    {
      uint32_t port = 42;
      dc1394_camera_get_linux_port(cap->cameras[num_found], &port);
      printf("port: %d\n", port);
    }
#endif

    /* set parameters */
    if (cap->verbose) {
      fprintf(stderr, "set parameter.\n");
    }
    s_set_parameters(cap, num_found, &param.settings[i]);

    /* set up a capture construct */
    if (cap->verbose) {
      fprintf(stderr, "set up a capture construct.\n");
    }

    err = dc1394_capture_setup(cap->cameras[num_found], cap->num_buffers, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_WRN(err, "Setup capture failed.");
    if (err != DC1394_SUCCESS) {
      continue;
    }
    
    /* set ready to capture */
    if (cap->verbose) {
      fprintf(stderr, "activate camera.\n");
    }
    s_activate_camera(cap, num_found);

    ++num_found;
  }
  cap->num_active = num_found;

  s_clear_conf_param(&param);

  return CAPTURE_SUCCESS;
}
示例#10
0
static dc1394video_mode_t s_get_appropriate_mode(dc1394camera_t *cam, dc1394video_mode_t mode)
{
  dc1394video_modes_t supported_modes;
  dc1394video_mode_t selected_mode = mode;

  uint32_t width, height;
  dc1394color_coding_t coding;
  int found = 0;
  unsigned int num_pixels = 0;

  dc1394error_t err;
  unsigned int i;

  err = dc1394_video_get_supported_modes(cam, &supported_modes);
  DC1394_WRN(err, "failed to get supported modes.");
  if (err != DC1394_SUCCESS) {
    return mode;
  }

  for (i = 0; i < supported_modes.num; ++i) {
    /* return given mode if the camera supports it */
    if (supported_modes.modes[i] == mode) {
      return mode;
    }
  }

  /*
    reaches here when no mode is exactly matched with one of supported modes
  */

  err = dc1394_get_image_size_from_video_mode(cam, mode, &width, &height);
  DC1394_WRN(err, "failed to get image size.");
  if (err != DC1394_SUCCESS) {
    return mode;
  }
  num_pixels = width * height;

  err = dc1394_get_color_coding_from_video_mode(cam, mode, &coding);
  DC1394_WRN(err, "failed to get color coding.");
  if (err != DC1394_SUCCESS) {
    return mode;
  }

  found = 0;
  /* search the mode of size does not exceed the given mode and has the same color coding */
  for (i = 0; i < supported_modes.num; ++i) {
    dc1394color_coding_t c;
    if (dc1394_get_color_coding_from_video_mode(cam, supported_modes.modes[i], &c) != DC1394_SUCCESS) {
      continue;
    }

    if (c == coding) {
      uint32_t w, h;

      if (dc1394_get_image_size_from_video_mode(cam, supported_modes.modes[i], &w, &h) != DC1394_SUCCESS) {
        continue;
      }

      if (w*h <= width*height && num_pixels < w*h) {
        num_pixels = w*h;
        selected_mode = supported_modes.modes[i];
        found = 1;
      }
    }
  }

  if (found == 0) {
    return mode;
  }

  return selected_mode;
}
示例#11
0
static int s_set_parameters(capture_t *cap, const int index, camera_setting_t *s)
{
  int ret = CAPTURE_SUCCESS;

  dc1394camera_t *cam = cap->cameras[index];
  dc1394error_t err;

  /* set operation mode to 1394b, if possible */
  if (cam->bmode_capable != 0 && cap->prefer_bmode) {
    err = dc1394_video_set_operation_mode(cam, DC1394_OPERATION_MODE_1394B);
    DC1394_WRN(err, "could not set 1394b mode.");

    if (err == DC1394_SUCCESS) {
      err = dc1394_video_set_iso_speed(cam, DC1394_ISO_SPEED_800);
      DC1394_WRN(err, "could not set iso mode to S800.");

      if (err != DC1394_SUCCESS) {
        err = dc1394_video_set_iso_speed(cam, DC1394_ISO_SPEED_400);
        DC1394_WRN(err, "could not set iso mode to S400.");
      }
    }
  }
  else {
    err = dc1394_video_set_operation_mode(cam, DC1394_OPERATION_MODE_LEGACY);
    DC1394_WRN(err, "could not set 1394-legacy mode.");

    err = dc1394_video_set_iso_speed(cam, DC1394_ISO_SPEED_400);
    DC1394_WRN(err, "could not set iso mode to S400.");
  }

  /* mode */
  s->mode = s_get_appropriate_mode(cam, ((s->mode >= 0) ? s->mode : DC1394_VIDEO_MODE_640x480_MONO8));
  if (dc1394_video_set_mode(cam, s->mode) != DC1394_SUCCESS) {
    ret = CAPTURE_ERROR;
  }
  dc1394_video_get_mode(cam, &s->mode);

  /* frame rate */
  s->framerate = s_get_appropriate_framerate(cam, s->mode, ((s->framerate >= 0) ? s->framerate : DC1394_FRAMERATE_30));
  if (dc1394_video_set_framerate(cam, s->framerate) != DC1394_SUCCESS) {
    ret = CAPTURE_ERROR;
  }

  /*
    features
  */
  SET_FEATURE(DC1394_FEATURE_BRIGHTNESS,    s->brightness);
  SET_FEATURE(DC1394_FEATURE_EXPOSURE,      s->exposure);
  SET_FEATURE(DC1394_FEATURE_SHARPNESS,     s->sharpness);
  SET_FEATURE(DC1394_FEATURE_HUE,           s->hue);
  SET_FEATURE(DC1394_FEATURE_SATURATION,    s->saturation);
  SET_FEATURE(DC1394_FEATURE_GAMMA,         s->gamma);
  SET_FEATURE(DC1394_FEATURE_SHUTTER,       s->shutter);
  SET_FEATURE(DC1394_FEATURE_GAIN,          s->gain);
  SET_FEATURE(DC1394_FEATURE_IRIS,          s->iris);
  SET_FEATURE(DC1394_FEATURE_FOCUS,         s->focus);
  //SET_FEATURE(DC1394_FEATURE_TEMPERATURE,   s->temperature); is not supported by dc1394_feature_set_value()
  
  SET_FEATURE(DC1394_FEATURE_ZOOM, s->zoom);
  SET_FEATURE(DC1394_FEATURE_PAN,  s->pan);
  SET_FEATURE(DC1394_FEATURE_TILT, s->tilt);

  /* white blance */
  if (s->white_balance[0] >= 0 && s->white_balance[1] >= 0) {
    dc1394_feature_set_mode(cam, DC1394_FEATURE_WHITE_BALANCE, DC1394_FEATURE_MODE_MANUAL);
    if (dc1394_feature_whitebalance_set_value(cam, s->white_balance[0], s->white_balance[1]) != DC1394_SUCCESS) {
      ret = CAPTURE_ERROR;
    }
  }
  else {
    if (dc1394_feature_set_mode(cam, DC1394_FEATURE_WHITE_BALANCE, DC1394_FEATURE_MODE_AUTO) != DC1394_SUCCESS) {
      ret = CAPTURE_ERROR;
    }
  }

  return ret;
}
示例#12
0
CameraIIDC::CameraIIDC(unsigned int camNum, CameraTriggerMode triggerMode) : Camera(triggerMode) {

    context = dc1394_new();
    
    dc1394camera_list_t *camera_list;
    dc1394error_t err;
    err = dc1394_camera_enumerate(context, &camera_list);
    
    if(camNum+1 > camera_list->num){
        cerr << "libdc1394: Selected camera is not available!";
        return;
    }
    
    cam = NULL;

    cam = dc1394_camera_new(context, camera_list->ids[camNum].guid);
    if(!cam){
        cerr << "libdc1394: Could not open camera!";
        return;
    }

    dc1394_camera_free_list(camera_list);

//    // Get video modes
//    dc1394video_modes_t video_modes;
//    err=dc1394_video_get_supported_modes(cam, &video_modes);
//    DC1394_WRN(err,"Can't get video modes");
//    // Select highest res mode
//    int i;
//    dc1394color_coding_t coding;
//    for (i=video_modes.num-1;i>=0;i--) {
//        if (!dc1394_is_video_mode_scalable(video_modes.modes[i])) {
//            dc1394_get_color_coding_from_video_mode(cam, video_modes.modes[i], &coding);
//            DC1394_WRN(err,"libdc1394: Could not get color coding");
//            if (coding==DC1394_COLOR_CODING_MONO8) {
//                video_mode=video_modes.modes[i];
//                break;
//            }
//        }
//    }
//    if (i < 0) {
//        cerr << "libdc1394: Could not get a valid gray scale mode!";
//        return;
//    }

    // Select format 7 mode 0
    video_mode = DC1394_VIDEO_MODE_FORMAT7_0;

    // Set bit depth
    err = dc1394_format7_set_color_coding(cam, video_mode, DC1394_COLOR_CODING_MONO8);
    if (err!=DC1394_SUCCESS)
        cerr << "libdc1394: Could not set video mode or color coding!";

//    // Set video mode
//    err=dc1394_video_set_mode(cam, video_mode);
//    if (err!=DC1394_SUCCESS)
//        cerr << "libdc1394: Could not set video mode!";

    // Setup capture
    err=dc1394_video_set_operation_mode(cam, DC1394_OPERATION_MODE_1394B);
    if (err!=DC1394_SUCCESS)
        cerr << "libdc1394: Could not set operation mode!";

    err=dc1394_video_set_iso_speed(cam, DC1394_ISO_SPEED_800);
    if (err!=DC1394_SUCCESS)
        cerr << "libdc1394: Could not set iso speed!";

    // Size of ringbuffer (Note: on OS X 10.9, size must be greater than 1)
#ifdef __APPLE__
    unsigned int bufferSize = 2;
#else
    unsigned int bufferSize = 1;
#endif

    err=dc1394_capture_setup(cam, bufferSize, DC1394_CAPTURE_FLAGS_DEFAULT);
    if (err!=DC1394_SUCCESS)
        cerr << "libdc1394: Could not set up camera!";

    // Disable auto exposure mode
    dc1394_feature_set_power(cam, DC1394_FEATURE_EXPOSURE, DC1394_OFF);

    // Disable gamma mode
    dc1394_feature_set_power(cam, DC1394_FEATURE_GAMMA, DC1394_OFF);

    // Disable sharpness mode
    dc1394_feature_set_power(cam, DC1394_FEATURE_SHARPNESS, DC1394_OFF);

    // Disable frame-rate mode
    dc1394_feature_set_power(cam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF);

    // Set manual settings
    dc1394_feature_set_mode(cam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
    dc1394_feature_set_mode(cam, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);


    // Set reasonable default settings
    CameraSettings settings;
    //settings.shutter = 8.333;
    settings.shutter = 16.66;
    settings.gain = 0.0;
    this->setCameraSettings(settings);

    // Print camera features and settings
    dc1394featureset_t features;
    err=dc1394_feature_get_all(cam, &features);
    DC1394_WRN(err, "libdc1394: Could not get feature set.");
    dc1394_feature_print_all(&features, stdout);
    fflush(stdout);

    return;
}