Beispiel #1
0
int _listFeatures(){
  if(camera==NULL) {
    dc1394_log_error("Camera is not initialised");
    return -1;
  }

    dc1394featureset_t features;

    /*-----------------------------------------------------------------------
     *  report camera's features
     *-----------------------------------------------------------------------*/
    err=dc1394_feature_get_all(camera,&features);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get feature set");
    }
    else {
        dc1394_feature_print_all(&features, stdout);
    }

    dc1394_avt_adv_feature_info_t adv_feature;
    dc1394_avt_get_advanced_feature_inquiry(camera, &adv_feature);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get adv feature set");
    }
    else {
      dc1394_avt_print_advanced_feature(&adv_feature);
    }

}
Beispiel #2
0
static dc1394error_t
free_resources(platform_camera_t * cam)
{
    DWORD ret = t1394IsochTearDownStream(cam->device->device_path);
    if (ret) {
        dc1394_log_warning("t1394IsochTearDownStream: Error %ld\n", ret);
        return DC1394_FAILURE;
    }
    return DC1394_SUCCESS;
}
int main(int argc, char *argv[]) {
	unsigned int i;
	dc1394_t * d;
	dc1394camera_list_t * list;
	dc1394error_t err;
	dc1394featureset_t features;

	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;
	}

	for(i = 0; i < list->num; i++) {
		dc1394camera_t *camera = dc1394_camera_new(d, list->ids[i].guid);

		if(camera) {
			unsigned int j;
			dc1394video_modes_t modes;

			// Print hardware informations.
			dc1394_camera_print_info(camera, stdout);

			// Print supported camera features.
			err = dc1394_feature_get_all(camera,&features);
			if(err != DC1394_SUCCESS) {
				dc1394_log_warning("Could not get feature set");
			} else {
				dc1394_feature_print_all(&features, stdout);
			}

			// Print a list of supported modes.
			printf("------ Supported Video Modes ------\n");

			err = dc1394_video_get_supported_modes(camera, &modes);
			DC1394_ERR_RTN(err,"Could not get list of modes");

			for(j = 0; j < modes.num; j++) {
				print_video_mode_info(camera, modes.modes[j]);
			}

			dc1394_camera_free(camera);
		}
	}
	dc1394_camera_free_list (list);
	dc1394_free (d);

	return 0;
}
Beispiel #4
0
dc1394error_t
dc1394_juju_capture_stop(platform_camera_t *craw)
{
    dc1394camera_t * camera = craw->camera;
    struct fw_cdev_stop_iso stop;
    int i;

    if (craw->capture_is_set == 0)
        return DC1394_CAPTURE_IS_NOT_SET;

    stop.handle = craw->iso_handle;
    if (ioctl(craw->iso_fd, FW_CDEV_IOC_STOP_ISO, &stop) < 0)
        return DC1394_IOCTL_FAILURE;

    munmap(craw->buffer, craw->buffer_size);
    close(craw->iso_fd);
    for (i = 0; i<craw->num_frames; i++)
        release_frame(craw, i);
    free (craw->frames);
    craw->frames = NULL;
    craw->capture_is_set = 0;

    if (craw->capture_iso_resource) {
        if (juju_iso_deallocate (craw, craw->capture_iso_resource) < 0)
            dc1394_log_warning ("juju: Failed to deallocate iso resources");
        craw->capture_iso_resource = NULL;
    }

    // stop ISO if it was started automatically
    if (craw->iso_auto_started>0) {
        dc1394error_t err=dc1394_video_set_transmission(camera, DC1394_OFF);
        DC1394_ERR_RTN(err,"Could not stop ISO!");
        craw->iso_auto_started=0;
    }

    return DC1394_SUCCESS;
}
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);
}
Beispiel #6
0
void *pdp_dc1394_new(t_symbol *vdef)
{
    t_pdp_dc1394 *x = (t_pdp_dc1394 *)pd_new(pdp_dc1394_class);

    x->x_outlet0 = outlet_new(&x->x_obj, &s_anything);

    x->d = dc1394_new ();
    x->err=dc1394_camera_enumerate (x->d, &x->list);
    //DC1394_ERR_RTN(x->err,"Failed to enumerate cameras");
    //post("Failed to enumerate cameras");

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

    x->camera = dc1394_camera_new (x->d, x->list->ids[0].guid);
    if (!x->camera) {
        //dc1394_log_error("Failed to initialize camera with guid %"PRIx64, list->ids[0].guid);
        return 1;
    }
    dc1394_camera_free_list (x->list);

    //printf("Using camera with GUID %"PRIx64"\n", camera->guid);

    /*-----------------------------------------------------------------------
     *  get the best video mode and highest framerate. This can be skipped
     *  if you already know which mode/framerate you want...
     *-----------------------------------------------------------------------*/
    // get video modes:
    x->err=dc1394_video_get_supported_modes(x->camera,&x->video_modes);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Can't get video modes");

    // select highest res mode:
    for (x->i=x->video_modes.num-1;x->i>=0;x->i--) {
        if (!dc1394_is_video_mode_scalable(x->video_modes.modes[x->i])) {
            dc1394_get_color_coding_from_video_mode(x->camera,x->video_modes.modes[x->i], &x->coding);
            if (x->coding==DC1394_COLOR_CODING_MONO8) {
                x->video_mode=x->video_modes.modes[x->i];
		fprintf(stderr,"video_mode %d: %d\n",x->i,x->video_modes.modes[x->i]);
                break;
            }
        }
    }
    if (x->i < 0) {
        dc1394_log_error("Could not get a valid MONO8 mode");
        cleanup_and_exit(x->camera);
    }

    x->err=dc1394_get_color_coding_from_video_mode(x->camera, x->video_mode,&x->coding);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get color coding");
    fprintf(stderr,"color_coding : %d\n",x->coding);

    // get highest framerate
    x->err=dc1394_video_get_supported_framerates(x->camera,x->video_mode,&x->framerates);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get framrates");
    x->framerate=x->framerates.framerates[x->framerates.num-1];
    fprintf(stderr,"framerate : %d\n",x->framerate);

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

    x->err=dc1394_video_set_iso_speed(x->camera, DC1394_ISO_SPEED_400);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set iso speed");

    x->err=dc1394_video_set_mode(x->camera, x->video_mode);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set video mode");

    x->err=dc1394_video_set_framerate(x->camera, x->framerate);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set framerate");

    x->err=dc1394_capture_setup(x->camera,4, DC1394_CAPTURE_FLAGS_DEFAULT);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera");

    /*-----------------------------------------------------------------------
     *  report camera's features
     *-----------------------------------------------------------------------*/
    x->err=dc1394_feature_get_all(x->camera,&x->features);
    if (x->err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get feature set");
    }
    else {
        dc1394_feature_print_all(&x->features, stdout);
    }

    /*-----------------------------------------------------------------------
     *  have the camera start sending us data
     *-----------------------------------------------------------------------*/
    x->err=dc1394_video_set_transmission(x->camera, DC1394_ON);
    //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not start camera iso transmission");



    x->x_initialized = true;


    return (void *)x;
}
bool ieee1394capture::init(RoboCompCamera::TCamParams &params_, RoboCompJointMotor::JointMotorPrx head_ , RoboCompDifferentialRobot::DifferentialRobotPrx base_ )
{
	params = params_;
	head = head_;
	base = base_;

	int32_t i;

	fps = (dc1394framerate_t)params.FPS;//15;
	res = (dc1394video_mode_t)0;

	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;
		break;
	case 2:
		res = DC1394_VIDEO_MODE_640x480_RGB8;
		device_width = 640;
		device_height = 480;
		break;
	default:
		res = DC1394_VIDEO_MODE_320x240_YUV422;
		device_width = 320;
		device_height = 240;
		break;
	}


	/// Get handle
	qDebug() << "ieee1394capture::init() -> Initializating first Firewire Card in the system...";
	if (!(d = dc1394_new()))
	{
		qDebug() << "ieee1394capture::init() -> Fatal error: Unable to aquire a handle to the Ieee1394 device";
		qDebug() << "Please check if the kernel modules `ieee1394',`raw1394' and `ohci1394' are loaded or if you have read/write access to /dev/raw1394 and to /dev/video1394-0 " ;
		return false;
	}
	CREATED_BUS = true;

	/// Create camera interfaces
	numCameras = 0;
	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;
	}
	numCameras = 0;
	for (uint32_t  di = 0; di < list->num; di++)
	{
		if (numCameras >= MAX_CAMERAS)
			break;
		cameras[numCameras] = dc1394_camera_new(d, list->ids[di].guid);
		if (!cameras[numCameras])
		{
			dc1394_log_warning("Failed to initialize camera with guid %llx", list->ids[di].guid);
			continue;
		}
		printf("Camera #%d\n", numCameras);
		numCameras++;
	}
	dc1394_camera_free_list(list);
	if ( numCameras < 1 )
	{
		qDebug() << "ieee1394capture::init() -> Fatal error: No cameras found in the bus! Called from ";
		cleanup();
		return false;
	}
	/// Check if one camera has become the root node
