コード例 #1
0
ファイル: ofxLibdc.cpp プロジェクト: BluntBlade/eyewriter
void ofxLibdc::applySettings() {
	if(camera)
		dc1394_capture_stop(camera);
		
	if(use1394b) {
		// assumes you want to run your 1394b camera at 800 Mbps
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_800);
	} else {
		dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_LEGACY);
		dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
	}
		
	dc1394framerate_t framerate;
	if(useFormat7) {
		videoMode = (dc1394video_mode_t) ((int) DC1394_VIDEO_MODE_FORMAT7_0 + format7Mode);
	} else {
		dc1394video_modes_t video_modes;
		dc1394_video_get_supported_modes(camera, &video_modes);
		dc1394color_coding_t coding;
		dc1394color_coding_t targetCoding = getLibdcType(imageType);
		for (int i = 0; i < video_modes.num; i++) {
			if (!dc1394_is_video_mode_scalable(video_modes.modes[i])) {
				dc1394video_mode_t curMode = video_modes.modes[i];
				dc1394_get_color_coding_from_video_mode(camera, curMode, &coding);
				unsigned int curWidth, curHeight;
				dc1394_get_image_size_from_video_mode(camera, curMode, &curWidth, &curHeight);
				if (coding == targetCoding && width == curWidth && height == curHeight) {
					videoMode = curMode;
					break;
				}
			}
			if(i == video_modes.num - 1) {
				ofLog(OF_LOG_ERROR, "Camera does not support target mode.");
				return;
			}
		}
		
		// get fastest framerate
		// todo: make this settable
		dc1394framerates_t framerates;
		dc1394_video_get_supported_framerates(camera, videoMode, &framerates);
		framerate = framerates.framerates[framerates.num - 1];
	}
	
	if(useFormat7) {
		quantizePosition();
		quantizeSize();
		dc1394_format7_set_roi(camera, videoMode, getLibdcType(imageType), DC1394_USE_MAX_AVAIL, left, top, width, height);
		unsigned int curWidth, curHeight;
		dc1394_format7_get_image_size(camera, videoMode, &curWidth, &curHeight);
	} else {
		dc1394_video_set_framerate(camera, framerate);
	}
	
	// contrary to the libdc1394 format7 demo, this should go after the roi setting
	dc1394_video_set_mode(camera, videoMode);
		
	dc1394_capture_setup(camera, OFXLIBDC_BUFFER_SIZE, DC1394_CAPTURE_FLAGS_DEFAULT);
}
コード例 #2
0
bool Libdc1394SequenceGrabber::initFrameRate(unsigned int rate) 
{
	msg(osg::INFO) << "initFrameRate" << std::endl;
	
	if (!_camera) return false;
    
    if (_format7) {
        uint32_t bit_size;
        dc1394_get_color_coding_bit_size(_sourceFormat,&bit_size);
        int packet_size = DC1394_USE_MAX_AVAIL;
        
        if(rate != 0) {
            double bus_period;
			if(_speed == DC1394_ISO_SPEED_800) {
				bus_period = 0.0000625;
			}
			else {
				bus_period = 0.000125;
			}

            int num_packets = (int)(1.0/(bus_period*rate)+0.5);
            packet_size = ((_roi.width - _roi.x)*(_roi.height - _roi.y)*bit_size + (num_packets*8) - 1) / (num_packets*8);
        }
        
        dc1394error_t err = dc1394_format7_set_packet_size(_camera, _videomode, packet_size);
        checkSuccess(err, "dc1394_format7_set_packet_size failed");
        
        err = dc1394_format7_set_roi(_camera, _videomode, _sourceFormat, packet_size, _roi.x,_roi.y,_roi.width,_roi.height);
        checkSuccess(err, "dc1394_format7_set_roi failed");
        return (err == DC1394_SUCCESS);
    }
	
	dc1394framerates_t framerates;
	dc1394error_t err=dc1394_video_get_supported_framerates(_camera,_videomode, &framerates);
    checkSuccess(err, "dc1394_video_get_supported_framerates failed");
    
	dc1394framerate_t framerate=framerates.framerates[framerates.num-1];
	
	switch (rate) {
		case 15:
			framerate = DC1394_FRAMERATE_15;
			break;
		case 30:
			framerate = DC1394_FRAMERATE_30;
			break;
		case 60:
			framerate = DC1394_FRAMERATE_60;
			break;
		case 120:
			framerate = DC1394_FRAMERATE_120;
			break;
		case 240:
			framerate = DC1394_FRAMERATE_240;
	}
	
	err=dc1394_video_set_framerate(_camera, framerate);
    checkSuccess(err, "dc1394_video_set_framerate failed");
    
	return (err == DC1394_SUCCESS);
}
コード例 #3
0
ファイル: firewire.cpp プロジェクト: WooYoungChoi/Pangolin
void FirewireVideo::init_camera(
    uint64_t guid, int dma_frames,
    dc1394speed_t iso_speed,
    dc1394video_mode_t video_mode,
    dc1394framerate_t framerate
    ) {

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

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

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


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

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

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

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

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

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

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

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

    Start();
}
コード例 #4
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);
}
コード例 #5
0
ファイル: pgr.c プロジェクト: jbmulligan/quip
int _set_framerate(QSP_ARG_DECL  PGR_Cam *pgcp, int framerate_index)
{
	dc1394framerate_t rate;

	if( pgcp == NULL ) return -1;

	rate = all_framerates[framerate_index].nfr_framerate;
	if( dc1394_video_set_framerate( pgcp->pc_cam_p, rate) != DC1394_SUCCESS ){
		warn("unable to set framerate");
		return -1;
	}
	pgcp->pc_framerate = rate;
	return 0;
}
コード例 #6
0
 /** Set non-scalable frame rate.
  *
  *  @pre camera is NOT in a Format7 video mode.
  *
  *  @param camera points to DC1394 camera struct.
  *  @param video_mode currently selected non-Format7 video mode.
  *  @param[in,out] frame_rate Config parameter for this option,
  *                 updated if the camera does not support the
  *                 requested value.
  *  @return true if successful; false if not.
  */
 bool setFrameRate(dc1394camera_t *camera,
                   dc1394video_mode_t video_mode,
                   double &frame_rate)
 {
   dc1394framerate_t rate = getFrameRate(camera, video_mode, frame_rate);
   if (DC1394_FRAMERATE_NUM == rate)
     {
       ROS_WARN("No valid frame rate");
       return false;                   // failure
     }
   if (DC1394_SUCCESS != dc1394_video_set_framerate(camera, rate))
     {
       ROS_WARN("Failed to set frame rate");
       return false;                   // failure
     }
   return true;
 }
