ConventionalVideoMode::ConventionalVideoMode(dc1394camera_t* libdc1394camera,
      dc1394video_mode_t libdc1394mode) :
   VideoMode(libdc1394mode)
{
   uint32_t width, height;
   dc1394error_t err;
   err = dc1394_get_image_size_from_video_mode(libdc1394camera, libdc1394mode, &width, &height);
   if (err != DC1394_SUCCESS)
      throw Error(err, "Cannot get image size from video mode");
   SetImageSize(width, height);

   dc1394color_coding_t libdc1394coding;
   err = dc1394_get_color_coding_from_video_mode(libdc1394camera, libdc1394mode, &libdc1394coding);
   if (err != DC1394_SUCCESS)
      throw Error(err, "Cannot get color coding from video mode");
   SetLibDC1394Coding(libdc1394coding);
}
Beispiel #2
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;
}
Beispiel #3
0
static dc1394video_mode_t s_get_appropriate_mode(dc1394camera_t *cam, dc1394video_mode_t mode)
{
  dc1394video_modes_t supported_modes;
  dc1394video_mode_t selected_mode = mode;

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

  dc1394error_t err;
  unsigned int i;

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

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

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

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

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

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

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

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

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

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

  return selected_mode;
}
Beispiel #4
0
bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
{
    int i;
    int code = 0;
    if (!dcCam)
        return false;
    if (isoSpeed > 0)
    {
        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;
}
Beispiel #5
0
//=============================================================================
// querySteroeCamera()
//
// 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
//
dc1394error_t
queryStereoCamera( dc1394camera_t* 	camera,
		   PGRStereoCamera_t* 	stereoCamera )
{

   // set the camera handle
   stereoCamera->camera = camera;

   // find out what base model camera we have
   stereoCamera->model = getCameraModel( camera );
   if ( stereoCamera->model == UNKNOWN_CAMERA )
      return DC1394_FAILURE;


   dc1394error_t err;
   
   if ( stereoCamera->model != BUMBLEBEE )
   {
      err = getSensorInfo( camera,
			   &stereoCamera->bColor,
			   &stereoCamera->nRows,
			   &stereoCamera->nCols );
      if ( err != DC1394_SUCCESS )
      {
	 fprintf( stderr, "Could not query the Sensor Info Register!\n" );
	 return err;
      }
   }
   else // model == BUMBLEBEE
   {
      // This is a Bumblebee "1".  This camera does not support the
      // sensor board info register so we need to determine if it is color
      // and the resolution the hard way
      //	
      // It will be nice when we don't need to support BB1 anymore as it is
      // not completely DC-compliant

      dc1394video_modes_t 	video_modes;
      err = dc1394_video_get_supported_modes( camera, &video_modes );
      if ( err != DC1394_SUCCESS ) 
      {
	 fprintf( stderr, "Can't get video modes\n" );
	 return err;
      }

      // find the highest res mode that is greyscale (MONO16)
      printf( "Searching for the highest resolution MONO16 mode available...\n" );
      dc1394video_mode_t 	video_mode;
      dc1394color_coding_t 	coding;
      for ( int i = video_modes.num-1; i >= 0; i-- ) 
      {
	 // don't consider FORMAT 7 modes (i.e. "scalable")
	 if ( !dc1394_is_video_mode_scalable( video_modes.modes[i] ) ) 
	 {
	    dc1394_get_color_coding_from_video_mode( camera, video_modes.modes[i], &coding );
	    if ( coding == DC1394_COLOR_CODING_MONO16 ) 
	    {
	       video_mode = video_modes.modes[i];
	       break;
	    }
	 }
      }
      if ( video_mode == DC1394_VIDEO_MODE_640x480_MONO16 )
      {
	 stereoCamera->nRows = 480;
	 stereoCamera->nCols = 640;
      }
      else if ( video_mode == DC1394_VIDEO_MODE_1024x768_MONO16 )
      {
	 stereoCamera->nRows = 768;
	 stereoCamera->nCols = 1024;
      }
      else
      {
	 fprintf( stderr, "Cannot find valid MONO16 video mode!\n" );
	 return DC1394_FAILURE;
      }


      dc1394color_filter_t bayerPattern;
      err = getBayerTile( stereoCamera->camera, &bayerPattern );
      if ( err != DC1394_SUCCESS ) 
      {
	 fprintf( stderr, "Failed to read the Bayer Tile Pattern register\n" );
	 return err;
      }
      // at this point all we need to know is "is it color or mono?"
      if ( bayerPattern == 0 )
	 stereoCamera->bColor = false;
      else
	 stereoCamera->bColor = true;
      
   }
   
   // a hack to figure out how many bytes per pixel are needed.
   // if the camera is a BB3, then it is 3, otherwise 2
   if ( stereoCamera->nRows == 960 )
   {
      //stereoCamera->nBytesPerPixel	= 3;
      // note: for performance reasons we have changed the default behavior
      // of the XB3 for these examples to only use the 2 wide-baseline pair.
      // This makes for faster image transmission.
      // If you change the code to transmit all 3 images, this value will 
      // have to revert to 3.
      stereoCamera->nBytesPerPixel	= 2;
   }
   else
   {
      stereoCamera->nBytesPerPixel	= 2;
   }
   
   return DC1394_SUCCESS;
}
bool Libdc1394SequenceGrabber::initVideoMode(unsigned int w, unsigned int h, bool grey, unsigned int videomode, unsigned int color_mode)
{
	msg(osg::INFO) << "initVideoMode" << std::endl;

	std::vector<dc1394video_mode_t> suitable_modes;
	if (videomode != 0) 
	{
		suitable_modes.push_back((dc1394video_mode_t)videomode);
	}
	else 
	{
		if (w == 320) {
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_320x240_YUV422);
		} else if (w == 640) {
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_640x480_RGB8);
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_640x480_YUV411);
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_640x480_YUV422);
			if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_640x480_MONO8);
			//if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_640x480_MONO16);
		} else if (w == 800) {
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_800x600_RGB8);
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_800x600_YUV422);
			if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_800x600_MONO8);
			//if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_800x600_MONO16);
		} else if (w == 1024) {
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1024x768_RGB8);
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1024x768_YUV422);
			if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1024x768_MONO8);
			//if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1024x768_MONO16);
		} else if (w == 1280) {
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1280x960_RGB8);
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1280x960_YUV422);
			if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1280x960_MONO8);
			//if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1280x960_MONO16);
		} else if (w == 1600) {
			//if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1600x1200_RGB8);
			if (!grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1600x1200_YUV422);
			if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1600x1200_MONO8);
			//if (grey) suitable_modes.push_back(DC1394_VIDEO_MODE_1600x1200_MONO16);
		}
	
	}
	dc1394video_modes_t video_modes;
	
    dc1394error_t err=dc1394_video_get_supported_modes(_camera,&video_modes);
    checkSuccess(err, "dc1394_video_get_supported_modes failed");
    
	for (unsigned int i = 0;i < video_modes.num;i++) 
	{
		for(unsigned int j=0; j < suitable_modes.size(); ++j) {
			if (video_modes.modes[i] == suitable_modes[j])
			{
				// videmodus gefunden, gleich setzen
				_videomode = video_modes.modes[i];
				err = dc1394_video_set_mode(_camera, video_modes.modes[i]);
				checkSuccess(err,"dc1394_video_set_mode failed");
                
                if (color_mode == 0) {
                    err = dc1394_get_color_coding_from_video_mode(_camera, _videomode, &_sourceFormat);
                    checkSuccess(err, "dc1394_get_color_coding_from_video_mode failed");
                } else {
                    _sourceFormat = (dc1394color_coding_t)(color_mode);
                }
                return true;
			}
		}
	}
	
	return false;
}
Beispiel #7
0
static int set_default_video_mode(PGR_Cam *pgcp)
{
	dc1394camera_t*	cam_p;
	dc1394video_mode_t	video_mode;
	int i;

	cam_p = pgcp->pc_cam_p;

	//  get the best video mode and highest framerate. This can be skipped
	//  if you already know which mode/framerate you want...
	// get video modes:

	if( dc1394_video_get_supported_modes( cam_p, &pgcp->pc_video_modes )
						!= DC1394_SUCCESS ){
		return -1;
	}

	// select highest res mode that is greyscale (MONO8)
	/*
	printf("Searching for the highest resolution MONO8 mode available (of %d modes)...\n",
		video_modes.num);
		*/

	dc1394color_coding_t coding;

	// assign an invalid value to video_mode to quiet compiler,
	// then check below to make sure a mode we want was found...

	video_mode = BAD_VIDEO_MODE;

//fprintf(stderr,"Checking %d video modes...\n",pgcp->pc_video_modes.num);
	for ( i = pgcp->pc_video_modes.num-1; i >= 0; i-- ) {
		// don't consider FORMAT 7 modes (i.e. "scalable")
		if ( !dc1394_is_video_mode_scalable( pgcp->pc_video_modes.modes[i] ) ) {
			dc1394_get_color_coding_from_video_mode( cam_p,
				pgcp->pc_video_modes.modes[i], &coding );
//fprintf(stderr,"Checking non-scalable mode %d\n",pgcp->pc_video_modes.modes[i]);
			if ( coding == DC1394_COLOR_CODING_MONO8 ) {
				video_mode = pgcp->pc_video_modes.modes[i];
				break;
			}
		} else {
//fprintf(stderr,"Not checking scalable mode %d\n",pgcp->pc_video_modes.modes[i]);
		}
	}
	if( video_mode == BAD_VIDEO_MODE ){	// only scalable modes?
		for ( i = pgcp->pc_video_modes.num-1; i >= 0; i-- ) {
			dc1394_get_color_coding_from_video_mode( cam_p, 
				pgcp->pc_video_modes.modes[i], &coding );
			if( coding == DC1394_COLOR_CODING_MONO8  ||
					coding == DC1394_COLOR_CODING_RAW8 ) {
				video_mode = pgcp->pc_video_modes.modes[i];
				break;
			}
		}
	}

	assert( video_mode != BAD_VIDEO_MODE );

#ifdef FOOBAR
	// double check that we found a video mode  that is MONO8
	dc1394_get_color_coding_from_video_mode( cam_p, video_mode, &coding );
	if ( ( dc1394_is_video_mode_scalable( video_mode ) ) ||
			( coding != DC1394_COLOR_CODING_MONO8 &&
			  coding != DC1394_COLOR_CODING_RAW8 ) ) {
		warn("Could not get a valid MONO8 mode" );
		return -1;
	}
#endif // FOOBAR

	dc1394_video_set_mode( pgcp->pc_cam_p, video_mode );
	pgcp->pc_video_mode = video_mode;

	return 0;
}
bool CvCaptureCAM_DC1394_v2_CPP::startCapture()
{
    int i;
    int code = 0;
    if (!dcCam)
        return false;
    if (isoSpeed > 0)
    {
        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);
    }

    if (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_RGB16 ||
                        colorCoding == DC1394_COLOR_CODING_RAW8 ||
                        colorCoding == DC1394_COLOR_CODING_RAW16)
                {
                    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;
                }

                if (colorCoding == DC1394_COLOR_CODING_MONO8 ||
                        (colorCoding == DC1394_COLOR_CODING_MONO16 &&
                        pref < 0))
                {
                    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;
}