示例#1
0
void ofxLibdc::applySettings() {
	if(camera)
		dc1394_capture_stop(camera);
		
	if(use1394b) {
		// assumes you want to run your 1394b camera at 800 Mbps
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_800);
	} else {
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_LEGACY);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
	}
		
	dc1394framerate_t framerate;
	if(useFormat7) {
		videoMode = (dc1394video_mode_t) ((int) DC1394_VIDEO_MODE_FORMAT7_0 + format7Mode);
	} else {
		dc1394video_modes_t video_modes;
		dc1394_video_get_supported_modes(camera, &video_modes);
		dc1394color_coding_t coding;
		dc1394color_coding_t targetCoding = getLibdcType(imageType);
		for (int i = 0; i < video_modes.num; i++) {
			if (!dc1394_is_video_mode_scalable(video_modes.modes[i])) {
				dc1394video_mode_t curMode = video_modes.modes[i];
				dc1394_get_color_coding_from_video_mode(camera, curMode, &coding);
				unsigned int curWidth, curHeight;
				dc1394_get_image_size_from_video_mode(camera, curMode, &curWidth, &curHeight);
				if (coding == targetCoding && width == curWidth && height == curHeight) {
					videoMode = curMode;
					break;
				}
			}
			if(i == video_modes.num - 1) {
				ofLog(OF_LOG_ERROR, "Camera does not support target mode.");
				return;
			}
		}
		
		// get fastest framerate
		// todo: make this settable
		dc1394framerates_t framerates;
		dc1394_video_get_supported_framerates(camera, videoMode, &framerates);
		framerate = framerates.framerates[framerates.num - 1];
	}
	
	if(useFormat7) {
		quantizePosition();
		quantizeSize();
		dc1394_format7_set_roi(camera, videoMode, getLibdcType(imageType), DC1394_USE_MAX_AVAIL, left, top, width, height);
		unsigned int curWidth, curHeight;
		dc1394_format7_get_image_size(camera, videoMode, &curWidth, &curHeight);
	} else {
		dc1394_video_set_framerate(camera, framerate);
	}
	
	// contrary to the libdc1394 format7 demo, this should go after the roi setting
	dc1394_video_set_mode(camera, videoMode);
		
	dc1394_capture_setup(camera, OFXLIBDC_BUFFER_SIZE, DC1394_CAPTURE_FLAGS_DEFAULT);
}
示例#2
0
void FirewireVideo::init_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    dc1394framerate_t framerate
    ) {

    if(video_mode>=DC1394_VIDEO_MODE_FORMAT7_0)
      throw VideoException("format7 modes need to be initialized through the constructor that allows for specifying the roi");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }


    cout << "Using camera with GUID " << camera->guid << endl;

    //-----------------------------------------------------------------------
    //  setup capture
    //-----------------------------------------------------------------------

    if( iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
            throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set video mode");

    err=dc1394_video_set_framerate(camera, framerate);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set framerate");

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    //-----------------------------------------------------------------------
    //  initialise width and height from mode
    //-----------------------------------------------------------------------
    dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height);

    Start();
}
示例#3
0
文件: libFW.c 项目: Linnara/yFirewire
int _setupCam(long yExpo, long yGain, long *sizex, long *sizey, long speed){
  dc1394camera_list_t * list;
  dc1394_t *d = dc1394_new ();
  if (!d)
    return -1;

  dc1394speed_t iso_speed;
   if(speed == 400) 
     iso_speed = DC1394_ISO_SPEED_400; 
   else if(speed == 800) 
     iso_speed = DC1394_ISO_SPEED_800; 
   else 
     return -1; 
   //iso_speed = DC1394_ISO_SPEED_400;

  dc1394_log_register_handler(DC1394_LOG_WARNING, NULL, NULL);
  err=dc1394_camera_enumerate (d, &list);
  DC1394_ERR_RTN(err,"Failed to enumerate cameras");
	
  if (list->num == 0) {
    dc1394_log_error("No cameras found");
    return -1;
  }
	
  camera = dc1394_camera_new (d, list->ids[0].guid);
  if (!camera) {
    dc1394_log_error("Failed to initialize camera with guid %lld", list->ids[0].guid);
    return -1;
  }
  dc1394_camera_free_list (list);
	
  printf("Using camera with GUID %lld\n", camera->guid);
	
  release_iso_and_bw();

  uint32_t expo = yExpo; 
  uint32_t gain = yGain;

  /*-----------------------------------------------------------------------
   *  setup capture
   *-----------------------------------------------------------------------*/
  dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not set operation mode");

  err=dc1394_video_set_iso_speed(camera, iso_speed);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not set iso speed");

  _setVideoMode(0, sizex, sizey);

  err=dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, gain);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not define gain");

  err=dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, expo);
  DC1394_ERR_CLN_RTN(err,_unsetupCam(),"Could not define shutter");

  return 0;
}
示例#4
0
int main(int argc,char *argv[])
{
  XEvent xev;
  XGCValues xgcv;
  long background=0x010203;
  int i, j;
  dc1394_t * d;
  dc1394camera_list_t * list;

  get_options(argc,argv);
  /* process options */
  switch(fps) {
  case 1: fps =        DC1394_FRAMERATE_1_875; break;
  case 3: fps =        DC1394_FRAMERATE_3_75; break;
  case 15: fps = DC1394_FRAMERATE_15; break;
  case 30: fps = DC1394_FRAMERATE_30; break;
  case 60: fps = DC1394_FRAMERATE_60; break;
  default: fps = DC1394_FRAMERATE_7_5; break;
  }
  switch(res) {
  case 1:
    res = DC1394_VIDEO_MODE_640x480_YUV411;
    device_width=640;
    device_height=480;
    format=XV_YUY2;
    break;
  case 2:
    res = DC1394_VIDEO_MODE_640x480_RGB8;
    device_width=640;
    device_height=480;
    format=XV_YUY2;
    break;
  case 3:
    res = DC1394_VIDEO_MODE_800x600_YUV422;
    device_width=800;
    device_height=600;
    format=XV_UYVY;
    break;
  default:
    res = DC1394_VIDEO_MODE_320x240_YUV422;
    device_width=320;
    device_height=240;
    format=XV_UYVY;
    break;
  }

  dc1394error_t err;

  d = dc1394_new ();
  if (!d)
    return 1;
  err=dc1394_camera_enumerate (d, &list);
  DC1394_ERR_RTN(err,"Failed to enumerate cameras");

  if (list->num == 0) {
    dc1394_log_error("No cameras found");
    return 1;
  }

  j = 0;
  for (i = 0; i < list->num; i++) {
    if (j >= MAX_CAMERAS)
      break;
    cameras[j] = dc1394_camera_new (d, list->ids[i].guid);
    if (!cameras[j]) {
      dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[i].guid);
      continue;
    }
    j++;
  }
  numCameras = j;
  dc1394_camera_free_list (list);

  if (numCameras == 0) {
    dc1394_log_error("No cameras found");
    exit (1);
  }

  /* setup cameras for capture */
  for (i = 0; i < numCameras; i++) {
      
    //err=dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_400);
    //dc1394_video_set_operation_mode(my_camera_ptr[i], DC1394_OPERATION_MODE_1394B);
    err= dc1394_video_set_operation_mode(cameras[i], DC1394_OPERATION_MODE_1394B);
    err=dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_800);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set ISO speed");

    err=dc1394_video_set_mode(cameras[i], res);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set video mode");

    err=dc1394_video_set_framerate(cameras[i], fps);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set framerate");

    err=dc1394_capture_setup(cameras[i],NUM_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera");

    err=dc1394_video_set_transmission(cameras[i], DC1394_ON);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not start camera iso transmission");

    // Camera settings
    err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_SHUTTER,1400);
    err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_BRIGHTNESS,800);
    err = dc1394_feature_set_value(cameras[i],DC1394_FEATURE_EXPOSURE,150);
    err = dc1394_feature_whitebalance_set_value(cameras[i],500,400);

  }

  fflush(stdout);
  if (numCameras < 1) {
    perror("no cameras found :(\n");
    cleanup();
    exit(-1);
  }

  switch(format){
  case XV_YV12:
    set_frame_length(device_width*device_height*3/2, numCameras);
    break;
  case XV_YUY2:
  case XV_UYVY:
    set_frame_length(device_width*device_height*2, numCameras);
    break;
  default:
    dc1394_log_error("Unknown format set (internal error)");
    exit(255);
  }

  /* make the window */
  display=XOpenDisplay(getenv("DISPLAY"));
  if(display==NULL) {
    dc1394_log_error("Could not open display \"%s\"",getenv("DISPLAY"));
    cleanup();
    exit(-1);
  }

  QueryXv();

  if ( adaptor < 0 ) {
    cleanup();
    exit(-1);
  }

  width=device_width;
  height=device_height * numCameras;
  //width=device_width * numCameras;
  //height=device_height;

  window=XCreateSimpleWindow(display,DefaultRootWindow(display),0,0,width,height,0,
			     WhitePixel(display,DefaultScreen(display)),
			     background);

  XSelectInput(display,window,StructureNotifyMask|KeyPressMask);
  XMapWindow(display,window);
  connection=ConnectionNumber(display);

  gc=XCreateGC(display,window,0,&xgcv);

  /* main event loop */
  while(1){

    for (i = 0; i < numCameras; i++) {
      if (dc1394_capture_dequeue(cameras[i], DC1394_CAPTURE_POLICY_WAIT, &frames[i])!=DC1394_SUCCESS)
	dc1394_log_error("Failed to capture from camera %d", i);
    }

    display_frames();
    XFlush(display);

    while(XPending(display)>0){
      XNextEvent(display,&xev);
      switch(xev.type){
      case ConfigureNotify:
	width=xev.xconfigure.width;
	height=xev.xconfigure.height;
	display_frames();
	break;
      case KeyPress:
	switch(XKeycodeToKeysym(display,xev.xkey.keycode,0)){
	case XK_q:
	case XK_Q:
	  cleanup();
	  exit(0);
	  break;
	case XK_comma:
	case XK_less:
	  //width=width/2;
	  //height=height/2;
	  width--;
	  XResizeWindow(display,window,width,height);
	  display_frames();
	  break;
	case XK_period:
	case XK_greater:
	  //width=2*width;
	  //height=2*height;
	  width++;
	  XResizeWindow(display,window,width,height);
	  display_frames();
	  break;
	case XK_0:
	  freeze = !freeze;
	  break;
	case XK_1:
	  fps =        DC1394_FRAMERATE_1_875;
	  for (i = 0; i < numCameras; i++)
	    dc1394_video_set_framerate(cameras[i], fps);
	  break;
	case XK_2:
	  fps =        DC1394_FRAMERATE_3_75;
	  for (i = 0; i < numCameras; i++)
	    dc1394_video_set_framerate(cameras[i], fps);
	  break;
	case XK_4:
	  fps = DC1394_FRAMERATE_15;
	  for (i = 0; i < numCameras; i++)
	    dc1394_video_set_framerate(cameras[i], fps);
	  break;
	case XK_5:
	  fps = DC1394_FRAMERATE_30;
	  for (i = 0; i < numCameras; i++)
	    dc1394_video_set_framerate(cameras[i], fps);
	  break;
	case XK_3:
	  fps = DC1394_FRAMERATE_7_5;
	  for (i = 0; i < numCameras; i++)
	    dc1394_video_set_framerate(cameras[i], fps);
	  break;
	}
	break;
      }
    } /* XPending */

    for (i = 0; i < numCameras; i++) {
      if (frames[i])
	dc1394_capture_enqueue (cameras[i], frames[i]);
    }

  } /* while not interrupted */

  exit(0);
}
示例#5
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;
}
示例#6
0
//=============================================================================
// setStereoVideoCapture()
//
// Given that the camera handle is a stereo camera, query the camera for 
// stereo specific information about this camera and populate the 
// PGRStereoCamera_t handle structure
//
// note: currently always allocated maximum framerate
dc1394error_t
setStereoVideoCapture( PGRStereoCamera_t* stereoCamera )
{
   dc1394error_t 	err;
   dc1394color_coding_t	coding;

   switch( stereoCamera->model )
   {
      case BUMBLEBEE:
	 dc1394video_mode_t 	videoMode;
	 dc1394framerate_t 	fps;

	 // note: both B&W and Bayer Bumblebees transmit in mono mode
	 if ( stereoCamera->nCols == 640 )
	 {
	    // lo res 
            printf("capture mode: DC1394_VIDEO_MODE_640x480_MONO16 ");
            printf("capture mode: %d\n", DC1394_VIDEO_MODE_640x480_MONO16);
	    videoMode 	= DC1394_VIDEO_MODE_640x480_MONO16;
	    fps		= DC1394_FRAMERATE_30;
	 }
	 else
	 {
            printf("capture mode: DC1394_VIDEO_MODE_1024x768_MONO16 ");
            printf("capture mode: %d\n", DC1394_VIDEO_MODE_1024x768_MONO16);
	    // assume hi res 
	    videoMode 	= DC1394_VIDEO_MODE_1024x768_MONO16;
	    fps		= DC1394_FRAMERATE_15;
	 }
	 
	 // make the calls to set up the capture mode
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_400 );
	 dc1394_video_set_mode(      stereoCamera->camera, videoMode );
	 dc1394_video_set_framerate( stereoCamera->camera, fps );
	 err = dc1394_capture_setup( stereoCamera->camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      case BUMBLEBEE2:
	 // Bumblebee2 transmits stereo images in Format 7

	 // load the factory defaults - this is auto-everything
	 err = dc1394_memory_load( stereoCamera->camera, 0 );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't load default memory channel\n" );
	    return err;
	 }

	 // set 16-bit transmission to be PGR-default little endian mode
	 err = setEndian( stereoCamera->camera, false );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't set Bumblebee2 into little-endian mode\n" );
	    return err;
	 }

	 // color cameras transmit in "RAW16", mono cameras in "MONO16"
	 coding	= DC1394_COLOR_CODING_MONO16;
	 if ( stereoCamera->bColor )
	    coding = DC1394_COLOR_CODING_RAW16;
	 
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_400 );
	 dc1394_video_set_mode( stereoCamera->camera, DC1394_VIDEO_MODE_FORMAT7_3 );

	 err = dc1394_format7_set_roi( stereoCamera->camera,
				       DC1394_VIDEO_MODE_FORMAT7_3,
				       coding,
                                       // bytes per packet - sets frame rate
				       DC1394_USE_MAX_AVAIL, 
				       0, 
				       0,
				       stereoCamera->nCols,
				       stereoCamera->nRows );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee2 capture\n" );
	    return err;
	 }

	 err = dc1394_capture_setup( stereoCamera->camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      case BUMBLEBEEXB3:
	 // Bumblebee3 transmits stereo images in Format 7

	 // load the factory defaults - this is auto-everything
	 err = dc1394_memory_load( stereoCamera->camera, 0 );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't load default memory channel\n" );
	    return err;
	 }


	 if ( stereoCamera->nBytesPerPixel == 2 )
	 {
	    // run in 2 camera mode

	    // NOTE: this code will always only set up the wide-baseline pair
	    // To change to the inner baseline pair you need to set the PAN
	    // register to 1.
	    // PAN = 0 is the wide baseline pair which is set by default.
	    // To change to all 3 images being transmitted you need to change
	    // modes to "coding	= DC1394_COLOR_CODING_RGB8;"
	    //

	    // set 16-bit transmission to be PGR-default little endian mode
	    err = setEndian( stereoCamera->camera, false );
	    if ( err != DC1394_SUCCESS ) 
	    {
	       fprintf( stderr, "Can't set Bumblebee2 into little-endian mode\n" );
	       return err;
	    }

	    // color cameras transmit in "RAW16", mono cameras in "MONO16"
	    coding	= DC1394_COLOR_CODING_MONO16;
	    if ( stereoCamera->bColor )
	       coding = DC1394_COLOR_CODING_RAW16;
	 }
	 else
	 {
	    // 3 camera mode transmits in RGB8
	    coding	= DC1394_COLOR_CODING_RGB8;
	 }

	 // assume the XB is plugged into a 1394B network
	 // XB3 can work with a 1394A bus but code changes will be required
	 dc1394_video_set_operation_mode( stereoCamera->camera, DC1394_OPERATION_MODE_1394B );
	 dc1394_video_set_iso_speed( stereoCamera->camera, DC1394_ISO_SPEED_800 );
	 dc1394_video_set_mode( stereoCamera->camera, DC1394_VIDEO_MODE_FORMAT7_3 );
	 err = dc1394_format7_set_roi( stereoCamera->camera,
				       DC1394_VIDEO_MODE_FORMAT7_3,
				       coding,
                                       // bytes per packet - sets frame rate
				       DC1394_USE_MAX_AVAIL, 
				       0, 
				       0,
				       stereoCamera->nCols,
				       stereoCamera->nRows );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee XB3 capture\n" );
	    return err;
	 }

	 err = dc1394_capture_setup( stereoCamera->camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT );
	 if ( err != DC1394_SUCCESS ) 
	 {
	    fprintf( stderr, "Can't setup Bumblebee capture\n" );
	    return err;
	 }
	 break;

      default:
	 fprintf( stderr, 
		  "setStereoVideoCapture() - \n"
		  "\tThis camera is not a supported stereo camera!\n" );
	 return DC1394_FAILURE;
   }

   // get the bayer tile info so we will know how to color process
   // this mode
   err = getBayerTile( stereoCamera->camera,
		       &stereoCamera->bayerTile );
   if ( err != DC1394_SUCCESS )
   {
      fprintf( stderr, "Could not query the Bayer Tile Register!\n" );
      return err;
   }

   return DC1394_SUCCESS;
}
示例#7
0
static gboolean
gst_dc1394_open_cam_with_best_caps (GstDc1394 * src)
{
    dc1394camera_list_t *cameras = NULL;
    gint err = 0;
    int framerateconst;

    GST_LOG_OBJECT (src, "Opening the camera!!!");


    if (dc1394_camera_enumerate (src->dc1394, &cameras) != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Can't find cameras"),
                           ("Can't find cameras"));
        goto error;
    }

    GST_LOG_OBJECT (src, "Found  %d  cameras", cameras->num);

    if (src->camnum > (cameras->num - 1)) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Invalid camera number"),
                           ("Invalid camera number"));
        goto error;
    }

    GST_LOG_OBJECT (src, "Opening camera : %d", src->camnum);

    src->camera =
        dc1394_camera_new_unit (src->dc1394, cameras->ids[src->camnum].guid,
                                cameras->ids[src->camnum].unit);

    dc1394_camera_free_list (cameras);
    cameras = NULL;

    // figure out mode
    framerateconst = gst_dc1394_framerate_frac_to_const (src->rate_numerator,
                     src->rate_denominator);

    GST_LOG_OBJECT (src, "The dma buffer queue size is %d  buffers",
                    src->bufsize);

    switch (src->iso_speed) {
    case 100:
        err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_100);
        break;
    case 200:
        err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_200);
        break;
    case 400:
        err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_400);
        break;
    case 800:
        if (src->camera->bmode_capable > 0) {
            dc1394_video_set_operation_mode (src->camera,
                                             DC1394_OPERATION_MODE_1394B);
            err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_800);
        }
        break;
    case 1600:
        if (src->camera->bmode_capable > 0) {
            dc1394_video_set_operation_mode (src->camera,
                                             DC1394_OPERATION_MODE_1394B);
            err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_1600);
        }
        break;
    case 3200:
        if (src->camera->bmode_capable > 0) {
            dc1394_video_set_operation_mode (src->camera,
                                             DC1394_OPERATION_MODE_1394B);
            err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_3200);
        }
        break;
    default:
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Invalid ISO speed"),
                           ("Invalid ISO speed"));
        goto error;
        break;
    }

    if (err != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set ISO speed"),
                           ("Could not set ISO speed"));
        goto error;
    }

    GST_LOG_OBJECT (src, "Setting mode :  %d", src->vmode);
    err = dc1394_video_set_mode (src->camera, src->vmode);

    if (err != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set video mode %d",
                           src->vmode), ("Could not set video mode %d", src->vmode));
        goto error;
    }

    GST_LOG_OBJECT (src, "Setting framerate :  %d", framerateconst);
    dc1394_video_set_framerate (src->camera, framerateconst);

    if (err != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set framerate to %d",
                           framerateconst), ("Could not set framerate to %d", framerateconst));
        goto error;
    }
    // set any format-7 parameters if this is a format-7 mode
    if (src->vmode >= DC1394_VIDEO_MODE_FORMAT7_MIN &&
            src->vmode <= DC1394_VIDEO_MODE_FORMAT7_MAX) {
        // the big thing we care about right now is frame size
        err = dc1394_format7_set_image_size (src->camera, src->vmode,
                                             src->width, src->height);
        if (err != DC1394_SUCCESS) {
            GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                               ("Could not set format 7 image size to %d x %d", src->width,
                                src->height), ("Could not set format 7 image size to %d x %d",
                                               src->width, src->height));

            goto error;
        }

    }
    err = dc1394_capture_setup (src->camera, src->bufsize,
                                DC1394_CAPTURE_FLAGS_DEFAULT);
    if (err != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error setting capture mode"),
                           ("Error setting capture mode"));
    }
    if (err != DC1394_SUCCESS) {
        if (err == DC1394_NO_BANDWIDTH) {
            GST_LOG_OBJECT (src, "Capture setup_dma failed."
                            "Trying to cleanup the iso_channels_and_bandwidth and retrying");

            // try to cleanup the bandwidth and retry
            err = dc1394_iso_release_all (src->camera);
            if (err != DC1394_SUCCESS) {
                GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                                   ("Could not cleanup bandwidth"), ("Could not cleanup bandwidth"));
                goto error;
            } else {
                err =
                    dc1394_capture_setup (src->camera, src->bufsize,
                                          DC1394_CAPTURE_FLAGS_DEFAULT);
                if (err != DC1394_SUCCESS) {
                    GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                                       ("unable to setup camera error %d", err),
                                       ("unable to setup camera error %d", err));
                    goto error;
                }
            }
        } else {
            GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                               ("unable to setup camera error %d", err),
                               ("unable to setup camera error %d", err));
            goto error;

        }
    }


    return TRUE;