コード例 #7
0
ファイル: pgr.c プロジェクト: jbmulligan/quip
static int set_default_framerate(QSP_ARG_DECL  PGR_Cam *pgcp)
{
	int r;

	// get highest framerate

	// Hmm...  the avaialable framerates appear to depend on the video mode!
	// Therefore, we should re-call this when we change the video mode!

	// format7 doesn't have a framerate!?

	// format7 doesn't have a framerate!?
	if( mode_is_format7(pgcp) ){
		//warn("set_default_framerate:  No framerate associated with format7 video mode!?");
		pgcp->pc_framerate = -1;
		set_script_var_from_int("n_framerates",0);
		return 0;
	}

	if ( dc1394_video_get_supported_framerates( pgcp->pc_cam_p, pgcp->pc_video_mode, &(pgcp->pc_framerates) )
			!= DC1394_SUCCESS ) {
		warn("Can't get framerates");
		return -1;
	}

	r = pgcp->pc_framerates.framerates[ pgcp->pc_framerates.num-1];
	pgcp->pc_framerate = r;

sprintf(ERROR_STRING,"set_default_framerate:  setting to %s", name_for_framerate(r));
advise(ERROR_STRING);

	dc1394_video_set_framerate( pgcp->pc_cam_p, pgcp->pc_framerate );
	// BUG if this fails, then pc_framerate is wrong!?

	// stash the number of framerates in a script variable
	// in case the user wants to fetch the strings...
	set_script_var_from_int("n_framerates",pgcp->pc_framerates.num);

	return 0;
}
コード例 #8
0
 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 counter = 0;
     d = dc1394_new ();
     if (!d)
         return 1;
     err=dc1394_camera_enumerate (d, &list);
     DC1394_ERR_RTN(err,"Failed to enumerate cameras");

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

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

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

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

     err=dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_7);
     DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set video mode\n");

     err=dc1394_video_set_framerate(camera, DC1394_FRAMERATE_7_5);
     DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate\n");

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

     /*-----------------------------------------------------------------------
      *  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\n");
     for(;;){
         /*-----------------------------------------------------------------------
          *  capture one frame
          *-----------------------------------------------------------------------*/
         err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
         DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not capture a frame\n");

         dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_FORMAT7_7, &width, &height);

         cv::Mat img = cv::Mat(height, width, CV_8U, frame->image);

         err = dc1394_capture_enqueue(camera, frame);
         frame=NULL;
         cv::imshow("Image", img);

         printf("Frame %d\n", counter);
         counter++;
         cv::waitKey(10);

      }
     /*-----------------------------------------------------------------------
      *  stop data transmission
      *-----------------------------------------------------------------------*/
     err=dc1394_video_set_transmission(camera,DC1394_OFF);
     DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not stop the camera?\n");

     /*-----------------------------------------------------------------------
      *  close camera
      *-----------------------------------------------------------------------*/
     dc1394_video_set_transmission(camera, DC1394_OFF);
     dc1394_capture_stop(camera);
     dc1394_camera_free(camera);
     dc1394_free (d);
     return 0;
 }
