Example #1
0
void FWCamera::getCameraImageFormats(dc1394camera_t* pCamera, CameraInfo* camInfo)
{
    dc1394video_modes_t videoModes;
    dc1394framerates_t framerates;
    dc1394error_t err = dc1394_video_get_supported_modes(pCamera, &videoModes);
    if (err != DC1394_SUCCESS) {
        AVG_ASSERT(false);
        return;
    }
    for (unsigned i = 0; i < videoModes.num; i++) {
        //Covers only libavg supported formats, other capabilities are ignored
        if (videoModes.modes[i] >= DC1394_VIDEO_MODE_320x240_YUV422
                && videoModes.modes[i] <= DC1394_VIDEO_MODE_1600x1200_MONO16){
            PixelFormat pixFormat = getPFFromVideoMode(videoModes.modes[i]);
            IntPoint size = getFrameSizeFromVideoMode(videoModes.modes[i]);
            FrameratesVector framerateList;
            err = dc1394_video_get_supported_framerates(pCamera, videoModes.modes[i],
                    &framerates);
            if (err != DC1394_SUCCESS) {
                AVG_LOG_WARNING("Camera: No framerates. Error was: " << err);
            } else {
                for (unsigned j = 0; j < framerates.num; j++)
                {
                    float rate = framerateToFloat(framerates.framerates[j]);
                    framerateList.push_back(rate);
                }
            }
            CameraImageFormat format = CameraImageFormat(size,pixFormat,framerateList);
            camInfo->addImageFormat(format);
        }
    }
}
Example #2
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);
}
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;
}
Example #4
0
  /** Get video mode.
   *
   *  @param camera points to DC1394 camera struct
   *  @param[in,out] video_mode Config parameter for this option,
   *                      updated if the camera does not support the
   *                      requested value
   *  @return corresponding dc1394video_mode_t enum value selected
   */
  dc1394video_mode_t getVideoMode(dc1394camera_t *camera,
                                  std::string &video_mode)
  {
    for (int vm = DC1394_VIDEO_MODE_MIN;
         vm <= DC1394_VIDEO_MODE_MAX;
         ++vm)
      {
        if (video_mode_names_[vm-DC1394_VIDEO_MODE_MIN] == video_mode)
          {
            // found the requested mode
            dc1394video_modes_t vmodes;
            dc1394error_t err =
              dc1394_video_get_supported_modes(camera, &vmodes);
            if (err != DC1394_SUCCESS)
              {
                ROS_FATAL("unable to get supported video modes");
                // TODO raise exception
                return (dc1394video_mode_t) 0;
              }

            // see if requested mode is available
            for (uint32_t i = 0; i < vmodes.num; ++i)
              {
                if (vmodes.modes[i] == vm)
                  return (dc1394video_mode_t) vm; // yes: success
              }

            // requested mode not available, revert to current mode of camera
            ROS_ERROR_STREAM("Video mode " << video_mode
                             << " not supported by this camera");
            dc1394video_mode_t current_mode;
            err = dc1394_video_get_mode(camera, &current_mode);
            if (err != DC1394_SUCCESS)
              {
                ROS_FATAL("unable to get current video mode");
                // TODO raise exception
                return (dc1394video_mode_t) 0;
              }

            // TODO list available modes

            // change video_mode parameter to show current mode of camera
            video_mode = videoModeName(current_mode);
            return current_mode;
          }
      }

    // request video mode does not match any known string
    ROS_FATAL_STREAM("Unknown video_mode:" << video_mode);
    ROS_BREAK();
    // TODO raise exception
    //CAM_EXCEPT(camera1394::Exception, "Unsupported video_mode");
    return (dc1394video_mode_t) 0;
  }