error:

    if (src->camera) {
        dc1394_camera_free (src->camera);
        src->camera = NULL;
    }

    return FALSE;

}
示例#8
0
static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
    dc1394_data* dc1394 = c->priv_data;
    dc1394camera_list_t *list;
    int res, i;
    struct dc1394_frame_format *fmt = NULL;
    struct dc1394_frame_rate *fps = NULL;

    if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
       return -1;

    /* Now let us prep the hardware. */
    dc1394->d = dc1394_new();
    dc1394_camera_enumerate (dc1394->d, &list);
    if ( !list || list->num == 0) {
        av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera\n\n");
        goto out;
    }

    /* FIXME: To select a specific camera I need to search in list its guid */
    dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid);
    if (list->num > 1) {
        av_log(c, AV_LOG_INFO, "Working with the first camera found\n");
    }

    /* Freeing list of cameras */
    dc1394_camera_free_list (list);

    /* Select MAX Speed possible from the cam */
    if (dc1394->camera->bmode_capable>0) {
       dc1394_video_set_operation_mode(dc1394->camera, DC1394_OPERATION_MODE_1394B);
       i = DC1394_ISO_SPEED_800;
    } else {
       i = DC1394_ISO_SPEED_400;
    }

    for (res = DC1394_FAILURE; i >= DC1394_ISO_SPEED_MIN && res != DC1394_SUCCESS; i--) {
            res=dc1394_video_set_iso_speed(dc1394->camera, i);
    }
    if (res != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Couldn't set ISO Speed\n");
        goto out_camera;
    }

    if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Couldn't set video format\n");
        goto out_camera;
    }

    if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate);
        goto out_camera;
    }
    if (dc1394_capture_setup(dc1394->camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Cannot setup camera \n");
        goto out_camera;
    }

    if (dc1394_video_set_transmission(dc1394->camera, DC1394_ON) !=DC1394_SUCCESS) {
        av_log(c, AV_LOG_ERROR, "Cannot start capture\n");
        goto out_camera;
    }
    return 0;

out_camera:
    dc1394_capture_stop(dc1394->camera);
    dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
    dc1394_camera_free (dc1394->camera);
out:
    dc1394_free(dc1394->d);
    return -1;
}
示例#9
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;
}
示例#10
0
// Note:
// the following was tested on a IIDC camera over USB therefore might not work as
// well on a camera over proper firewire transport
void FirewireVideo::init_format7_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    float framerate,
    uint32_t width, uint32_t height,
    uint32_t left, uint32_t top, bool reset_at_boot
    ) {

    if(video_mode< DC1394_VIDEO_MODE_FORMAT7_0)
        throw VideoException("roi can be specified only for format7 modes");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }

    cout << "Using camera with GUID " << camera->guid << endl;

    if(reset_at_boot){
      dc1394_camera_reset(camera);
    }

    //-----------------------------------------------------------------------
    //  setup mode and roi
    //-----------------------------------------------------------------------

    if(iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
           throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    // check that the required mode is actually supported
    dc1394format7mode_t format7_info;

    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // safely set the video mode
    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 video mode");

    // set position to 0,0 so that setting any size within min and max is a valid command
    err = dc1394_format7_set_image_position(camera, video_mode,0,0);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 image position");

    // work out the desired image size
    width = nearest_value(width, format7_info.unit_pos_x, 0, format7_info.max_size_x - left);
    height = nearest_value(height, format7_info.unit_pos_y, 0, format7_info.max_size_y - top);

    // set size
    err = dc1394_format7_set_image_size(camera,video_mode,width,height);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    // get the info again since many parameters depend on image size
    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // work out position of roi
    left = nearest_value(left, format7_info.unit_size_x, format7_info.unit_size_x, format7_info.max_size_x - width);
    top = nearest_value(top, format7_info.unit_size_y, format7_info.unit_size_y, format7_info.max_size_y - height);

    // set roi position
    err = dc1394_format7_set_image_position(camera,video_mode,left,top);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    this->width = width;
    this->height = height;
    this->top = top;
    this->left = left;

    cout<<"roi: "<<left<<" "<<top<<" "<<width<<" "<<height<<"  ";


    //-----------------------------------------------------------------------
    //  setup frame rate
    //-----------------------------------------------------------------------

    err=dc1394_format7_set_packet_size(camera,video_mode, format7_info.max_packet_size);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 packet size");

    if((framerate != MAX_FR) && (framerate != EXT_TRIG)){
      //set the framerate by using the absolute feature as suggested by the
      //folks at PointGrey
      err = dc1394_feature_set_absolute_control(camera,DC1394_FEATURE_FRAME_RATE,DC1394_ON);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not turn on absolute frame rate control");

      err = dc1394_feature_set_mode(camera,DC1394_FEATURE_FRAME_RATE,DC1394_FEATURE_MODE_MANUAL);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not make frame rate manual ");

      err=dc1394_feature_set_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,framerate);
      if( err != DC1394_SUCCESS )
          throw VideoException("Could not set format7 framerate ");
    }

    // ask the camera what is the resulting framerate (this assume that such a rate is actually
    // allowed by the shutter time)
    float value;
    err=dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,&value);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not get framerate");

    cout<<" framerate(shutter permitting):"<<value<<endl;

    //-----------------------------------------------------------------------
    //  setup capture
    //-----------------------------------------------------------------------

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    Start();

}
示例#11
0
int main(int argc, const char * argv[]) {

    dc1394_t *d;
    dc1394camera_list_t *list;
    dc1394error_t err;
    dc1394camera_t *camera;
    dc1394format7modeset_t modeset;
    dc1394video_frame_t *frame;
    FILE* imagefile;
    char filename[256];
    int i = 0;

    d = dc1394_new();
    if (!d) {
        return 1;
    }

    err = dc1394_camera_enumerate(d, &list);
    DC1394_ERR_RTN(err, "Failed to enumerate cameras");
    if (list->num == 0) {
        dc1394_log_error("No cameras found");
        dc1394_free(d);
        return 1;
    }
    printf("Detected %d cameras\n", list->num);

    // Assume that Ladybug 5 is detected as camera #0
    camera = dc1394_camera_new(d, list->ids[0].guid);
    if (!camera) {
        dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid);
        dc1394_free(d);
    }
    dc1394_camera_free_list(list);
    printf("Using camera %s %s\n", camera->vendor, camera->model);

    // Report camera info
    err = dc1394_camera_print_info(camera, stdout);
    DC1394_ERR_RTN(err, "Could not print camera info");


    // Setup video mode, etc...
    err = dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
    DC1394_ERR_RTN(err, "Could not set B mode");
    err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_MAX);
    DC1394_ERR_RTN(err, "Could not set max speed");
    err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0);
    DC1394_ERR_RTN(err, "Could not set DC1394_VIDEO_MODE_FORMAT7_0");

    // Get format7 mode info
    err = dc1394_format7_get_modeset(camera, &modeset);
    DC1394_ERR_RTN(err, "Could not get format 7 mode info\n");
    print_format7_info(&modeset);


    // Set format 7 roi
    err = dc1394_format7_set_roi(camera,
                                 DC1394_VIDEO_MODE_FORMAT7_0,
                                 modeset.mode[0].color_coding,
                                 modeset.mode[0].max_packet_size,
                                 modeset.mode[0].pos_x,
                                 modeset.mode[0].pos_y,
                                 modeset.mode[0].max_size_x,
                                 modeset.mode[0].max_size_y);
    DC1394_ERR_RTN(err, "Could not set max ROI");

    // Set capture
    err = dc1394_capture_setup(camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT);
    DC1394_ERR_RTN(err, "Could not setup capture");
    err = dc1394_video_set_transmission(camera, DC1394_ON);
    DC1394_ERR_RTN(err, "Could not start transmission");

    while (i < NFRAMES) {
        // Capture image
        printf("Capturing image %d\n", i);
        err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
        DC1394_ERR_RTN(err, "Could not dequeue a frame");
        
        // Do something with the image
        print_frame_info(frame);

        // Save the image
        sprintf(filename, "%05d.pgm",i);
        imagefile = fopen(filename, "wb");
        if ( imagefile == NULL ) {
            printf("Could not save image\n");
            continue;
        }
        fprintf(imagefile, "P5\n%u %u 255\n", frame->size[0], frame->size[1]);
        fwrite(frame->image, 1, frame->image_bytes, imagefile);
        fclose(imagefile);
        printf("Saved image %s\n", filename);

        err = dc1394_capture_enqueue(camera, frame);
        DC1394_ERR_RTN(err, "Could enqueue a frame");

        i++;
    }

    dc1394_camera_free(camera);
    dc1394_free(d);
    return 0;
}
示例#12
0
// Note:
// the following was tested on a IIDC camera over USB therefore might not work as
// well on a camera over proper firewire transport
void FirewireVideo::init_format7_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    int framerate,
    uint32_t width, uint32_t height,
    uint32_t left, uint32_t top, bool reset_at_boot
    ) {

    if(video_mode< DC1394_VIDEO_MODE_FORMAT7_0)
        throw VideoException("roi can be specified only for format7 modes");

    camera = dc1394_camera_new (d, guid);
    if (!camera)
        throw VideoException("Failed to initialize camera");

    // Attempt to stop camera if it is already running
    dc1394switch_t is_iso_on = DC1394_OFF;
    dc1394_video_get_transmission(camera, &is_iso_on);
    if (is_iso_on==DC1394_ON) {
        dc1394_video_set_transmission(camera, DC1394_OFF);
    }

    cout << "Using camera with GUID " << camera->guid << endl;

    if(reset_at_boot){
      dc1394_camera_reset(camera);
    }

    //-----------------------------------------------------------------------
    //  setup mode and roi
    //-----------------------------------------------------------------------

    if(iso_speed >= DC1394_ISO_SPEED_800)
    {
        err=dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
        if( err != DC1394_SUCCESS )
           throw VideoException("Could not set DC1394_OPERATION_MODE_1394B");
    }

    err=dc1394_video_set_iso_speed(camera, iso_speed);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set iso speed");

    // check that the required mode is actually supported
    dc1394format7mode_t format7_info;

    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // safely set the video mode
    err=dc1394_video_set_mode(camera, video_mode);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 video mode");

    // set position to 0,0 so that setting any size within min and max is a valid command
    err = dc1394_format7_set_image_position(camera, video_mode,0,0);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 image position");

    // work out the desired image size
    width = nearest_value(width, format7_info.unit_pos_x, 0, format7_info.max_size_x - left);
    height = nearest_value(height, format7_info.unit_pos_y, 0, format7_info.max_size_y - top);

    // set size
    err = dc1394_format7_set_image_size(camera,video_mode,width,height);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    // get the info again since many parameters depend on image size
    err = dc1394_format7_get_mode_info(camera, video_mode, &format7_info);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not get format7 mode info");

    // work out position of roi
    left = nearest_value(left, format7_info.unit_size_x, format7_info.unit_size_x, format7_info.max_size_x - width);
    top = nearest_value(top, format7_info.unit_size_y, format7_info.unit_size_y, format7_info.max_size_y - height);

    // set roi position
    err = dc1394_format7_set_image_position(camera,video_mode,left,top);
    if( err != DC1394_SUCCESS )
      throw VideoException("Could not set format7 size");

    this->width = width;
    this->height = height;
    this->top = top;
    this->left = left;

    cout<<"roi: "<<left<<" "<<top<<" "<<width<<" "<<height<<"  ";


    //-----------------------------------------------------------------------
    //  setup frame rate
    //-----------------------------------------------------------------------

    if((framerate == MAX_FR)||(framerate == EXT_TRIG)){

      err=dc1394_format7_set_packet_size(camera,video_mode, format7_info.max_packet_size);
      if( err != DC1394_SUCCESS )
        throw VideoException("Could not set format7 packet size");

    } else {

      // setting packet size to get the desired frame rate according to the libdc docs
      // does not do the trick, so for now we support only max frame rate

        throw VideoException("In format 7 only max frame rate is currently supported");
      //      uint32_t depth;
      //      err = dc1394_format7_get_data_depth(camera, video_mode, &depth);
      //      if( err != DC1394_SUCCESS )
      //        throw VideoException("Could not get format7 depth");
      //
      //      // the following is straight from the libdc docs
      //      double bus_period = bus_period_from_iso_speed(iso_speed);
      //
      //      // work out the max number of packets that the bus can deliver
      //      int num_packets = (int) (1.0/(bus_period*framerate) + 0.5);
      //
      //      if((num_packets > 4095)||(num_packets < 0))
      //        throw VideoException("number of format7 packets out of range");
      //
      //      // work out what the packet size should be for the requested size and framerate
      //      uint32_t packet_size = (width*964*depth + (num_packets*8) - 1)/(num_packets*8);
      //      packet_size = nearest_value(packet_size,format7_info.unit_packet_size,format7_info.unit_packet_size,format7_info.max_packet_size);
      //
      //      if(packet_size > format7_info.max_packet_size){
      //        throw VideoException("format7 requested frame rate and size exceed bus bandwidth");
      //      }
      //
      //      err=dc1394_format7_set_packet_size(camera,video_mode, packet_size);
      //      if( err != DC1394_SUCCESS ){
      //        throw VideoException("Could not set format7 packet size");
      //      }
    }

    // ask the camera what is the resulting framerate (this assume that such a rate is actually
    // allowed by the shutter time)
    err = dc1394_feature_set_power(camera,DC1394_FEATURE_FRAME_RATE,DC1394_OFF);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not turn off frame rate");

    float value;
    err=dc1394_feature_get_absolute_value(camera,DC1394_FEATURE_FRAME_RATE,&value);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not get framerate");

    cout<<" framerate(shutter permitting):"<<value<<endl;

    //-----------------------------------------------------------------------
    //  setup capture
    //-----------------------------------------------------------------------

    err=dc1394_capture_setup(camera,dma_frames, DC1394_CAPTURE_FLAGS_DEFAULT);
    if( err != DC1394_SUCCESS )
        throw VideoException("Could not setup camera - check settings");

    Start();

}
示例#13
0
bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
{
    int i;
    int code = 0;
    if (!dcCam)
        return false;
    if (isoSpeed > 0)
    {
        // if capable set operation mode to 1394b for iso speeds above 400
        if (isoSpeed > 400 && dcCam->bmode_capable == DC1394_TRUE)
        {
            dc1394_video_set_operation_mode(dcCam, DC1394_OPERATION_MODE_1394B);
        }
        code = dc1394_video_set_iso_speed(dcCam,
                                          isoSpeed <= 100 ? DC1394_ISO_SPEED_100 :
                                          isoSpeed <= 200 ? DC1394_ISO_SPEED_200 :
                                          isoSpeed <= 400 ? DC1394_ISO_SPEED_400 :
                                          isoSpeed <= 800 ? DC1394_ISO_SPEED_800 :
                                          isoSpeed == 1600 ? DC1394_ISO_SPEED_1600 :
                                          DC1394_ISO_SPEED_3200);
    }

    // should a specific mode be used
    if (userMode >= 0)

    {
        dc1394video_mode_t wantedMode;
        dc1394video_modes_t videoModes;
        dc1394_video_get_supported_modes(dcCam, &videoModes);

        //set mode from number, for example the second supported mode, i.e userMode = 1

        if (userMode < (int)videoModes.num)
        {
            wantedMode = videoModes.modes[userMode];
        }

        //set modes directly from DC134 constants (from dc1394video_mode_t)
        else if ((userMode >= DC1394_VIDEO_MODE_MIN) && (userMode <= DC1394_VIDEO_MODE_MAX ))
        {
            //search for wanted mode, to check if camera supports it
            int j = 0;
            while ((j< (int)videoModes.num) && videoModes.modes[j]!=userMode)
            {
                j++;
            }

            if ((int)videoModes.modes[j]==userMode)
            {
                wantedMode = videoModes.modes[j];
            }
            else
            {
                userMode = -1;  // wanted mode not supported, search for best mode
            }
        }
        else
        {
            userMode = -1;      // wanted mode not supported, search for best mode
        }
        //if userMode is available: set it and update size
        if (userMode != -1)
        {
            code = dc1394_video_set_mode(dcCam, wantedMode);
            uint32_t width, height;
            dc1394_get_image_size_from_video_mode(dcCam, wantedMode, &width, &height);
            frameWidth  = (int)width;
            frameHeight = (int)height;
        }
    }

    if (userMode == -1 && (frameWidth > 0 || frameHeight > 0))
    {
        dc1394video_mode_t bestMode = (dc1394video_mode_t) - 1;
        dc1394video_modes_t videoModes;
        dc1394_video_get_supported_modes(dcCam, &videoModes);
        for (i = 0; i < (int)videoModes.num; i++)
        {
            dc1394video_mode_t mode = videoModes.modes[i];
            if (mode >= DC1394_VIDEO_MODE_FORMAT7_MIN && mode <= DC1394_VIDEO_MODE_FORMAT7_MAX)
                continue;
            int pref = -1;
            dc1394color_coding_t colorCoding;
            dc1394_get_color_coding_from_video_mode(dcCam, mode, &colorCoding);

            uint32_t width, height;
            dc1394_get_image_size_from_video_mode(dcCam, mode, &width, &height);
            if ((int)width == frameWidth || (int)height == frameHeight)
            {
                if (colorCoding == DC1394_COLOR_CODING_RGB8 ||
                        colorCoding == DC1394_COLOR_CODING_RAW8)
                {
                    bestMode = mode;
                    break;
                }

                if (colorCoding == DC1394_COLOR_CODING_YUV411 ||
                        colorCoding == DC1394_COLOR_CODING_YUV422 ||
                        (colorCoding == DC1394_COLOR_CODING_YUV444 &&
                        pref < 1))
                {
                    bestMode = mode;
                    pref = 1;
                    break;
                }

                if (colorCoding == DC1394_COLOR_CODING_MONO8)
                {
                    bestMode = mode;
                    pref = 0;
                }
            }
        }
        if ((int)bestMode >= 0)
            code = dc1394_video_set_mode(dcCam, bestMode);
    }

    if (fps > 0)
    {
        dc1394video_mode_t mode;
        dc1394framerates_t framerates;
        double minDiff = DBL_MAX;
        dc1394framerate_t bestFps = (dc1394framerate_t) - 1;

        dc1394_video_get_mode(dcCam, &mode);
        dc1394_video_get_supported_framerates(dcCam, mode, &framerates);

        for (i = 0; i < (int)framerates.num; i++)
        {
            dc1394framerate_t ifps = framerates.framerates[i];
            double fps1 = (1 << (ifps - DC1394_FRAMERATE_1_875)) * 1.875;
            double diff = fabs(fps1 - fps);
            if (diff < minDiff)
            {
                minDiff = diff;
                bestFps = ifps;
            }
        }
        if ((int)bestFps >= 0)
            code = dc1394_video_set_framerate(dcCam, bestFps);
    }

    if (cameraId == VIDERE)
    {
        bayerFilter = DC1394_COLOR_FILTER_GBRG;
        nimages = 2;
        uint32_t value = 0;
        dc1394_get_control_register(dcCam, 0x50c, &value);
        colorStereo = (value & 0x80000000) != 0;
    }

    code = dc1394_capture_setup(dcCam, nDMABufs, DC1394_CAPTURE_FLAGS_DEFAULT);
    if (code >= 0)
    {
        FD_SET(dc1394_capture_get_fileno(dcCam), &dc1394.camFds);
        dc1394_video_set_transmission(dcCam, DC1394_ON);
        if (cameraId == VIDERE)
        {
            enum { PROC_MODE_OFF, PROC_MODE_NONE, PROC_MODE_TEST, PROC_MODE_RECTIFIED, PROC_MODE_DISPARITY, PROC_MODE_DISPARITY_RAW };
            int procMode = PROC_MODE_RECTIFIED;
            usleep(100000);
            uint32_t qval1 = 0x08000000 | (0x90 << 16) | ((procMode & 0x7) << 16);
            uint32_t qval2 = 0x08000000 | (0x9C << 16);
            dc1394_set_control_register(dcCam, 0xFF000, qval1);
            dc1394_set_control_register(dcCam, 0xFF000, qval2);
        }
        started = true;
    }

    return code >= 0;
}
示例#14
0
  /** Set ISO speed.
   *
   *  @param camera points to DC1394 camera struct
   *  @param[in,out] iso_speed Config parameter for this option,
   *                 updated if the camera does not support the
   *                 requested value
   *  @return true if ISO speed set successfully, false if not.
   *
   *  @post IEEE1394b mode enabled if camera and bus support it.
   */
  bool setIsoSpeed(dc1394camera_t *camera, int &iso_speed)
  {
    // Enable IEEE1394b mode if the camera and bus support it
    bool bmode = camera->bmode_capable;
    if (bmode
        && (DC1394_SUCCESS !=
            dc1394_video_set_operation_mode(camera,
                                            DC1394_OPERATION_MODE_1394B)))
      {
        bmode = false;
        ROS_WARN("failed to set IEEE1394b mode");
      }

    // start with highest speed supported
    dc1394speed_t request = DC1394_ISO_SPEED_3200;
    int rate = 3200;
    if (!bmode)
      {
        // not IEEE1394b capable: so 400Mb/s is the limit
        request = DC1394_ISO_SPEED_400;
        rate = 400;
      }

    // round requested speed down to next-lower defined value
    while (rate > iso_speed)
      {
        if (request <= DC1394_ISO_SPEED_MIN)
          {
            // get current ISO speed of the device
            dc1394speed_t curSpeed;
            if (DC1394_SUCCESS == dc1394_video_get_iso_speed(camera, &curSpeed)
                && curSpeed <= DC1394_ISO_SPEED_MAX)
              {
                // Translate curSpeed back to an int for the parameter
                // update, works as long as any new higher speeds keep
                // doubling.
                request = curSpeed;
                rate = 100 << (curSpeed - DC1394_ISO_SPEED_MIN);
              }
            else
              {
                ROS_WARN("Unable to get ISO speed; assuming 400Mb/s");
                rate = 400;
                request = DC1394_ISO_SPEED_400;
              }
            break;
          }

        // continue with next-lower possible value
        request = (dc1394speed_t) ((int) request - 1);
        rate = rate / 2;
      }

    // update configured rate to match selected value
    iso_speed = rate;

    // set the requested speed
    if (DC1394_SUCCESS != dc1394_video_set_iso_speed(camera, request))
      {
        ROS_WARN("Failed to set iso speed");
        return false;
      }

    return true;
  }