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); }
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); }
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; }
//============================================================================= // querySteroeCamera() // // Given that the camera handle is a stereo camera, query the camera for // stereo specific information about this camera and populate the // PGRStereoCamera_t handle structure // dc1394error_t queryStereoCamera( dc1394camera_t* camera, PGRStereoCamera_t* stereoCamera ) { // set the camera handle stereoCamera->camera = camera; // find out what base model camera we have stereoCamera->model = getCameraModel( camera ); if ( stereoCamera->model == UNKNOWN_CAMERA ) return DC1394_FAILURE; dc1394error_t err; if ( stereoCamera->model != BUMBLEBEE ) { err = getSensorInfo( camera, &stereoCamera->bColor, &stereoCamera->nRows, &stereoCamera->nCols ); if ( err != DC1394_SUCCESS ) { fprintf( stderr, "Could not query the Sensor Info Register!\n" ); return err; } } else // model == BUMBLEBEE { // This is a Bumblebee "1". This camera does not support the // sensor board info register so we need to determine if it is color // and the resolution the hard way // // It will be nice when we don't need to support BB1 anymore as it is // not completely DC-compliant dc1394video_modes_t video_modes; err = dc1394_video_get_supported_modes( camera, &video_modes ); if ( err != DC1394_SUCCESS ) { fprintf( stderr, "Can't get video modes\n" ); return err; } // find the highest res mode that is greyscale (MONO16) printf( "Searching for the highest resolution MONO16 mode available...\n" ); dc1394video_mode_t video_mode; dc1394color_coding_t coding; for ( int i = video_modes.num-1; i >= 0; i-- ) { // don't consider FORMAT 7 modes (i.e. "scalable") if ( !dc1394_is_video_mode_scalable( video_modes.modes[i] ) ) { dc1394_get_color_coding_from_video_mode( camera, video_modes.modes[i], &coding ); if ( coding == DC1394_COLOR_CODING_MONO16 ) { video_mode = video_modes.modes[i]; break; } } } if ( video_mode == DC1394_VIDEO_MODE_640x480_MONO16 ) { stereoCamera->nRows = 480; stereoCamera->nCols = 640; } else if ( video_mode == DC1394_VIDEO_MODE_1024x768_MONO16 ) { stereoCamera->nRows = 768; stereoCamera->nCols = 1024; } else { fprintf( stderr, "Cannot find valid MONO16 video mode!\n" ); return DC1394_FAILURE; } dc1394color_filter_t bayerPattern; err = getBayerTile( stereoCamera->camera, &bayerPattern ); if ( err != DC1394_SUCCESS ) { fprintf( stderr, "Failed to read the Bayer Tile Pattern register\n" ); return err; } // at this point all we need to know is "is it color or mono?" if ( bayerPattern == 0 ) stereoCamera->bColor = false; else stereoCamera->bColor = true; } // a hack to figure out how many bytes per pixel are needed. // if the camera is a BB3, then it is 3, otherwise 2 if ( stereoCamera->nRows == 960 ) { //stereoCamera->nBytesPerPixel = 3; // note: for performance reasons we have changed the default behavior // of the XB3 for these examples to only use the 2 wide-baseline pair. // This makes for faster image transmission. // If you change the code to transmit all 3 images, this value will // have to revert to 3. stereoCamera->nBytesPerPixel = 2; } else { stereoCamera->nBytesPerPixel = 2; } return DC1394_SUCCESS; }
static int set_default_video_mode(PGR_Cam *pgcp) { dc1394camera_t* cam_p; dc1394video_mode_t video_mode; int i; cam_p = pgcp->pc_cam_p; // get the best video mode and highest framerate. This can be skipped // if you already know which mode/framerate you want... // get video modes: if( dc1394_video_get_supported_modes( cam_p, &pgcp->pc_video_modes ) != DC1394_SUCCESS ){ return -1; } // select highest res mode that is greyscale (MONO8) /* printf("Searching for the highest resolution MONO8 mode available (of %d modes)...\n", video_modes.num); */ dc1394color_coding_t coding; // assign an invalid value to video_mode to quiet compiler, // then check below to make sure a mode we want was found... video_mode = BAD_VIDEO_MODE; //fprintf(stderr,"Checking %d video modes...\n",pgcp->pc_video_modes.num); for ( i = pgcp->pc_video_modes.num-1; i >= 0; i-- ) { // don't consider FORMAT 7 modes (i.e. "scalable") if ( !dc1394_is_video_mode_scalable( pgcp->pc_video_modes.modes[i] ) ) { dc1394_get_color_coding_from_video_mode( cam_p, pgcp->pc_video_modes.modes[i], &coding ); //fprintf(stderr,"Checking non-scalable mode %d\n",pgcp->pc_video_modes.modes[i]); if ( coding == DC1394_COLOR_CODING_MONO8 ) { video_mode = pgcp->pc_video_modes.modes[i]; break; } } else { //fprintf(stderr,"Not checking scalable mode %d\n",pgcp->pc_video_modes.modes[i]); } } if( video_mode == BAD_VIDEO_MODE ){ // only scalable modes? for ( i = pgcp->pc_video_modes.num-1; i >= 0; i-- ) { dc1394_get_color_coding_from_video_mode( cam_p, pgcp->pc_video_modes.modes[i], &coding ); if( coding == DC1394_COLOR_CODING_MONO8 || coding == DC1394_COLOR_CODING_RAW8 ) { video_mode = pgcp->pc_video_modes.modes[i]; break; } } } assert( video_mode != BAD_VIDEO_MODE ); #ifdef FOOBAR // double check that we found a video mode that is MONO8 dc1394_get_color_coding_from_video_mode( cam_p, video_mode, &coding ); if ( ( dc1394_is_video_mode_scalable( video_mode ) ) || ( coding != DC1394_COLOR_CODING_MONO8 && coding != DC1394_COLOR_CODING_RAW8 ) ) { warn("Could not get a valid MONO8 mode" ); return -1; } #endif // FOOBAR dc1394_video_set_mode( pgcp->pc_cam_p, video_mode ); pgcp->pc_video_mode = video_mode; return 0; }