Example #5
0
void ofxLibdc::setup(int cameraNumber) {	
	// create camera struct
	dc1394camera_list_t * list;
	dc1394_camera_enumerate (libdcContext, &list);
	camera = dc1394_camera_new (libdcContext, list->ids[cameraNumber].guid);
	if (!camera) {
		stringstream error;
		error << "Failed to initialize camera " << cameraNumber << " with guid " << list->ids[0].guid;
		ofLog(OF_LOG_ERROR, error.str());
		return;
	} else {
		stringstream msg;
		msg << "Using camera with GUID " << camera->guid;
		ofLog(OF_LOG_VERBOSE, msg.str());
	}
	dc1394_camera_free_list(list);
	
	// select highest res mode:
	dc1394video_modes_t video_modes;
	dc1394_video_get_supported_modes(camera, &video_modes);
	dc1394video_mode_t video_mode;
	dc1394color_coding_t coding;
	for (int 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(camera, video_modes.modes[i], &coding);
			if (coding == DC1394_COLOR_CODING_MONO8) {
				video_mode = video_modes.modes[i];
				break;
			}
		}
		if(i == 0) {
			ofLog(OF_LOG_ERROR, "Camera does not support DC1394_COLOR_CODING_MONO8.");
			return;
		}
	}
	dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height);
	 
	// get highest framerate
	dc1394framerates_t framerates;
	dc1394_video_get_supported_framerates(camera, video_mode, &framerates);
	dc1394framerate_t framerate = framerates.framerates[framerates.num - 1];
	
	// apply everything
	dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
	dc1394_video_set_mode(camera, video_mode);
	dc1394_video_set_framerate(camera, framerate);
	dc1394_capture_setup(camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT);
	
	// print out features
	dc1394featureset_t features;
	dc1394_feature_get_all(camera, &features);
	dc1394_feature_print_all(&features, stdout);
}
Example #6
0
int list_video_modes(QSP_ARG_DECL  PGR_Cam *pgcp)
{
	dc1394video_modes_t	video_modes;
	const char *s;
	unsigned int i;

	if ( dc1394_video_get_supported_modes( pgcp->pc_cam_p, &video_modes ) != DC1394_SUCCESS )
		return -1;

	for( i = 0; i< video_modes.num; i++ ){
		s=name_for_video_mode(video_modes.modes[i]);
		assert( s != NULL );
		prt_msg_frag("\t");
		prt_msg(s);
	}
	return 0;
}
Example #7
0
dc1394video_mode_t pick_fmt7_mode(QSP_ARG_DECL  PGR_Cam *pgcp,const char *pmpt)
{
	int i;
	int j,k;
	dc1394video_modes_t	video_modes;
	const char **choices;
	dc1394video_mode_t *	modelist;
	dc1394video_mode_t	m;

	if( pgcp == NULL ) return BAD_VIDEO_MODE;

	if ( dc1394_video_get_supported_modes( pgcp->pc_cam_p, &video_modes ) != DC1394_SUCCESS )
		return BAD_VIDEO_MODE;

	choices = (const char **)getbuf( video_modes.num * sizeof(char *) );
	modelist = (dc1394video_mode_t *) getbuf( video_modes.num * sizeof(dc1394video_mode_t) );
	j=0;
	for(i=0;i<video_modes.num;i++){
		k=index_of_video_mode(video_modes.modes[i]);	/* get index into our table... */
								/* could probably get this by subtraction if
								 * our table is in the correct order...
								 */
		if( k >= 0 && video_modes.modes[i] >= DC1394_VIDEO_MODE_FORMAT7_0
			   && video_modes.modes[i] <= DC1394_VIDEO_MODE_FORMAT7_7 ){
			choices[j] = all_video_modes[k].nvm_name;
			modelist[j] = all_video_modes[k].nvm_mode;
			j++;
		}
	}
	i=WHICH_ONE(pmpt,j,choices);
	givbuf(choices);
	if( i >= 0 )
		m=modelist[i];
	else
		m=BAD_VIDEO_MODE;
	givbuf(modelist);

	return(m);
}
Example #8
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;
}
Example #9
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 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;
}
void Camera1394::save_capa ( string filename ) {

    dc1394video_modes_t modes;
    dc1394error_t err ;

    bool framerates ;
    string modename ;
    string frate ;

    err=dc1394_video_get_supported_modes(cam, &modes);

    if ( err != DC1394_SUCCESS ) {
        std::cerr << "[vision_server]    Could not get list of modes" ;
    return ;
    }

    ofstream capafile ( filename.c_str() , ios::out ) ;

    for ( unsigned int i=0; i<modes.num; i++) {

    framerates = true ;

    if ( ( modes.modes[i] ==  DC1394_VIDEO_MODE_EXIF ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_0 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_1 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_2 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_3 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_4 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_5 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_6 ) ||
         ( modes.modes[i] == DC1394_VIDEO_MODE_FORMAT7_7 ) )
            framerates = false ;


    capafile << "[Mode] " << mode_2_string ( modes.modes[i] ) << endl ;


    if (framerates) {

        dc1394framerates_t framerates;

        err = dc1394_video_get_supported_framerates (cam, modes.modes[i], &framerates);
        if ( err != DC1394_SUCCESS ) {
            std::cerr << "[vision_server] ERROR : could not retrieve framerate" << endl ;
            exit(0) ;
        }

        for ( unsigned int j = 0; j < framerates.num; j++) {
            dc1394framerate_t rate = framerates.framerates[j];
            switch (rate) {
                case DC1394_FRAMERATE_1_875 :
                    frate = "DC1394_FRAMERATE_1_875" ;
                    break ;
                case DC1394_FRAMERATE_3_75 :
                    frate = "DC1394_FRAMERATE_3_75" ;
                    break ;
                case DC1394_FRAMERATE_7_5 :
                    frate = "DC1394_FRAMERATE_7_5" ;
                    break ;
                case DC1394_FRAMERATE_15 :
                    frate = "DC1394_FRAMERATE_15" ;
                    break ;
                case DC1394_FRAMERATE_30 :
                    frate = "DC1394_FRAMERATE_30" ;
                    break ;
                case DC1394_FRAMERATE_60 :
                    frate = "DC1394_FRAMERATE_60" ;
                    break ;
                case DC1394_FRAMERATE_120 :
                    frate = "DC1394_FRAMERATE_120" ;
                    break ;
                case DC1394_FRAMERATE_240 :
                    frate = "DC1394_FRAMERATE_240" ;
                    break ;
                default :
                    frate ="Unknown framerate" ;
                    break ;

            }

            capafile << "[Framerate] " << frate << endl ;
        }
    }

    capafile << endl ;

}

    // Enumerates features

    dc1394featureset_t  features ;

    dc1394_feature_get_all( cam, &features );

    for ( int i=0; i<DC1394_FEATURE_NUM; i++ ) {
        if ( features.feature[i].available ) {

                capafile << std::endl << "[Feature] " << feature_2_string ( features.feature[i].id ) << std::endl ;

                for (unsigned int j=0; j<features.feature[i].modes.num; j++ ) {

                    capafile << "  Mode : " << featuremode_2_string ( features.feature[i].modes.modes[j] ) << std::endl ;

                    if (features.feature[i].modes.modes[j] == DC1394_FEATURE_MODE_MANUAL ) {

                            uint32_t min = 0 ;
                            uint32_t max = 0 ;

                            err = dc1394_feature_get_boundaries( cam, features.feature[i].id , &min, &max);

                            if ( err != DC1394_SUCCESS ) {
                                std::cerr << "[vision_server] ERROR : Could not get boudaries for mode " << featuremode_2_string ( features.feature[i].modes.modes[j] ) << endl ;
                                exit(0) ;
                            }

                            capafile << "  Value : " << min << " - " << max << std::endl ;
                        }
                }

        }

    }


    // close file

    capafile.close() ;

}
Example #12
0
void Libdc1394SequenceGrabber::populateDeviceInfoList(cefix::SequenceGrabberDeviceInfoList& devices)
{
	dc1394_t * d;
	dc1394camera_list_t * list;
	dc1394error_t err;
	dc1394video_modes_t video_modes;
	dc1394framerates_t framerates;
	
	d = Libdc1394Context::get();
	if (!d)
		return;
	
	err=dc1394_camera_enumerate (d, &list);
	
	for(unsigned int i = 0; i < list->num; ++i) {
		osg::notify(osg::INFO) << "UID: " <<  list->ids[i].guid << std::endl;
		dc1394camera_t* camera = dc1394_camera_new (d, list->ids[i].guid);
		if (!camera) continue;
		
		devices.push_back(cefix::SequenceGrabber::DeviceInfo(getGrabberId(), cefix::longToHexString(list->ids[i].guid)));
		
		dc1394_camera_print_info(camera, stdout);
		
		err=dc1394_video_get_supported_modes(camera,&video_modes);
		osg::notify(osg::INFO) << "available video-modes: " << std::endl;

		for (int j = 0;j < video_modes.num;j++) 
		{
			osg::notify(osg::INFO) << "* " << getVideoMode(video_modes.modes[j]);
			
			if (dc1394_video_get_supported_framerates(camera, video_modes.modes[j], &framerates) == DC1394_SUCCESS) {
				osg::notify(osg::INFO) << " fps: ";
				for(unsigned int k = 0; k < framerates.num; ++k) {
					osg::notify(osg::INFO) << " " << getFrameRate(framerates.framerates[k]);
				}
			}
			osg::notify(osg::INFO) << std::endl;
		}
		
	
		dc1394featureset_t features;
		dc1394_feature_get_all(camera, &features);
		dc1394_feature_print_all(&features, stdout);
		
		/*
		for( int j = 0; j < DC1394_FEATURE_NUM; j++ )
		{
			const dc1394feature_info_t& f = features.feature[j];
			
			if( f.available ) 
			{ 
				std::cout << getNameOfFeature(f.id) << std::endl;
				std::cout << "  current mode: ";
				switch(f.current_mode) {
					case DC1394_FEATURE_MODE_MANUAL:
						std::cout << "manual";
						break;
					case DC1394_FEATURE_MODE_AUTO:
						std::cout << "auto";
						break;
					case DC1394_FEATURE_MODE_ONE_PUSH_AUTO:
						std::cout << "one-push";
						break;
				}
				std::cout << std::endl;
				std::cout << "  min: " << f.min << " max: " << f.max << " value: " << f.value << std::endl;
				if (f.absolute_capable==DC1394_TRUE) {
					std::cout << "  abs:min: " << f.abs_min << " max: " << f.abs_max << " value: " << f.abs_value << std::endl;
				}
			}
		}
		*/
		
		dc1394_camera_free(camera);
	}
	
	dc1394_camera_free_list(list);
}
Example #13
0
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;
}
Example #14
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;
}
Example #15
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;
}
Example #16
0
GstCaps *
gst_dc1394_get_cam_caps (GstDc1394 * src)
{

    dc1394camera_t *camera = NULL;
    dc1394camera_list_t *cameras = NULL;
    dc1394error_t camerr;
    gint i, j;
    dc1394video_modes_t modes;
    dc1394framerates_t framerates;
    GstCaps *gcaps = NULL;

    gcaps = gst_caps_new_empty ();

    camerr = dc1394_camera_enumerate (src->dc1394, &cameras);

    if (camerr != DC1394_SUCCESS || cameras == NULL) {
        GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
                           ("Can't find cameras error : %d", camerr),
                           ("Can't find cameras error : %d", camerr));
        goto error;
    }

    if (cameras->num == 0) {
        GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, ("There were no cameras"),
                           ("There were no cameras"));
        goto error;
    }

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

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

    dc1394_camera_free_list (cameras);
    cameras = NULL;

    camerr = dc1394_video_get_supported_modes (camera, &modes);
    if (camerr != DC1394_SUCCESS) {
        GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error getting supported modes"),
                           ("Error getting supported modes"));
        goto error;
    }

    for (i = modes.num - 1; i >= 0; i--) {
        int m = modes.modes[i];

        if (m < DC1394_VIDEO_MODE_EXIF) {

            GstStructure *gs = gst_structure_empty_new ("video");

            gst_structure_set (gs, "vmode", G_TYPE_INT, m, NULL);

            if (gst_dc1394_caps_set_format_vmode_caps (gs, m) < 0) {
                GST_ELEMENT_ERROR (src, STREAM, FAILED,
                                   ("attempt to set mode to %d failed", m),
                                   ("attempt to set mode to %d failed", m));
                goto error;
            } else {

                camerr = dc1394_video_get_supported_framerates (camera, m, &framerates);
                gst_dc1394_caps_set_framerate_list (gs, &framerates);
                gst_caps_append_structure (gcaps, gs);

            }
        } else {
            // FORMAT 7
            guint maxx, maxy;
            GstStructure *gs = gst_structure_empty_new ("video");
            dc1394color_codings_t colormodes;
            guint xunit, yunit;

            gst_structure_set (gs, "vmode", G_TYPE_INT, m, NULL);

            // Get the maximum frame size
            camerr = dc1394_format7_get_max_image_size (camera, m, &maxx, &maxy);
            if (camerr != DC1394_SUCCESS) {
                GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                                   ("Error getting format 7 max image size"),
                                   ("Error getting format 7 max image size"));
                goto error;
            }
            GST_LOG_OBJECT (src, "Format 7 maxx=%d maxy=%d", maxx, maxy);

            camerr = dc1394_format7_get_unit_size (camera, m, &xunit, &yunit);
            if (camerr != DC1394_SUCCESS) {
                GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                                   ("Error getting format 7 image unit size"),
                                   ("Error getting format 7 image unit size"));
                goto error;
            }
            GST_LOG_OBJECT (src, "Format 7 unitx=%d unity=%d", xunit, yunit);

            gst_dc1394_set_caps_framesize_range (gs, xunit, maxx, xunit,
                                                 yunit, maxy, yunit);

            // note that format 7 has no concept of a framerate, so we pass the
            // full range
            gst_structure_set (gs,
                               "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);

            // get the available color codings
            camerr = dc1394_format7_get_color_codings (camera, m, &colormodes);
            if (camerr != DC1394_SUCCESS) {
                GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
                                   ("Error getting format 7 color modes"),
                                   ("Error getting format 7 color modes"));
                goto error;
            }

            for (j = 0; j < colormodes.num; j++) {
                GstStructure *newgs = gst_structure_copy (gs);

                gst_dc1394_set_caps_color (newgs, colormodes.codings[j]);
                GST_LOG_OBJECT (src, "Format 7 colormode set : %d",
                                colormodes.codings[j]);
                // note that since there are multiple color modes, we append
                // multiple structures.
                gst_caps_append_structure (gcaps, newgs);
            }
        }
    }

    if (camera) {
        dc1394_camera_free (camera);
    }

    return gcaps;