/*	for ( int n=0; n < numCameras; n++ )
	{
		if ( cameraNodeList[n] == numNodes )
		{
			qDebug() << "ieee1394capture::init() -> Fatal error: Sorry, your camera is the highest numbered node of the bus, and has therefore become the root node." ;
			cleanup();
			return false;
		}
	}*/
	CREATED_CAMS = true;

	/// Setup cameras for capture
	qDebug() << "ieee1394capture::init() -> Searching cameras with requested parameters:";
	printf("%s\n",params.mode.c_str());
	if (params.mode == "MODE_320x240_YUV422")
	{
		res = DC1394_VIDEO_MODE_320x240_YUV422;
		params.width = 320;
		params.height = 240;
	}
	else if (params.mode == "MODE_640x480_YUV422" )
	{
		res = DC1394_VIDEO_MODE_640x480_YUV422;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_RGB" )
	{
		res = DC1394_VIDEO_MODE_640x480_RGB8;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_YUV411")
	{
		res = DC1394_VIDEO_MODE_640x480_YUV411;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_MONO")
	{
		res = DC1394_VIDEO_MODE_640x480_MONO8;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_640x480_MONO16")
	{
		res = DC1394_VIDEO_MODE_640x480_MONO16;
		params.width = 640;
		params.height = 480;
	}
	else if (params.mode == "MODE_516x338_YUV422")
	{
		res = DC1394_VIDEO_MODE_FORMAT7_1;
		params.width = 516;
		params.height = 338;
	}
	else qFatal("ieee1394capture::init() -> Image Mode %s not available. Aborting...", params.mode.c_str());
	params.size = params.width*params.height;
	if (params.FPS!=15 and params.FPS!=30)
	{
		qWarning("ieee1394capture::init() -> Framerate %d not available. Aborting...", params.FPS );
		cleanup();
		return false;
	}

	dc1394format7modeset_t info;

	for (i = 0; i < numCameras; i++)
	{

	    if (params.mode == "MODE_516x338_YUV422")
	    {
		err = dc1394_format7_get_modeset(cameras[i], &info);

		for( int j=0;j<DC1394_VIDEO_MODE_FORMAT7_NUM;j++)
		{
		  qDebug() << info.mode[j].present;
		  qDebug() << info.mode[j].size_x;
		  qDebug() << info.mode[j].size_y;
		  qDebug() << info.mode[j].max_size_x;
		  qDebug() << info.mode[j].max_size_y;

		  qDebug() << info.mode[j].pos_x;
		  qDebug() << info.mode[j].pos_y;

		  qDebug() << info.mode[j].unit_size_x;
		  qDebug() << info.mode[j].unit_size_y;
		  qDebug() << info.mode[j].unit_pos_x;
		  qDebug() << info.mode[j].unit_pos_y;

		  qDebug() << info.mode[j].pixnum;

		  qDebug() << info.mode[j].packet_size; /* in bytes */
		  qDebug() << info.mode[j].unit_packet_size;
		  qDebug() << info.mode[j].max_packet_size;
		}
	    }


   	    release_iso_and_bw(i);

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

	    err = dc1394_video_set_iso_speed(cameras[i], DC1394_ISO_SPEED_400);
	    DC1394_ERR_CLN_RTN(err, cleanup(), "Could not set ISO speed");


	    //For format 7 modes only
	    if (params.mode == "MODE_516x338_YUV422")
	    {
	   //  uint32_t packet_size;

	    //  err=dc1394_format7_set_image_size(cameras[i], res, 514, 384);
	    //  DC1394_ERR_RTN(err,"Could not set image size");
	    //  err=dc1394_format7_get_recommended_packet_size(cameras[i], res, &packet_size);
	    //  DC1394_ERR_RTN(err,"Could not get format 7 recommended packet size");
	    //  err=dc1394_format7_set_roi(cameras[i], res, DC1394_COLOR_CODING_YUV422, packet_size, 0,0, 514, 384);
	    //  DC1394_ERR_RTN(err,"Could not set ROI");
	      qDebug() << "ya";
	    }

	    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");


	}
	fflush(stdout);
	qDebug() << "	ieee1394capture::init() -> Iso transmission started.";


	///Buffers de imagen
	qDebug() << "BUFFERS DE IMAGEN ------------------------------------------";
	for ( int i=0; i < numCameras; i++ )
	{
		AimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 );
		BimgBuffer[i] = ( Ipp8u * ) ippsMalloc_8u ( params.size * 9 );
		img8u_lum[i] = AimgBuffer[i];
		img8u_YUV[i] = AimgBuffer[i]+params.size;
		localYRGBImgBufferPtr[i] = BimgBuffer[i];
		qDebug() << "Reservando" << params.size * 9 <<" para localYRGBImgBufferPtr["<<i<<"]";
		printf("(de %p a %p)\n", localYRGBImgBufferPtr[i], localYRGBImgBufferPtr[i]+(params.size*9-1));
	}


	planos[0]=BimgBuffer[0]+params.size*3;
	planos[1]=BimgBuffer[0]+ ( params.size*4 );
	planos[2]=BimgBuffer[0]+ ( params.size*5 );
	//img8u_aux = BimgBuffer[0]+(params.size*6);

	imgSize_ipp.width=params.width;
	imgSize_ipp.height=params.height;

	return true;

}
Beispiel #8
0
int main(int argc, char *argv[]) 
{
  // assumes your camera can output 640x480 with 8-bit monochrome
  video_mode = DC1394_VIDEO_MODE_640x480_MONO8;

  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;
  }

  // use two counters so tht cameras array does not contain gaps in the case of errors
  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_800);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set ISO speed");
    
    err=dc1394_video_set_mode(cameras[i], video_mode);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not set video mode");
    
    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_get_image_size_from_video_mode(cameras[i], video_mode, &video_mode_width, &video_mode_height);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not query video mode width and height");

    err=dc1394_video_set_one_shot(cameras[i], DC1394_ON);
    DC1394_ERR_CLN_RTN(err,cleanup(),"Could not use one shot mode");
  }

    fflush(stdout);
    if (numCameras < 1) {
        perror("no cameras found :(\n");
        cleanup();
        exit(-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);

      // save image as '[GUID].pgm'
      char filename[256];
      sprintf(filename, "%" PRIu64 "%s",list->ids[i].guid,IMAGE_FILE_EXTENSION);
      imagefile=fopen(filename, "w");

      if( imagefile == NULL) {
	  dc1394_log_error("Can't create %s", filename);
	}
  
      // adding the pgm file header
      fprintf(imagefile,"P5\n%u %u 255\n", video_mode_width, video_mode_height);

      // writing to the file
      fwrite((const char *)frames[i]->image, 1, \
	     video_mode_width * video_mode_height, imagefile);
      fclose(imagefile);                                    
    }

  // exit cleanly
  cleanup();
  return(0);
}
Beispiel #9
0
dc1394error_t
dc1394_juju_capture_setup(platform_camera_t *craw, uint32_t num_dma_buffers,
        uint32_t flags)
{
    struct fw_cdev_create_iso_context create;
    struct fw_cdev_start_iso start_iso;
    dc1394error_t err;
    dc1394video_frame_t proto;
    int i, j, retval;
    dc1394camera_t * camera = craw->camera;

    if (flags & DC1394_CAPTURE_FLAGS_DEFAULT)
        flags = DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
            DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC;

    craw->flags = flags;

    // if capture is already set, abort
    if (craw->capture_is_set>0)
        return DC1394_CAPTURE_IS_RUNNING;

    // if auto iso is requested, stop ISO (if necessary)
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        dc1394switch_t is_iso_on;
        dc1394_video_get_transmission(camera, &is_iso_on);
        if (is_iso_on == DC1394_ON) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
        }
    }

    if (capture_basic_setup(camera, &proto) != DC1394_SUCCESS) {
        dc1394_log_error("basic setup failed");
        return DC1394_FAILURE;
    }

    if (flags & (DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
                DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)) {
        uint64_t channels_allowed = 0;
        unsigned int bandwidth_units = 0;
        int channel;
        if (flags & DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC)
            channels_allowed = 0xffff;
        if (flags & DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC)
            dc1394_video_get_bandwidth_usage (camera, &bandwidth_units);
        err = juju_iso_allocate (craw, channels_allowed,
                bandwidth_units, &craw->capture_iso_resource);
        if (err == DC1394_SUCCESS) {
            channel = craw->capture_iso_resource->channel;
        } else if (err == DC1394_FUNCTION_NOT_SUPPORTED) {
            channel = craw->node_id & 0x3f;
            dc1394_log_warning ("iso allocation not available in this kernel, "
                    "using channel %d...", channel);
        } else {
            dc1394_log_error ("juju: Failed to allocate iso resources");
            return err;
        }

        if (dc1394_video_set_iso_channel (camera, channel) != DC1394_SUCCESS)
            return DC1394_NO_ISO_CHANNEL;
    }

    if (dc1394_video_get_iso_channel (camera, &craw->iso_channel)
            != DC1394_SUCCESS)
        return DC1394_FAILURE;
    dc1394_log_debug ("juju: Receiving from iso channel %d", craw->iso_channel);

    craw->iso_fd = open(craw->filename, O_RDWR);
    if (craw->iso_fd < 0) {
        dc1394_log_error("error opening file: %s", strerror (errno));
        return DC1394_FAILURE;
    }

    create.type = FW_CDEV_ISO_CONTEXT_RECEIVE;
    create.header_size = craw->header_size;
    create.channel = craw->iso_channel;
    create.speed = SCODE_400;
    err = DC1394_IOCTL_FAILURE;
    if (ioctl(craw->iso_fd, FW_CDEV_IOC_CREATE_ISO_CONTEXT, &create) < 0) {
        dc1394_log_error("failed to create iso context");
        goto error_fd;
    }

    craw->iso_handle = create.handle;

    craw->num_frames = num_dma_buffers;
    craw->current = -1;
    craw->buffer_size = proto.total_bytes * num_dma_buffers;
    craw->buffer =
        mmap(NULL, craw->buffer_size, PROT_READ | PROT_WRITE , MAP_SHARED, craw->iso_fd, 0);
    err = DC1394_IOCTL_FAILURE;
    if (craw->buffer == MAP_FAILED)
        goto error_fd;

    err = DC1394_MEMORY_ALLOCATION_FAILURE;
    craw->frames = malloc (num_dma_buffers * sizeof *craw->frames);
    if (craw->frames == NULL)
        goto error_mmap;

    for (i = 0; i < num_dma_buffers; i++) {
        err = init_frame(craw, i, &proto);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error initing frames");
            break;
        }
    }
    if (err != DC1394_SUCCESS) {
        for (j = 0; j < i; j++)
            release_frame(craw, j);
        goto error_mmap;
    }

    for (i = 0; i < num_dma_buffers; i++) {
        err = queue_frame(craw, i);
        if (err != DC1394_SUCCESS) {
            dc1394_log_error("error queuing");
            goto error_frames;
        }
    }

    // starting from here we use the ISO channel so we set the flag in
    // the camera struct:
    craw->capture_is_set = 1;

    start_iso.cycle   = -1;
    start_iso.tags = FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS;
    start_iso.sync = 1;
    start_iso.handle = craw->iso_handle;
    retval = ioctl(craw->iso_fd, FW_CDEV_IOC_START_ISO, &start_iso);
    err = DC1394_IOCTL_FAILURE;
    if (retval < 0) {
        dc1394_log_error("error starting iso");
        goto error_frames;
    }

    // if auto iso is requested, start ISO
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        err=dc1394_video_set_transmission(camera, DC1394_ON);
        DC1394_ERR_RTN(err,"Could not start ISO!");
        craw->iso_auto_started=1;
    }

    return DC1394_SUCCESS;