コード例 #9
0
ファイル: pgr_stereocam.cpp プロジェクト: flame85/techx
//=============================================================================
// setStereoVideoCapture()
//
// Given that the camera handle is a stereo camera, query the camera for 
// stereo specific information about this camera and populate the 
// PGRStereoCamera_t handle structure
//
// note: currently always allocated maximum framerate
dc1394error_t
setStereoVideoCapture( PGRStereoCamera_t* stereoCamera )
{
   dc1394error_t 	err;
   dc1394color_coding_t	coding;

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

   return DC1394_SUCCESS;
}
コード例 #10
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;
}
コード例 #11
0
ファイル: pdp_dc1394.c プロジェクト: Angeldude/pd
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;
}
コード例 #12
0
ファイル: capture.c プロジェクト: nagyistoce/openvgr
static int s_set_parameters(capture_t *cap, const int index, camera_setting_t *s)
{
  int ret = CAPTURE_SUCCESS;

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

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

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

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

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

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

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

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

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

  return ret;
}
コード例 #13
0
ファイル: ffmv_ccd.cpp プロジェクト: A-j-K/indi
/**************************************************************************************
** Client is asking us to establish connection to the device
***************************************************************************************/
bool FFMVCCD::Connect()
{
    dc1394camera_list_t *list;
    dc1394error_t err;
    bool supported;
    bool settings_valid;
    uint32_t val;
    dc1394format7mode_t fm7;
    dc1394feature_info_t feature;
    float min, max;

    dc1394 = dc1394_new();
    if (!dc1394) {
        return false;
    }

    err = dc1394_camera_enumerate(dc1394, &list);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Could not find DC1394 cameras!");
        return false;
    }
    if (!list->num) {
        IDMessage(getDeviceName(), "No DC1394 cameras found!");
        return false;
    }
    dcam = dc1394_camera_new(dc1394, list->ids[0].guid);
    if (!dcam) {
        IDMessage(getDeviceName(), "Unable to connect to camera!");
        return false;
    }

    /* Reset camera */
    err = dc1394_camera_reset(dcam);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to reset camera!");
        return false;
    }

    /* Set mode */
    err = dc1394_video_set_mode(dcam, DC1394_VIDEO_MODE_640x480_MONO16);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to connect to set videomode!");
        return false;
    }
    /* Disable Auto exposure control */
    err = dc1394_feature_set_power(dcam, DC1394_FEATURE_EXPOSURE, DC1394_OFF);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to disable auto exposure control");
        return false;
    }

    /* Set frame rate to the lowest possible */
    err = dc1394_video_set_framerate(dcam, DC1394_FRAMERATE_7_5);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to connect to set framerate!");
        return false;
    }
    /* Turn frame rate control off to enable extended exposure (subs of 512ms) */
    err = dc1394_feature_set_power(dcam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to disable framerate!");
        return false;
    }

    /* Get the longest possible exposure length */
    err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Failed to enable manual shutter control.");
    } 
    err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_SHUTTER, DC1394_ON);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Failed to enable absolute shutter control.");
    } 
    err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_SHUTTER, &min, &max);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Could not get max shutter length");
    } else {
        max_exposure = max;
    }

    /* Set gain to max. By setting the register directly, we can achieve a
     * gain of 24 dB...compared to a gain of 12 dB which is reported as the
     * max
     */
    err = dc1394_set_control_register(dcam, 0x820, 0x40);
    //err = dc1394_set_control_register(dcam, 0x820, 0x7f);
    if (err != DC1394_SUCCESS) {
            return err;
    }
#if 0
    /* Set absolute gain to max */
    err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_GAIN, DC1394_ON);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Failed to enable ansolute gain control.");
    } 
    err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_GAIN, &min, &max);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Could not get max gain value");
    } else {
        err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAIN, max);
        if (err != DC1394_SUCCESS) {
            IDMessage(getDeviceName(), "Could not set max gain value");
        }
    }