error:

    if (gcaps) {
        gst_caps_unref (gcaps);
    }

    if (cameras) {
        dc1394_camera_free_list (cameras);
        cameras = NULL;
    }

    if (camera) {
        dc1394_camera_free (camera);
        camera = NULL;
    }

    return NULL;
}
Example #17
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;
}
int main(int argc, char *argv[])
{
    FILE* imagefile;
    dc1394camera_t *camera;
    unsigned int width, height;
    dc1394video_frame_t *frame=NULL;
    //dc1394featureset_t features;
    dc1394_t * d;
    dc1394camera_list_t * list;
    dc1394error_t err;
    int i,j;

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

    printf("Total cameras found %d\n",list->num);

    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);
        return 1;
    }
    dc1394_camera_free_list (list);

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

    dc1394video_modes_t video_modes;
    err=dc1394_video_get_supported_modes(camera,&video_modes);
    DC1394_ERR_RTN(err,"Failed get camera modes");

    printf("Video Modes:\n");
    for( i = 0; i < video_modes.num; i++ ) {
        printVideoMode(video_modes.modes[i]);
        if( video_modes.modes[i] < DC1394_VIDEO_MODE_FORMAT7_0 ) {
           dc1394framerates_t rates;
            err=dc1394_video_get_supported_framerates(camera,video_modes.modes[i],&rates);
            DC1394_ERR_RTN(err,"Failed get mode frame rates");
            for( j = 0; j < rates.num; j++ ) {
                printFrameRates(rates.framerates[j]);
            }
        } else {
            dc1394color_codings_t codings;
            err=dc1394_format7_get_color_codings(camera,video_modes.modes[i],&codings);
            DC1394_ERR_RTN(err,"Failed get format7 color codings");
            for( j = 0; j < codings.num; j++ ) {
                printColorCodings(codings.codings[j]);
            }
            uint32_t width,height;
            err=dc1394_format7_get_max_image_size(camera,video_modes.modes[i],&width,&height);
            DC1394_ERR_RTN(err,"Failed get format7 max size");
            printf("    Max dimension = %d  %d\n",width,height);
        }
    }



    dc1394_camera_free(camera);
    dc1394_free (d);
    return 0;
}