error_frames:
    for (i = 0; i < num_dma_buffers; i++)
        release_frame(craw, i);
error_mmap:
    munmap(craw->buffer, craw->buffer_size);
error_fd:
    close(craw->iso_fd);

    return err;
}
//--------------------------------------------------------------------
bool ofxVideoGrabberPtgrey::initGrabber(int w, int h, bool setUseTexture){
    width = w;
    height = h;
    bUseTexture = setUseTexture;
	
	// In format_7 the framerate is set by setting the packet_size
	// this is used in dc1394_format7_set_roi()
	// The following formula is from the libdc1394 faq
	// http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/faq/#How_can_I_work_out_the_packet_size_for_a_wanted_frame_rate
	float bus_period = 0.000125;  // for firewire 400
	int frame_rate = 60;
	int depth = 3;
	int num_packets = (int)(1.0/(bus_period*frame_rate) + 0.5);
	//packet_size =  (width*height*depth + (num_packets*8) - 1)/(num_packets*8);
	packet_size = DC1394_USE_MAX_AVAIL;	

    //first choose a device to use
    if( bChooseDevice ) {
        bool bFound = false;
        for (uint32_t index = 0; index < deviceList->num; index++) {
            if (deviceList->ids[index].unit == deviceID) {
                bFound = true;
                deviceID = deviceList->ids[index].guid;
            }
        }
        if (!bFound) {
            printf("initGrabber warning: Device ID for unit %x not found, using first device\n", deviceID);
            deviceID = deviceList->ids[0].guid;
        }
    } else if(deviceList->num > 0) {
        deviceID = deviceList->ids[0].guid;
    } else {
        ofLog(OF_LOG_ERROR, "in initGrabber, No cameras found");
    }


    camera = dc1394_camera_new(driver, deviceID);
	if (!camera) {
		ofLog(OF_LOG_ERROR, "Failed to initialize camera with guid %x", deviceID);
		return 1;
	}

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

    err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
    if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set iso speed"); }
	
	err = dc1394_video_set_mode( camera, video_mode );
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 video mode"); }
	
	err = dc1394_format7_set_color_coding(camera, video_mode, color_coding);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 color coding"); }
	
	err = dc1394_format7_set_packet_size(camera, video_mode, packet_size);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 packet_size"); }
	
	err = dc1394_format7_set_roi(camera, video_mode, color_coding, packet_size, 0,0, width,height);
	if( err != DC1394_SUCCESS ) {
		ofLog(OF_LOG_ERROR, "failed to set format 7");
	}

    //err = dc1394_video_set_framerate(camera, framerate);
	//DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate");

    err = dc1394_capture_setup(camera,2, DC1394_CAPTURE_FLAGS_DEFAULT);
	if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to setup dma capturing"); }


	/*-----------------------------------------------------------------------
     *  set camera's features
     *-----------------------------------------------------------------------*/

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 200);  //1-255

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_EXPOSURE, 62);  //7-62

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, 60);  //1-263, 64 being the max for 60fps

	err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);
	err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 50);  //16-64

	//err = dc1394_feature_set_mode(camera, DC1394_FEATURE_PAN, DC1394_FEATURE_MODE_MANUAL);
	//err = dc1394_feature_set_value(camera, DC1394_FEATURE_PAN, 56);


    /*-----------------------------------------------------------------------
     *  report camera's features
     *-----------------------------------------------------------------------*/
    err=dc1394_feature_get_all(camera,&features);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get feature set");
    }
    else {
        dc1394_feature_print_all(&features, stdout);
    }

    /*-----------------------------------------------------------------------
     *  have the camera start sending us data
     *-----------------------------------------------------------------------*/
    err=dc1394_video_set_transmission(camera, DC1394_ON);
    //DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission");

	//create pixel buffer
    pixels	= new unsigned char[width * height * 3];

    //create texture
    if (bUseTexture) {
        tex.allocate(width,height,GL_LUMINANCE);
        memset(pixels, 0, width*height);
        tex.loadData(pixels, width, height, GL_LUMINANCE);
    }

}
Beispiel #11
0
dc1394error_t
dc1394_windows_capture_stop(platform_camera_t *craw)
{
    DWORD dwBytesRet = 0;
    DWORD ret;

    if (craw->device_acquisition == INVALID_HANDLE_VALUE) {
        dc1394_log_error("StopImageAcquisition: Called with invalid device handle\n");
        return DC1394_FAILURE;
    }

    // Tear down the stream
    ret = free_resources(craw);
    if (ret) {
        dc1394_log_error("free_resources: Error %ld\n", ret);
    }

    // put pCurrentBuffer on the list for the sake of cleanup
    if (craw->pCurrentBuffer != NULL) {
        craw->pCurrentBuffer->pNextBuffer = craw->pLastBuffer;
        craw->pLastBuffer = craw->pCurrentBuffer;
    }

    while (craw->pLastBuffer) {
        if (craw->pLastBuffer != craw->pCurrentBuffer) {
            // check the IO status, just in case
            for (unsigned int ii = 0; ii < craw->pLastBuffer->nSubBuffers; ++ii) {
                if (!GetOverlappedResult(craw->device_acquisition, &craw->pLastBuffer->subBuffers[ii].overLapped, &dwBytesRet, TRUE)) {
                    dc1394_log_warning("dc1394_windows_capture_stop: Warning Buffer %d.%d has not been detached, error = %d\n", craw->pLastBuffer->index,ii,GetLastError());
                }
            }
        }

        // check the IO status, just in case
        for(unsigned int ii = 0; ii<craw->pLastBuffer->nSubBuffers; ++ii) {
            // close event: NOTE: must pre-populate correctly above
            if(craw->pLastBuffer->subBuffers[ii].overLapped.hEvent != NULL) {
                CloseHandle(craw->pLastBuffer->subBuffers[ii].overLapped.hEvent);
                craw->pLastBuffer->subBuffers[ii].overLapped.hEvent = NULL;
            }
        }

        // free data buffer
        if (craw->pLastBuffer->pDataBuf)
            GlobalFree(craw->pLastBuffer->pDataBuf);

        // advance to next buffer
        PACQUISITION_BUFFER pAcqBuffer = craw->pLastBuffer;
        craw->pLastBuffer = craw->pLastBuffer->pNextBuffer;

        // free buffer struct
        GlobalFree(pAcqBuffer);
    }

    // clean up our junk
    if (craw->device_acquisition != INVALID_HANDLE_VALUE) {
        CloseHandle(craw->device_acquisition);
        craw->device_acquisition = INVALID_HANDLE_VALUE;
    }

    craw->pFirstBuffer = craw->pLastBuffer = craw->pCurrentBuffer = NULL;
    free (&craw->capture.frames);

    craw->capture_is_set = 0;

    return DC1394_SUCCESS;
}
Beispiel #12
0
dc1394error_t
dc1394_windows_capture_setup(platform_camera_t * craw, uint32_t num_dma_buffers,
                             uint32_t flags)
{
    dc1394camera_t * camera = craw->camera;
    dc1394error_t err;

    if (flags & DC1394_CAPTURE_FLAGS_DEFAULT) {
        flags = DC1394_CAPTURE_FLAGS_CHANNEL_ALLOC |
            DC1394_CAPTURE_FLAGS_BANDWIDTH_ALLOC;
    }

    // if capture is already set, abort
    if (craw->capture_is_set > 0) {
        return DC1394_CAPTURE_IS_RUNNING;
    }

    craw->capture.flags = flags;
    craw->allocated_channel = -1;

    // if auto iso is requested, stop ISO (if necessary)
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        dc1394switch_t is_iso_on;
        dc1394_video_get_transmission(camera, &is_iso_on);
        if (is_iso_on == DC1394_ON) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
        }
    }

    craw->capture.frames =
        malloc (num_dma_buffers * sizeof (dc1394video_frame_t));
    if (!craw->capture.frames) {
        goto fail;
    }

    err = capture_basic_setup(camera, craw->capture.frames);
    if (err != DC1394_SUCCESS) {
        goto fail;
    }

    err = windows_capture_setup (craw, num_dma_buffers, flags);
    if (err != DC1394_SUCCESS) {
        goto fail;
    }

    // if auto iso is requested, start ISO
    if (flags & DC1394_CAPTURE_FLAGS_AUTO_ISO) {
        err=dc1394_video_set_transmission(camera, DC1394_ON);
        DC1394_ERR_RTN(err,"Could not start ISO!");
        craw->iso_auto_started = 1;
    }

    craw->capture.num_dma_buffers = num_dma_buffers;
    return DC1394_SUCCESS;

 fail:
    // free resources if they were allocated
    if (craw->allocated_channel >= 0) {
        if (dc1394_iso_release_channel (camera, craw->allocated_channel)
            != DC1394_SUCCESS)
            dc1394_log_warning("Warning: Could not free ISO channel");
    }
    if (craw->allocated_bandwidth) {
        if (dc1394_iso_release_bandwidth (camera, craw->allocated_bandwidth)
            != DC1394_SUCCESS)
            dc1394_log_warning("Warning: Could not free bandwidth");
    }
    craw->allocated_channel = -1;
    craw->allocated_bandwidth = 0;

    free (craw->capture.frames);
    craw->capture.frames = NULL;
    dc1394_log_error ("Error: Failed to setup DMA capture");

    return DC1394_FAILURE;
}
int main(int argc, char *argv[])
{
    // first check for the correct number of arguments
    if (argc != numArguments) {
        printf("Wrong number of arguments, exiting\n");
        exit(0);
    }
    
    time_t theTime = time(NULL);
    struct tm *aTime = localtime(&theTime);
    
    int day = aTime->tm_mday;
    int month = aTime->tm_mon + 1;
    int year = aTime->tm_year + 1900;
    int hour = aTime->tm_hour;
    int min = aTime->tm_min;
    int sec = aTime->tm_sec;
    
    char directory[128];
    sprintf(directory, "/opt/data_collection/%d_%d_%d_%d_%d_%d", year, month, day, hour, min, sec);
    char cmd[128];
    sprintf(cmd, "mkdir %s", directory);
    system(cmd);
    
    double lapse=0;
    double fps;
    double ntime=0, ptime=0, tmp;
    int index;
    dc1394video_frame_t *frame;
    dc1394error_t err;
    int cam_id=0;
    
    char fileName[128];

    // init 1394
    d = dc1394_new();
    if (!d) return 1;
    
    // find cameras
    dc1394camera_list_t * list;
    err=dc1394_camera_enumerate (d, &list);
    DC1394_ERR_RTN(err,"Failed to enumerate cameras");
    if (list->num == 0) {
        fprintf(stderr,"No cameras found\n");
        return 1;
    }
    else {
        if (list->num<cam_id+1) {
            fprintf(stderr,"Not enough cameras found for id\n");
            return 1;
        }
    }
    // use selected camera
    camera = dc1394_camera_new (d, list->ids[cam_id].guid);
    if (!camera) {
        dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[cam_id].guid);
        return 1;
    }
    dc1394_camera_free_list (list);
    
    // setup video format
    dc1394video_mode_t video_mode;
    if (color == 0) {
        printf("video mode is MONO\n");
        video_mode = DC1394_VIDEO_MODE_640x480_MONO8;
    } else {
        printf("video mode is RGB8\n");
        video_mode = DC1394_VIDEO_MODE_640x480_RGB8;
    }
    
    dc1394framerate_t framerate = DC1394_FRAMERATE_7_5;
    
    //dc1394_video_set_transmission(video_mode, DC1394_OFF); // just in case
    dc1394_video_set_mode(camera, video_mode);
    dc1394_video_set_framerate(camera, framerate);
    dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
        
    // setup catpure
    err=dc1394_capture_setup(camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT);
    if (err!=DC1394_SUCCESS) {
        fprintf(stderr,"Could not set capture!\n");
        return 0;
    }
    
    // start image transmission
    dc1394_video_set_transmission(camera, DC1394_ON);
    
    // first, see what we are controlling manually vs. auto
    autoExposure = atoi(argv[1]);
    autoGain = atoi(argv[3]);
    autoShutter = atoi(argv[5]);
    autoBrightness = atoi(argv[7]);

    // set what we want to control to manual...
    if (autoExposure == 1) {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_AUTO);
    } else {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL);
    }
    
    if (autoGain == 1) {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_AUTO);
    } else {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL);
    }

    if (autoShutter == 1) {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_AUTO);
    } else {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
    }

    if (autoBrightness == 1) {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_AUTO);
    } else {
        dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
    }
        
    // print out the current features
    dc1394featureset_t  features;
    err=dc1394_feature_get_all(camera, &features);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get the feature set");
    }
    else {
        dc1394_feature_print_all(&features, stdout);
    }
    
    
    // set the exposure level
    if (argc == numArguments) {
        exposure = atoi(argv[2]);
    }
    
    err=dc1394_feature_set_value(camera, DC1394_FEATURE_EXPOSURE, exposure);
    if (err!=DC1394_SUCCESS) {
        printf("Could NOT set the exposure!\n");
    } else {
        printf("exposure set to %d\n", exposure);
    }

    // set the gain
    if (argc == numArguments) {
        gain = atoi(argv[4]);
    }
    
    err=dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, gain);
    if (err!=DC1394_SUCCESS) {
        printf("Could NOT set the gain!\n");
    } else {
        printf("gain set to %d\n", gain);
    }

    // set the shutter
    if (argc == numArguments) {
        shutter = atoi(argv[6]);
    }

    err=dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, shutter);
    if (err!=DC1394_SUCCESS) {
        printf("Could NOT set the shutter!\n");
    } else {
        printf("shutter set to %d\n", shutter);
    }
    
    // set the brightness
    if (argc == numArguments) {
        brightness = atoi(argv[8]);
    }
    
    err=dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, brightness);
    if (err!=DC1394_SUCCESS) {
        printf("Could NOT set the brightness!\n");
    } else {
        printf("shutter set to %d\n", brightness);
    }

    // print out the current features    
    //dc1394featureset_t  features;
    err=dc1394_feature_get_all(camera, &features);
    if (err!=DC1394_SUCCESS) {
        dc1394_log_warning("Could not get the feature set");
    }
    else {
        dc1394_feature_print_all(&features, stdout);
    }
    
    // go ahead and log our settings to a text file in the directory we created
    FILE *file;
    char fileNameSettings[256];
    sprintf(fileNameSettings, "%s/settings.txt", directory);
    file = fopen(fileNameSettings, "a+");
    fprintf(file,"exposure=%d,%d\n", autoExposure, exposure);
    fprintf(file,"gain=%d,%d\n", autoGain, gain);
    fprintf(file,"shutter=%d,%d\n",autoShutter, shutter);
    fprintf(file,"brightness=%d,%d\n",autoBrightness, brightness);
    fclose(file);
    
    // start the main loop
    int quit = 0;
    while (!quit) {
        
        // capture image
        err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);/* Capture */
        DC1394_ERR_RTN(err,"Problem getting an image");

        // return buffer
        dc1394_capture_enqueue(camera, frame);
        
        int t=0;
        if (color == 1) {
            t=3;
        } else {
            t=1;
        }
        
        IplImage *tmp = cvCreateImage(cvSize(640,480),8,t);
        memcpy(tmp->imageData, frame->image, 640*480*t);
        cvShowImage("image", tmp);
        char c = cvWaitKey(10);
        
        // save the image
        sprintf(fileName, "%s/frame%06d.bmp", directory, count);
        count++;
        cvSaveImage(fileName, tmp, 0);
        cvReleaseImage(&tmp);
        
    } // end loop

    return 0;
}
Beispiel #14
0
dc1394error_t
platform_capture_stop(platform_camera_t *craw)
{
    dc1394camera_t * camera = craw->camera;
    int err;

    if (craw->capture_is_set>0) {
        // unlisten
        if (ioctl(craw->capture.dma_fd, VIDEO1394_IOC_UNLISTEN_CHANNEL,
                    &(craw->iso_channel)) < 0)
            return DC1394_IOCTL_FAILURE;

        // release
        if (craw->capture.dma_ring_buffer) {
            munmap((void*)craw->capture.dma_ring_buffer,craw->capture.dma_buffer_size);
        }


        while (close(craw->capture.dma_fd) != 0) {
            dc1394_log_debug("waiting for dma_fd to close");
            sleep (1);
        }
        craw->capture.dma_fd = -1;

        free (craw->capture.frames);
        craw->capture.frames = NULL;

        // this dma_device file is allocated by the strdup() function and can be freed here without problems.
        free(craw->capture.dma_device_file);
        craw->capture.dma_device_file=NULL;

        // capture is not set anymore
        craw->capture_is_set=0;

        // free ressources if they were allocated
        if (craw->allocated_channel >= 0) {
            if (dc1394_iso_release_channel (camera, craw->allocated_channel)
                    != DC1394_SUCCESS)
                dc1394_log_warning("Warning: Could not free ISO channel");
        }
        if (craw->allocated_bandwidth) {
            if (dc1394_iso_release_bandwidth (camera, craw->allocated_bandwidth)
                    != DC1394_SUCCESS)
                dc1394_log_warning("Warning: Could not free bandwidth");
        }
        craw->allocated_channel = -1;
        craw->allocated_bandwidth = 0;

        // stop ISO if it was started automatically
        if (craw->iso_auto_started>0) {
            err=dc1394_video_set_transmission(camera, DC1394_OFF);
            DC1394_ERR_RTN(err,"Could not stop ISO!");
            craw->iso_auto_started=0;
        }

        // free the additional capture handle
        raw1394_destroy_handle(craw->capture.handle);
    }
    else {
        return DC1394_CAPTURE_IS_NOT_SET;
    }

    return DC1394_SUCCESS;
}
Beispiel #15
0
/*****************************************************
 capture_linux_setup

 This sets up the dma for the given camera.
 capture_basic_setup must be called before

******************************************************/
static dc1394error_t
capture_linux_setup(platform_camera_t * craw, uint32_t num_dma_buffers)
{
    struct video1394_mmap vmmap;
    struct video1394_wait vwait;
    uint32_t i;
    dc1394video_frame_t * f;

    memset(&vmmap, 0, sizeof(vmmap));
    memset(&vwait, 0, sizeof(vwait));

    if (open_dma_device(craw) != DC1394_SUCCESS) {
        dc1394_log_warning("Could not open video1394 device file in /dev");
        return DC1394_INVALID_VIDEO1394_DEVICE;
    }

    vmmap.sync_tag= 1;
    vmmap.nb_buffers= num_dma_buffers;
    vmmap.flags= VIDEO1394_SYNC_FRAMES;
    vmmap.buf_size= craw->capture.frames[0].total_bytes; //number of bytes needed
    vmmap.channel= craw->iso_channel;

    /* tell the video1394 system that we want to listen to the given channel */
    if (ioctl(craw->capture.dma_fd, VIDEO1394_IOC_LISTEN_CHANNEL, &vmmap) < 0) {
        dc1394_log_error("VIDEO1394_IOC_LISTEN_CHANNEL ioctl failed: %s", strerror(errno));
        close (craw->capture.dma_fd);
        return DC1394_IOCTL_FAILURE;
    }
    // starting from here we use the ISO channel so we set the flag in the camera struct:
    craw->capture_is_set=1;

    craw->capture.dma_frame_size= vmmap.buf_size;
    craw->capture.num_dma_buffers= vmmap.nb_buffers;
    craw->capture.dma_last_buffer= -1;
    vwait.channel= craw->iso_channel;

    /* QUEUE the buffers */
    for (i= 0; i < vmmap.nb_buffers; i++) {
        vwait.buffer= i;

        if (ioctl(craw->capture.dma_fd,VIDEO1394_IOC_LISTEN_QUEUE_BUFFER,&vwait) < 0) {
            dc1394_log_error("VIDEO1394_IOC_LISTEN_QUEUE_BUFFER ioctl failed");
            ioctl(craw->capture.dma_fd, VIDEO1394_IOC_UNLISTEN_CHANNEL, &(vwait.channel));
            craw->capture_is_set=0;
            close (craw->capture.dma_fd);
            return DC1394_IOCTL_FAILURE;
        }

    }

    craw->capture.dma_ring_buffer= mmap(0, vmmap.nb_buffers * vmmap.buf_size,
                                        PROT_READ|PROT_WRITE,MAP_SHARED, craw->capture.dma_fd, 0);

    /* make sure the ring buffer was allocated */
    if (craw->capture.dma_ring_buffer == (uint8_t*)(-1)) {
        dc1394_log_error("mmap failed!");
        ioctl(craw->capture.dma_fd, VIDEO1394_IOC_UNLISTEN_CHANNEL, &vmmap.channel);
        craw->capture_is_set=0;
        close (craw->capture.dma_fd);

        // This should be display if the user has low memory
        if (vmmap.nb_buffers * vmmap.buf_size > sysconf (_SC_PAGESIZE) * sysconf (_SC_AVPHYS_PAGES)) {
            dc1394_log_error("Unable to allocate DMA buffer.\nThe requested size (0x%ux or %ud MiB) is bigger than the available memory (0x%lux or %lud MiB).\nPlease free some memory before allocating the buffers",
			     vmmap.nb_buffers * vmmap.buf_size,
			     vmmap.nb_buffers * vmmap.buf_size/1048576,
			     sysconf (_SC_PAGESIZE) * sysconf (_SC_AVPHYS_PAGES),
			     sysconf (_SC_PAGESIZE) * sysconf (_SC_AVPHYS_PAGES)/1048576);
        } else {
            // if it's not low memory, then it's the vmalloc limit.
            // VMALLOC_RESERVED not sufficient (default is 128MiB in recent kernels)
            dc1394_log_error("Unable to allocate DMA buffer. The requested size (0x%x) may be larger than the usual default VMALLOC_RESERVED limit of 128MiB. To verify this, look for the following line in dmesg:\n'allocation failed: out of vmalloc space'\nIf you see this, reboot with the kernel boot parameter:\n'vmalloc=k'\nwhere k (in bytes) is larger than your requested DMA ring buffer size.\nNote that other processes share the vmalloc space so you may need a\nlarge amount of vmalloc memory.", vmmap.nb_buffers * vmmap.buf_size);
            //}
        }
        return DC1394_IOCTL_FAILURE;
    }

    craw->capture.dma_buffer_size= vmmap.buf_size * vmmap.nb_buffers;

    for (i = 0; i < num_dma_buffers; i++) {
        f = craw->capture.frames + i;
        if (i > 0)
            memcpy (f, craw->capture.frames, sizeof (dc1394video_frame_t));
        f->image = (unsigned char *)(craw->capture.dma_ring_buffer +
                                     i * craw->capture.dma_frame_size);
        f->id = i;
    }

    return DC1394_SUCCESS;
}