#endif

    /* Set brightness */
    err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Failed to enable manual brightness control.");
    } 
    err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_ON);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Failed to enable ansolute brightness control.");
    } 
    err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_BRIGHTNESS, 1);
    if (err != DC1394_SUCCESS) {
            IDMessage(getDeviceName(), "Could not set max brightness value");
    }

    /* Turn gamma control off */
    err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAMMA, 1);
    if (err != DC1394_SUCCESS) {
            IDMessage(getDeviceName(), "Could not set gamma value");
    }
    err = dc1394_feature_set_power(dcam, DC1394_FEATURE_GAMMA, DC1394_OFF);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to disable gamma!");
        return false;
    }

    /* Turn off white balance */
    err = dc1394_feature_set_power(dcam, DC1394_FEATURE_WHITE_BALANCE, DC1394_OFF);
    if (err != DC1394_SUCCESS) {
        IDMessage(getDeviceName(), "Unable to disable white balance!");
        return false;
    }

    err=dc1394_capture_setup(dcam,10, DC1394_CAPTURE_FLAGS_DEFAULT);

    return true;
}
コード例 #14
0
ファイル: capture_images.c プロジェクト: 1ee7/cuav
static int capture_loop(dc1394camera_t *camera, const char *basename, float delay, bool testonly)
{
	uint16_t average;
	uint32_t num_saturated, num_half_saturated;
	float shutter = SHUTTER_GOOD;
	float gain = GAIN_GOOD;

	CHECK(dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400));
	CHECK(dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_1280x960_MONO16));
	CHECK(dc1394_video_set_framerate(camera, DC1394_FRAMERATE_3_75));

	CHECK(dc1394_capture_setup(camera, 16, DC1394_CAPTURE_FLAGS_DEFAULT));

	CHECK(dc1394_feature_set_power(camera, DC1394_FEATURE_EXPOSURE, DC1394_OFF));

	CHECK(dc1394_feature_set_power(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_ON));
	CHECK(dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL));
	CHECK(dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 0));

	CHECK(dc1394_feature_set_power(camera, DC1394_FEATURE_GAIN, DC1394_ON));
	CHECK(dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL));
	CHECK(dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 500));
	CHECK(dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_GAIN, DC1394_ON));
	CHECK(dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_GAIN, GAIN_GOOD));

	CHECK(dc1394_feature_set_power(camera, DC1394_FEATURE_SHUTTER, DC1394_ON));
	CHECK(dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL));
	CHECK(dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, 500));
	CHECK(dc1394_feature_set_absolute_control(camera, DC1394_FEATURE_SHUTTER, DC1394_ON));
	CHECK(dc1394_feature_set_absolute_value(camera, DC1394_FEATURE_SHUTTER, SHUTTER_GOOD));

	CHECK(dc1394_video_set_transmission(camera, DC1394_ON));

	while (true) {
		alarm(10+(unsigned)delay);

		if (capture_image(camera, basename, shutter, gain, &average, 
				  &num_saturated, &num_half_saturated, testonly) == -1) {
			return -1;
		}

		if (num_saturated > SATURATED_HIGH) {
			/* too much saturation */
			if (gain > GAIN_MIN) {
				gain = new_gain(average, average*0.5, gain);
			} else if (shutter > SHUTTER_MIN) {
				shutter = new_shutter(average, average*0.5, shutter, SHUTTER_MAX);
			}
		} else if (average < AVERAGE_LOW && 
			   num_saturated == 0 && 
			   num_half_saturated < SATURATED_HIGH) {
			/* too dark */
			if (shutter < SHUTTER_GOOD) {
				float shutter2 = new_shutter(average, AVERAGE_TARGET, shutter, SHUTTER_GOOD);
				average = (shutter2/shutter)*average;
				shutter = shutter2;
			}
			if (average < AVERAGE_LOW) {
				if (gain < GAIN_MAX) {
					gain = new_gain(average, AVERAGE_TARGET, gain);
				} else if (shutter < SHUTTER_MAX) {
					shutter = new_shutter(average, AVERAGE_TARGET, shutter, SHUTTER_MAX);
				}
			}
		} else if (average > AVERAGE_HIGH) {
			/* too light */
			if (shutter > SHUTTER_GOOD) {
				float shutter2 = new_shutter(average, AVERAGE_TARGET, shutter, SHUTTER_GOOD);
				average = (shutter2/shutter)*average;
				shutter = shutter2;
			}
			if (average > AVERAGE_HIGH) {
				if (gain > GAIN_MIN) {
					gain = new_gain(average, AVERAGE_TARGET, gain);
				} else if (shutter > SHUTTER_MIN) {
					shutter = new_shutter(average, AVERAGE_TARGET, shutter, SHUTTER_MAX);
				}
			}
		}

		fflush(stdout);

		usleep(delay*1.0e6);
	}

	return 0;
}
コード例 #15
0
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;
}
コード例 #16
0
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;

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

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

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

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

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

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

    err=dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_1280x960_RGB8);
    DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set video mode\n");

    err=dc1394_video_set_framerate(camera, DC1394_FRAMERATE_7_5);
    DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate\n");

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

    /*-----------------------------------------------------------------------
     *  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\n");

    /*-----------------------------------------------------------------------
     *  capture one frame
     *-----------------------------------------------------------------------*/
    err=dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
    DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not capture a frame\n");

    /*-----------------------------------------------------------------------
     *  stop data transmission
     *-----------------------------------------------------------------------*/
    err=dc1394_video_set_transmission(camera,DC1394_OFF);
    DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not stop the camera?\n");

    /*-----------------------------------------------------------------------
     *  save image as 'Image.pgm'
     *-----------------------------------------------------------------------*/
    imagefile=fopen(IMAGE_FILE_NAME, "wb");

    if( imagefile == NULL) {
        perror( "Can't create output file");
        cleanup_and_exit(camera);
    }

    dc1394_get_image_size_from_video_mode(camera, DC1394_VIDEO_MODE_1280x960_RGB8, &width, &height);
    fprintf(imagefile,"P6\n%u %u\n255\n", width, height);
    fwrite(frame->image, 1, height*width*3, imagefile);
    fclose(imagefile);
    printf("wrote: " IMAGE_FILE_NAME " (%d image bytes)\n",height*width*3);

    /*-----------------------------------------------------------------------
     *  close camera
     *-----------------------------------------------------------------------*/
    dc1394_video_set_transmission(camera, DC1394_OFF);
    dc1394_capture_stop(camera);
    dc1394_camera_free(camera);
    dc1394_free (d);
    return 0;
}
コード例 #17
0
    VideoIIDC1394::VideoIIDC1394(int source, uint8_t iso, uint8_t vid_mode, uint8_t f_rate, uint32_t w, uint32_t h)
    {
#if defined(DUNE_WITH_DC1394)

      std::cout << " Entered constructor " << std:: endl;

      width = w;

      height = h;

      iidc = dc1394_new();

      frame = NULL;

      std::cout << " Built Object " << std:: endl;

      dc1394error_t error_code;

      if (!iidc)
      {
        throw std::runtime_error("Failed to start IEEE 1394 IIDC interface");
      }

      error_code = dc1394_camera_enumerate(iidc, &list);

      std::cout << " Enumerated camera objects " << std:: endl;

      if (error_code < 0)
      {
        throw std::runtime_error("Failed to enumerate cameras");
      }

      std::cout << "Number of cameras found: " << list->num << std:: endl;

      camera = dc1394_camera_new(iidc, list->ids[0].guid);

      std::cout << " Built new camera object " << std:: endl;

      if (!camera)
      {
        throw std::runtime_error("Failed to initialize camera");
      }

      dc1394_camera_free_list(list);

      error_code = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);

      if (error_code < 0)
      {
        throw std::runtime_error("Failed to set ISO SPEED");
      }

      error_code = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_640x480_YUV422);
      if (error_code < 0)
      {
        throw std::runtime_error("Failed to set video mode");
      }

      error_code = dc1394_video_set_framerate(camera, DC1394_FRAMERATE_15);
      if (error_code < 0)
      {
        free(this);
        throw std::runtime_error("Failed to set ISO SPEED");
      }

      error_code = dc1394_capture_setup(camera, 8, DC1394_CAPTURE_FLAGS_DEFAULT);
      if (error_code < 0)
      {
        throw std::runtime_error("Failed to set ISO SPEED");
      }

      error_code = dc1394_video_set_transmission(camera, DC1394_ON);
      if (error_code < 0)
      {
        throw std::runtime_error("Could not start video capture");
      }

      converted_frame = new dc1394video_frame_t;
      std::memset(converted_frame, 0, sizeof(dc1394video_frame_t));

      std::cout << " Finished setting everything up " << std:: endl;

