int _listFeatures(){ if(camera==NULL) { dc1394_log_error("Camera is not initialised"); return -1; } dc1394featureset_t features; /*----------------------------------------------------------------------- * report camera's features *-----------------------------------------------------------------------*/ err=dc1394_feature_get_all(camera,&features); if (err!=DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&features, stdout); } dc1394_avt_adv_feature_info_t adv_feature; dc1394_avt_get_advanced_feature_inquiry(camera, &adv_feature); if (err!=DC1394_SUCCESS) { dc1394_log_warning("Could not get adv feature set"); } else { dc1394_avt_print_advanced_feature(&adv_feature); } }
int main(int argc, char *argv[]) { unsigned int i; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; dc1394featureset_t features; d = dc1394_new(); if(!d) return 1; err = dc1394_camera_enumerate(d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if(list->num == 0) { dc1394_log_error("No cameras found"); return 1; } for(i = 0; i < list->num; i++) { dc1394camera_t *camera = dc1394_camera_new(d, list->ids[i].guid); if(camera) { unsigned int j; dc1394video_modes_t modes; // Print hardware informations. dc1394_camera_print_info(camera, stdout); // Print supported camera features. err = dc1394_feature_get_all(camera,&features); if(err != DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&features, stdout); } // Print a list of supported modes. printf("------ Supported Video Modes ------\n"); err = dc1394_video_get_supported_modes(camera, &modes); DC1394_ERR_RTN(err,"Could not get list of modes"); for(j = 0; j < modes.num; j++) { print_video_mode_info(camera, modes.modes[j]); } dc1394_camera_free(camera); } } dc1394_camera_free_list (list); dc1394_free (d); return 0; }
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); }
static int _report_camera_features( QSP_ARG_DECL PGR_Cam *pgcp ) { // report camera's features dc1394featureset_t features; if ( /*dc1394_get_camera_feature_set*/ dc1394_feature_get_all( pgcp->pc_cam_p, &features ) != DC1394_SUCCESS ) { warn("report_camera_features: unable to get camera feature set"); return -1; } /*dc1394_print_feature_set( &features ); */ dc1394_feature_print_all( &features,stdout ); return 0; }
void show_camera_features(PGR_Cam *pgcp) { dc1394featureset_t features; if( /* dc1394_get_camera_feature_set */ dc1394_feature_get_all (pgcp->pc_cam_p, &features) != DC1394_SUCCESS ){ warn("error getting camera feature set"); return; } if( /* dc1394_print_feature_set(&features) */ dc1394_feature_print_all(&features,stdout) != DC1394_SUCCESS ){ warn("error printing feature set"); } }
void *pdp_dc1394_new(t_symbol *vdef) { t_pdp_dc1394 *x = (t_pdp_dc1394 *)pd_new(pdp_dc1394_class); x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); x->d = dc1394_new (); x->err=dc1394_camera_enumerate (x->d, &x->list); //DC1394_ERR_RTN(x->err,"Failed to enumerate cameras"); //post("Failed to enumerate cameras"); if (x->list->num == 0) { dc1394_log_error("No cameras found"); return 1; } x->camera = dc1394_camera_new (x->d, x->list->ids[0].guid); if (!x->camera) { //dc1394_log_error("Failed to initialize camera with guid %"PRIx64, list->ids[0].guid); return 1; } dc1394_camera_free_list (x->list); //printf("Using camera with GUID %"PRIx64"\n", camera->guid); /*----------------------------------------------------------------------- * get the best video mode and highest framerate. This can be skipped * if you already know which mode/framerate you want... *-----------------------------------------------------------------------*/ // get video modes: x->err=dc1394_video_get_supported_modes(x->camera,&x->video_modes); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Can't get video modes"); // select highest res mode: for (x->i=x->video_modes.num-1;x->i>=0;x->i--) { if (!dc1394_is_video_mode_scalable(x->video_modes.modes[x->i])) { dc1394_get_color_coding_from_video_mode(x->camera,x->video_modes.modes[x->i], &x->coding); if (x->coding==DC1394_COLOR_CODING_MONO8) { x->video_mode=x->video_modes.modes[x->i]; fprintf(stderr,"video_mode %d: %d\n",x->i,x->video_modes.modes[x->i]); break; } } } if (x->i < 0) { dc1394_log_error("Could not get a valid MONO8 mode"); cleanup_and_exit(x->camera); } x->err=dc1394_get_color_coding_from_video_mode(x->camera, x->video_mode,&x->coding); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get color coding"); fprintf(stderr,"color_coding : %d\n",x->coding); // get highest framerate x->err=dc1394_video_get_supported_framerates(x->camera,x->video_mode,&x->framerates); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not get framrates"); x->framerate=x->framerates.framerates[x->framerates.num-1]; fprintf(stderr,"framerate : %d\n",x->framerate); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ x->err=dc1394_video_set_iso_speed(x->camera, DC1394_ISO_SPEED_400); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set iso speed"); x->err=dc1394_video_set_mode(x->camera, x->video_mode); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set video mode"); x->err=dc1394_video_set_framerate(x->camera, x->framerate); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not set framerate"); x->err=dc1394_capture_setup(x->camera,4, DC1394_CAPTURE_FLAGS_DEFAULT); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not setup camera-\nmake sure that the video mode and framerate are\nsupported by your camera"); /*----------------------------------------------------------------------- * report camera's features *-----------------------------------------------------------------------*/ x->err=dc1394_feature_get_all(x->camera,&x->features); if (x->err!=DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&x->features, stdout); } /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ x->err=dc1394_video_set_transmission(x->camera, DC1394_ON); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not start camera iso transmission"); x->x_initialized = true; return (void *)x; }
//-------------------------------------------------------------------- int of1394VideoGrabber::initGrabber() { // moved from constructor int i; printf("Making new camera\n"); d = dc1394_new (); err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { if(err!=0 && bVerbose)printf("\n No cameras found\n "); return 1; } camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { if(err!=0 && bVerbose)printf("\n Failed to initialize camera with guid %PRIx64", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0); uint32_t f, f2; dc1394_format7_get_image_size(camera, DC1394_VIDEO_MODE_FORMAT7_0, &f, &f2); 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"); dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height); if(err != DC1394_SUCCESS){ cout<<"get image size error: "<<err<<endl; } printf("Size from video mode = %i wide %i high\n", width, height); pixels = new unsigned char[width*height*3]; // x3 for RGB pixels2 = new unsigned char[width*height*3]; // x3 for RGB tex.allocate(width,height,GL_LUMINANCE); 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"); memcpy( pixels, frame->image, width * height*3) ; dc1394_capture_enqueue( camera, frame ) ; ofSleepMillis(10); startThread(true, false); failedToInit = false; dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_GAMMA, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_IRIS, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_WHITE_BALANCE, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_TEMPERATURE, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_WHITE_SHADING, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_SATURATION, DC1394_FEATURE_MODE_AUTO); dc1394_feature_set_mode(camera, DC1394_FEATURE_HUE, DC1394_FEATURE_MODE_AUTO); //Print features dc1394_feature_get_all(camera, &features); dc1394_feature_print_all(&features, stdout); return 0; }
void ofxLibdc::printFeatures() const { dc1394featureset_t features; dc1394_feature_get_all(camera, &features); dc1394_feature_print_all(&features, stdout); }
/***************************************************************************** * 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; }
CameraIIDC::CameraIIDC(unsigned int camNum, CameraTriggerMode triggerMode) : Camera(triggerMode) { context = dc1394_new(); dc1394camera_list_t *camera_list; dc1394error_t err; err = dc1394_camera_enumerate(context, &camera_list); if(camNum+1 > camera_list->num){ cerr << "libdc1394: Selected camera is not available!"; return; } cam = NULL; cam = dc1394_camera_new(context, camera_list->ids[camNum].guid); if(!cam){ cerr << "libdc1394: Could not open camera!"; return; } dc1394_camera_free_list(camera_list); // // Get video modes // dc1394video_modes_t video_modes; // err=dc1394_video_get_supported_modes(cam, &video_modes); // DC1394_WRN(err,"Can't get video modes"); // // Select highest res mode // int i; // dc1394color_coding_t coding; // for (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(cam, video_modes.modes[i], &coding); // DC1394_WRN(err,"libdc1394: Could not get color coding"); // if (coding==DC1394_COLOR_CODING_MONO8) { // video_mode=video_modes.modes[i]; // break; // } // } // } // if (i < 0) { // cerr << "libdc1394: Could not get a valid gray scale mode!"; // return; // } // Select format 7 mode 0 video_mode = DC1394_VIDEO_MODE_FORMAT7_0; // Set bit depth err = dc1394_format7_set_color_coding(cam, video_mode, DC1394_COLOR_CODING_MONO8); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set video mode or color coding!"; // // Set video mode // err=dc1394_video_set_mode(cam, video_mode); // if (err!=DC1394_SUCCESS) // cerr << "libdc1394: Could not set video mode!"; // Setup capture err=dc1394_video_set_operation_mode(cam, DC1394_OPERATION_MODE_1394B); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set operation mode!"; err=dc1394_video_set_iso_speed(cam, DC1394_ISO_SPEED_800); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set iso speed!"; // Size of ringbuffer (Note: on OS X 10.9, size must be greater than 1) #ifdef __APPLE__ unsigned int bufferSize = 2; #else unsigned int bufferSize = 1; #endif err=dc1394_capture_setup(cam, bufferSize, DC1394_CAPTURE_FLAGS_DEFAULT); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set up camera!"; // Disable auto exposure mode dc1394_feature_set_power(cam, DC1394_FEATURE_EXPOSURE, DC1394_OFF); // Disable gamma mode dc1394_feature_set_power(cam, DC1394_FEATURE_GAMMA, DC1394_OFF); // Disable sharpness mode dc1394_feature_set_power(cam, DC1394_FEATURE_SHARPNESS, DC1394_OFF); // Disable frame-rate mode dc1394_feature_set_power(cam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF); // Set manual settings dc1394_feature_set_mode(cam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); dc1394_feature_set_mode(cam, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL); // Set reasonable default settings CameraSettings settings; //settings.shutter = 8.333; settings.shutter = 16.66; settings.gain = 0.0; this->setCameraSettings(settings); // Print camera features and settings dc1394featureset_t features; err=dc1394_feature_get_all(cam, &features); DC1394_WRN(err, "libdc1394: Could not get feature set."); dc1394_feature_print_all(&features, stdout); fflush(stdout); return; }
//-------------------------------------------------------------------- bool ofxVideoGrabberPtgrey::initGrabber(int w, int h, bool setUseTexture){ width = w; height = h; bUseTexture = setUseTexture; // In format_7 the framerate is set by setting the packet_size // this is used in dc1394_format7_set_roi() // The following formula is from the libdc1394 faq // http://damien.douxchamps.net/ieee1394/libdc1394/v2.x/faq/#How_can_I_work_out_the_packet_size_for_a_wanted_frame_rate float bus_period = 0.000125; // for firewire 400 int frame_rate = 60; int depth = 3; int num_packets = (int)(1.0/(bus_period*frame_rate) + 0.5); //packet_size = (width*height*depth + (num_packets*8) - 1)/(num_packets*8); packet_size = DC1394_USE_MAX_AVAIL; //first choose a device to use if( bChooseDevice ) { bool bFound = false; for (uint32_t index = 0; index < deviceList->num; index++) { if (deviceList->ids[index].unit == deviceID) { bFound = true; deviceID = deviceList->ids[index].guid; } } if (!bFound) { printf("initGrabber warning: Device ID for unit %x not found, using first device\n", deviceID); deviceID = deviceList->ids[0].guid; } } else if(deviceList->num > 0) { deviceID = deviceList->ids[0].guid; } else { ofLog(OF_LOG_ERROR, "in initGrabber, No cameras found"); } camera = dc1394_camera_new(driver, deviceID); if (!camera) { ofLog(OF_LOG_ERROR, "Failed to initialize camera with guid %x", deviceID); return 1; } /*----------------------------------------------------------------------- * setup capture *-----------------------------------------------------------------------*/ err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set iso speed"); } err = dc1394_video_set_mode( camera, video_mode ); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 video mode"); } err = dc1394_format7_set_color_coding(camera, video_mode, color_coding); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 color coding"); } err = dc1394_format7_set_packet_size(camera, video_mode, packet_size); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7 packet_size"); } err = dc1394_format7_set_roi(camera, video_mode, color_coding, packet_size, 0,0, width,height); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to set format 7"); } //err = dc1394_video_set_framerate(camera, framerate); //DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not set framerate"); err = dc1394_capture_setup(camera,2, DC1394_CAPTURE_FLAGS_DEFAULT); if( err != DC1394_SUCCESS ) { ofLog(OF_LOG_ERROR, "failed to setup dma capturing"); } /*----------------------------------------------------------------------- * set camera's features *-----------------------------------------------------------------------*/ err = dc1394_feature_set_mode(camera, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); err = dc1394_feature_set_value(camera, DC1394_FEATURE_BRIGHTNESS, 200); //1-255 err = dc1394_feature_set_mode(camera, DC1394_FEATURE_EXPOSURE, DC1394_FEATURE_MODE_MANUAL); err = dc1394_feature_set_value(camera, DC1394_FEATURE_EXPOSURE, 62); //7-62 err = dc1394_feature_set_mode(camera, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); err = dc1394_feature_set_value(camera, DC1394_FEATURE_SHUTTER, 60); //1-263, 64 being the max for 60fps err = dc1394_feature_set_mode(camera, DC1394_FEATURE_GAIN, DC1394_FEATURE_MODE_MANUAL); err = dc1394_feature_set_value(camera, DC1394_FEATURE_GAIN, 50); //16-64 //err = dc1394_feature_set_mode(camera, DC1394_FEATURE_PAN, DC1394_FEATURE_MODE_MANUAL); //err = dc1394_feature_set_value(camera, DC1394_FEATURE_PAN, 56); /*----------------------------------------------------------------------- * report camera's features *-----------------------------------------------------------------------*/ err=dc1394_feature_get_all(camera,&features); if (err!=DC1394_SUCCESS) { dc1394_log_warning("Could not get feature set"); } else { dc1394_feature_print_all(&features, stdout); } /*----------------------------------------------------------------------- * have the camera start sending us data *-----------------------------------------------------------------------*/ err=dc1394_video_set_transmission(camera, DC1394_ON); //DC1394_ERR_CLN_RTN(err,cleanup_and_exit(camera),"Could not start camera iso transmission"); //create pixel buffer pixels = new unsigned char[width * height * 3]; //create texture if (bUseTexture) { tex.allocate(width,height,GL_LUMINANCE); memset(pixels, 0, width*height); tex.loadData(pixels, width, height, GL_LUMINANCE); } }
void Libdc1394SequenceGrabber::populateDeviceInfoList(cefix::SequenceGrabberDeviceInfoList& devices) { dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; dc1394video_modes_t video_modes; dc1394framerates_t framerates; d = Libdc1394Context::get(); if (!d) return; err=dc1394_camera_enumerate (d, &list); for(unsigned int i = 0; i < list->num; ++i) { osg::notify(osg::INFO) << "UID: " << list->ids[i].guid << std::endl; dc1394camera_t* camera = dc1394_camera_new (d, list->ids[i].guid); if (!camera) continue; devices.push_back(cefix::SequenceGrabber::DeviceInfo(getGrabberId(), cefix::longToHexString(list->ids[i].guid))); dc1394_camera_print_info(camera, stdout); err=dc1394_video_get_supported_modes(camera,&video_modes); osg::notify(osg::INFO) << "available video-modes: " << std::endl; for (int j = 0;j < video_modes.num;j++) { osg::notify(osg::INFO) << "* " << getVideoMode(video_modes.modes[j]); if (dc1394_video_get_supported_framerates(camera, video_modes.modes[j], &framerates) == DC1394_SUCCESS) { osg::notify(osg::INFO) << " fps: "; for(unsigned int k = 0; k < framerates.num; ++k) { osg::notify(osg::INFO) << " " << getFrameRate(framerates.framerates[k]); } } osg::notify(osg::INFO) << std::endl; } dc1394featureset_t features; dc1394_feature_get_all(camera, &features); dc1394_feature_print_all(&features, stdout); /* for( int j = 0; j < DC1394_FEATURE_NUM; j++ ) { const dc1394feature_info_t& f = features.feature[j]; if( f.available ) { std::cout << getNameOfFeature(f.id) << std::endl; std::cout << " current mode: "; switch(f.current_mode) { case DC1394_FEATURE_MODE_MANUAL: std::cout << "manual"; break; case DC1394_FEATURE_MODE_AUTO: std::cout << "auto"; break; case DC1394_FEATURE_MODE_ONE_PUSH_AUTO: std::cout << "one-push"; break; } std::cout << std::endl; std::cout << " min: " << f.min << " max: " << f.max << " value: " << f.value << std::endl; if (f.absolute_capable==DC1394_TRUE) { std::cout << " abs:min: " << f.abs_min << " max: " << f.abs_max << " value: " << f.abs_value << std::endl; } } } */ dc1394_camera_free(camera); } dc1394_camera_free_list(list); }
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; }