#else
      (void)source;
      (void)iso;
      (void)vid_mode;
      (void)f_rate;
      (void)w;
      (void)h;

      throw std::runtime_error("IIDC Firewire Video interface is not yet implemented in this system.");

#endif
    }
コード例 #18
0
ファイル: dc1394.c プロジェクト: cobr123/qtVlc
/*****************************************************************************
 * Open:
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    demux_t      *p_demux = (demux_t*)p_this;
    demux_sys_t  *p_sys;
    es_format_t   fmt;
    dc1394error_t res;
    int           i_width;
    int           i_height;

    if( strncmp(p_demux->psz_access, "dc1394", 6) != 0 )
        return VLC_EGENERIC;

    /* Set up p_demux */
    p_demux->pf_demux = Demux;
    p_demux->pf_control = Control;
    p_demux->info.i_update = 0;
    p_demux->info.i_title = 0;
    p_demux->info.i_seekpoint = 0;

    p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
    if( !p_sys )
        return VLC_ENOMEM;

    memset( &fmt, 0, sizeof( es_format_t ) );

    /* DEFAULTS */
    p_sys->video_mode      = DC1394_VIDEO_MODE_640x480_YUV422;
    p_sys->width           = 640;
    p_sys->height          = 480;
    p_sys->frame_rate      = DC1394_FRAMERATE_15;
    p_sys->brightness      = 200;
    p_sys->focus           = 0;
    p_sys->fd_audio        = -1;
    p_sys->p_dccontext     = NULL;
    p_sys->camera          = NULL;
    p_sys->selected_camera = -1;
    p_sys->dma_buffers     = 1;
    p_sys->reset_bus       = 0;

    /* PROCESS INPUT OPTIONS */
    if( process_options(p_demux) != VLC_SUCCESS )
    {
        msg_Err( p_demux, "Bad MRL, please check the option line "
                          "(MRL was: %s)",
                          p_demux->psz_path );
        free( p_sys );
        return VLC_EGENERIC;
    }

    p_sys->p_dccontext = dc1394_new();
    if( !p_sys->p_dccontext )
    {
        msg_Err( p_demux, "Failed to initialise libdc1394");
        free( p_sys );
        return VLC_EGENERIC;
    }

    if( FindCamera( p_sys, p_demux ) != VLC_SUCCESS )
    {
        dc1394_free( p_sys->p_dccontext );
        free( p_sys );
        return VLC_EGENERIC;
    }

    if( !p_sys->camera )
    {
        msg_Err( p_demux, "No camera found !!" );
        dc1394_free( p_sys->p_dccontext );
        free( p_sys );
        return VLC_EGENERIC;
    }

    if( p_sys->reset_bus )
    {
        if( dc1394_reset_bus( p_sys->camera ) != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "Unable to reset IEEE 1394 bus");
            Close( p_this );
            return VLC_EGENERIC;
        }
        else msg_Dbg( p_demux, "Successfully reset IEEE 1394 bus");
    }

    if( dc1394_camera_reset( p_sys->camera ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to reset camera");
        Close( p_this );
        return VLC_EGENERIC;
    }

    if( dc1394_camera_print_info( p_sys->camera,
                  stderr ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to print camera info");
        Close( p_this );
        return VLC_EGENERIC;
    }

    if( dc1394_feature_get_all( p_sys->camera,
                &p_sys->features ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to get feature set");
        Close( p_this );
        return VLC_EGENERIC;
    }
    // TODO: only print features if verbosity increased
    dc1394_feature_print_all(&p_sys->features, stderr);

#if 0 //"Note that you need to execute this function only if you use exotic video1394 device names. /dev/video1394, /dev/video1394/* and /dev/video1394-* are automatically recognized." http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/api/capture/
    if( p_sys->video_device )
    {
        if( dc1394_capture_set_device_filename( p_sys->camera,
                        p_sys->video_device ) != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "Unable to set video device");
            Close( p_this );
            return VLC_EGENERIC;
        }
    }
#endif

    if( p_sys->focus )
    {
        if( dc1394_feature_set_value( p_sys->camera,
                      DC1394_FEATURE_FOCUS,
                      p_sys->focus ) != DC1394_SUCCESS )
        {
            msg_Err( p_demux, "Unable to set initial focus to %u",
                     p_sys->focus );
        }
        else
            msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus );
    }

    if( dc1394_feature_set_value( p_sys->camera,
                  DC1394_FEATURE_FOCUS,
                  p_sys->brightness ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to set initial brightness to %u",
                 p_sys->brightness );
    }
    else
        msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness );

    if( dc1394_video_set_framerate( p_sys->camera,
                    p_sys->frame_rate ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to set framerate");
        Close( p_this );
        return VLC_EGENERIC;
    }

    if( dc1394_video_set_mode( p_sys->camera,
                   p_sys->video_mode ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to set video mode");
        Close( p_this );
        return VLC_EGENERIC;
    }

    if( dc1394_video_set_iso_speed( p_sys->camera,
                    DC1394_ISO_SPEED_400 ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to set iso speed");
        Close( p_this );
        return VLC_EGENERIC;
    }

    /* and setup capture */
    res = dc1394_capture_setup( p_sys->camera,
                    p_sys->dma_buffers,
                DC1394_CAPTURE_FLAGS_DEFAULT);
    if( res != DC1394_SUCCESS )
    {
        if( res == DC1394_NO_BANDWIDTH )
        {
            msg_Err( p_demux ,"No bandwidth: try adding the "
             "\"resetbus\" option" );
        }
        else
        {
            msg_Err( p_demux ,"Unable to setup capture" );
        }
        Close( p_this );
        return VLC_EGENERIC;
    }

    /* TODO - UYV444 chroma converter is missing, when it will be available
     * fourcc will become variable (and not just a fixed value for UYVY)
     */
    i_width = p_sys->width;
    i_height = p_sys->height;

    if( picture_Setup( &p_sys->pic, VLC_CODEC_UYVY,
                       i_width, i_height, 1, 1 ) )
    {
        msg_Err( p_demux ,"unknown chroma" );
        Close( p_this );
        return VLC_EGENERIC;
    }

    es_format_Init( &fmt, VIDEO_ES, VLC_CODEC_UYVY );

    fmt.video.i_width = i_width;
    fmt.video.i_height = i_height;

    msg_Dbg( p_demux, "Added new video es %4.4s %dx%d",
             (char*)&fmt.i_codec, fmt.video.i_width, fmt.video.i_height );

    p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );

    if( p_sys->audio_device )
    {
        if( OpenAudioDev( p_demux ) == VLC_SUCCESS )
        {
            es_format_t fmt;
            es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_S16L ); /* FIXME: hmm, ?? */

            fmt.audio.i_channels = p_sys->channels ? p_sys->channels : 1;
            fmt.audio.i_rate = p_sys->i_sample_rate;
            fmt.audio.i_bitspersample = 16;
            fmt.audio.i_blockalign = fmt.audio.i_channels *
                                     fmt.audio.i_bitspersample / 8;
            fmt.i_bitrate = fmt.audio.i_channels * fmt.audio.i_rate *
                            fmt.audio.i_bitspersample;

            msg_Dbg( p_demux, "New audio es %d channels %dHz",
            fmt.audio.i_channels, fmt.audio.i_rate );

            p_sys->p_es_audio = es_out_Add( p_demux->out, &fmt );
        }
    }

    /* have the camera start sending us data */
    if( dc1394_video_set_transmission( p_sys->camera,
                       DC1394_ON ) != DC1394_SUCCESS )
    {
        msg_Err( p_demux, "Unable to start camera iso transmission" );
        dc1394_capture_stop( p_sys->camera );
        Close( p_this );
        return VLC_EGENERIC;
    }
    msg_Dbg( p_demux, "Set iso transmission" );
    // TODO: reread camera
    return VLC_SUCCESS;
}
コード例 #19
0
ファイル: cap_dc1394_v2.cpp プロジェクト: huamulan/opencv
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;
}
コード例 #20
0
ファイル: libdc1394.c プロジェクト: 248668342/ffmpeg-windows
static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
{
    dc1394_data* dc1394 = c->priv_data;
    dc1394camera_list_t *list;
    int res, i;
    struct dc1394_frame_format *fmt = NULL;
    struct dc1394_frame_rate *fps = NULL;

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

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

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

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

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

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

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

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

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

out_camera:
    dc1394_capture_stop(dc1394->camera);
    dc1394_video_set_transmission(dc1394->camera, DC1394_OFF);
    dc1394_camera_free (dc1394->camera);
out:
    dc1394_free(dc1394->d);
    return -1;
}
コード例 #21
0
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;

}
コード例 #22
0
ファイル: gstdc1394.c プロジェクト: asrashley/gst-plugins-bad
static gboolean
gst_dc1394_open_cam_with_best_caps (GstDc1394 * src)
{
    dc1394camera_list_t *cameras = NULL;
    gint err = 0;
    int framerateconst;

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


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

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

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

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

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

    dc1394_camera_free_list (cameras);
    cameras = NULL;

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

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

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

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

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

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

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

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

            goto error;
        }

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

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

        }
    }


    return TRUE;

error:

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

    return FALSE;

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

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

  dc1394error_t err;

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

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

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

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

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

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

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

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

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

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

  }

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

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

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

  QueryXv();

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

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

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

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

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

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

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

    display_frames();
    XFlush(display);

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

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

  } /* while not interrupted */

  exit(0);
}
コード例 #24
0
ファイル: DC1394Camera.cpp プロジェクト: JasonHagler/tortuga
void DC1394Camera::init(core::ConfigNode config, uint64_t guid)
{
    LOGGER.infoStream() << guid << ": Initializing camera ";
    m_guid = guid;

    // Grab our camera 
    m_camera = dc1394_camera_new(s_libHandle, guid);
    if (!m_camera) {
        LOGGER.errorStream() <<
            "Failed to initialize camera with guid: " << guid;
        assert(m_camera && "Couldn't initialize camera");
    }

    // Determines settings and frame size
    dc1394error_t err = DC1394_FAILURE;
    dc1394video_mode_t videoMode = DC1394_VIDEO_MODE_640x480_RGB8;
    dc1394framerate_t frameRate = DC1394_FRAMERATE_15;

    // Check for the whitebalance feature
    dc1394feature_info_t whiteBalance;
    whiteBalance.id = DC1394_FEATURE_WHITE_BALANCE;
    err = dc1394_feature_get(m_camera, &whiteBalance);
    assert(DC1394_SUCCESS == err && "Could not get white balance feature info");
    bool hasWhiteBalance = (whiteBalance.available == DC1394_TRUE);

    uint32_t uValue, vValue;
    if (hasWhiteBalance)
    {
        err = dc1394_feature_whitebalance_get_value(m_camera, &uValue, &vValue);
        LOGGER.infoStream() << m_guid
                            << ": Current U: " << uValue
                            << " V: " << vValue;
    }
    
    // Actually set the values if the user wants to
    if (config.exists("uValue") && config.exists("vValue"))
    {
        bool uAuto =
            boost::to_lower_copy(config["uValue"].asString("auto")) == "auto";
        bool vAuto =
            boost::to_lower_copy(config["vValue"].asString("auto")) == "auto";
        bool autoVal = uAuto && vAuto;

        if ((uAuto || vAuto) && !autoVal)
        {
            assert(false && "Both Whitebalance values must either be auto or manual");
        }

        if (autoVal)
        {
            setWhiteBalance(0, 0, true);
        }
        else
        {
            // Read in config values
            uint32_t u_b_value = static_cast<uint32_t>(config["uValue"].asInt());
            uint32_t v_r_value = static_cast<uint32_t>(config["vValue"].asInt());

            // Set values
            setWhiteBalance(u_b_value, v_r_value);
        }
    }
    else if (config.exists("uValue") || config.exists("vValue"))
    {
        assert(false && "Must set both the U and V values for white balance");
    }

    err = dc1394_feature_whitebalance_get_value(m_camera, &uValue, &vValue);
    LOGGER.infoStream() << m_guid
                        << ": Set U: " << uValue 
                        << " V: " << vValue;


    
    if (config.exists("brightness"))
    {
        // Read in and set values
        if (boost::to_lower_copy(config["brightness"].asString("auto")) == "auto")
        {
            setBrightness(0, true);
        }
        else
        {
            uint32_t value = static_cast<uint32_t>(config["brightness"].asInt());
            setBrightness(value);
        }
    }

    if (config.exists("exposure"))
    {
        // Read in and set values
        if (boost::to_lower_copy(config["exposure"].asString("auto")) == "auto")
        {
            setExposure(0, true);
        }
        else
        {
            uint32_t value = static_cast<uint32_t>(config["exposure"].asInt());
            setExposure(value);
        }
    }


    
    // Grab image size
    err = dc1394_get_image_size_from_video_mode(m_camera, videoMode,
                                                &m_width, &m_height);
    assert(DC1394_SUCCESS == err && "Could not get image size");
    
    float fRate;
    err = dc1394_framerate_as_float(frameRate, &fRate);
    assert(DC1394_SUCCESS == err && "Could not get framerate as float");
    m_fps = fRate;

    // Setup the capture
    err = dc1394_video_set_iso_speed(m_camera, DC1394_ISO_SPEED_400);
    assert(DC1394_SUCCESS == err && "Could not set iso speed");
           
    err = dc1394_video_set_mode(m_camera, videoMode);
    assert(DC1394_SUCCESS == err && "Could not set video mode");

    err = dc1394_video_set_framerate(m_camera, frameRate);
    assert(DC1394_SUCCESS == err && "Could not set framerate");

    // Start data transfer
    err = dc1394_video_set_transmission(m_camera, DC1394_ON);
    assert(DC1394_SUCCESS == err && "Could not start camera iso transmission");

    err = dc1394_capture_setup(m_camera, DMA_BUFFER_SIZE,
                               DC1394_CAPTURE_FLAGS_DEFAULT);
    assert(DC1394_SUCCESS == err && "Could not setup camera make sure"
           " that the video mode and framerate are supported by your camera");
}