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; }
bool Camera::Init() { // VideoCapture Interface cv_image_ = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 3); // Initialize libdc1394 if ((d = dc1394_new ()) == NULL) return false; // Find cameras err = dc1394_camera_enumerate(d, &list); DC1394_ERR_RTN(err, "Failed to enumerate cameras"); // Verify that we have at least one cameraDC1394_BYTE_ORDER_YUYV if(list->num == 0) { dc1394_log_error("No cameras found"); return false; } // Work with first camera found if ((camera = dc1394_camera_new (d, list->ids[0].guid)) == NULL) { dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid); return false; } // Not using the list anymore, clean it up dc1394_camera_free_list(list); // Power ON dc1394_camera_set_power(camera, DC1394_ON); // Print camera info dc1394_camera_print_info(camera, stdout); // Setup capture err = dc1394_capture_setup(camera, 4, DC1394_CAPTURE_FLAGS_DEFAULT); // Set video mode dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_640x480_YUV422); // Start transmission err = dc1394_video_set_transmission(camera, DC1394_ON); // VideoCapture Interface init_ = true; return true; }
void CameraIIDC::startCapture(){ dc1394error_t err; // Print camera information dc1394_camera_print_info(cam, stdout); fflush(stdout); if(triggerMode == triggerModeHardware){ // Set hardware trigger err=dc1394_external_trigger_set_power(cam, DC1394_ON); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set external trigger on!"; err=dc1394_external_trigger_set_source(cam, DC1394_TRIGGER_SOURCE_0); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set external trigger source!"; err=dc1394_external_trigger_set_mode(cam, DC1394_TRIGGER_MODE_14); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set external trigger mode!"; err=dc1394_external_trigger_set_polarity(cam, DC1394_TRIGGER_ACTIVE_HIGH); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set external trigger polarity!"; } else if(triggerMode == triggerModeSoftware) { // Disable hardware trigger err=dc1394_external_trigger_set_power(cam, DC1394_OFF); if (err!=DC1394_SUCCESS) cerr << "libdc1394: Could not set external trigger off!"; } // Begin transmission err = dc1394_video_set_transmission(cam, DC1394_ON); if (err!=DC1394_SUCCESS) { cerr << "ERROR: Could not begin transmission!" << endl; } capturing = true; }
/***************************************************************************** * 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; }
int main (int argc, char **argv) { dc1394camera_t *camera = NULL; uint64_t guid = 0x0LL; dc1394_t * d; dc1394camera_list_t * list; 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; } /* parse arguments */ if (argc == 2) { if (!strcmp (argv[1], "--list-cameras")) list_cameras (d, list); else print_usage(); dc1394_camera_free_list (list); dc1394_free (d); return 0; } else if (argc == 3) { if (!strcmp (argv[1], "--guid")) { if (sscanf (argv[2], "0x%"PRIx64, &guid) == 1) { } else { dc1394_camera_free_list (list); dc1394_free (d); return print_usage(); } } } else if (argc != 1) { dc1394_camera_free_list (list); dc1394_free (d); return print_usage(); } if (guid == 0x0LL) { printf ("I: found %d camera%s, working with camera 0\n", list->num, list->num == 1 ? "" : "s"); camera = dc1394_camera_new (d, list->ids[0].guid); } else { camera = dc1394_camera_new (d, guid); if (camera == NULL) { dc1394_log_error("no camera with guid 0x%"PRIx64" found", guid); return 1; } printf ("I: found camera with guid 0x%"PRIx64"\n", guid); } dc1394_camera_print_info (camera, stdout); printf ("\nSFF feature info:\n"); dc1394_basler_sff_feature_print_all (camera, stdout); dc1394_camera_free (camera); dc1394_camera_free_list (list); dc1394_free (d); return 0; }
void Libdc1394SequenceGrabber::populateDeviceInfoList(cefix::SequenceGrabberDeviceInfoList& devices) { dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; dc1394video_modes_t video_modes; dc1394framerates_t framerates; d = Libdc1394Context::get(); if (!d) return; err=dc1394_camera_enumerate (d, &list); for(unsigned int i = 0; i < list->num; ++i) { osg::notify(osg::INFO) << "UID: " << list->ids[i].guid << std::endl; dc1394camera_t* camera = dc1394_camera_new (d, list->ids[i].guid); if (!camera) continue; devices.push_back(cefix::SequenceGrabber::DeviceInfo(getGrabberId(), cefix::longToHexString(list->ids[i].guid))); dc1394_camera_print_info(camera, stdout); err=dc1394_video_get_supported_modes(camera,&video_modes); osg::notify(osg::INFO) << "available video-modes: " << std::endl; for (int j = 0;j < video_modes.num;j++) { osg::notify(osg::INFO) << "* " << getVideoMode(video_modes.modes[j]); if (dc1394_video_get_supported_framerates(camera, video_modes.modes[j], &framerates) == DC1394_SUCCESS) { osg::notify(osg::INFO) << " fps: "; for(unsigned int k = 0; k < framerates.num; ++k) { osg::notify(osg::INFO) << " " << getFrameRate(framerates.framerates[k]); } } osg::notify(osg::INFO) << std::endl; } dc1394featureset_t features; dc1394_feature_get_all(camera, &features); dc1394_feature_print_all(&features, stdout); /* for( int j = 0; j < DC1394_FEATURE_NUM; j++ ) { const dc1394feature_info_t& f = features.feature[j]; if( f.available ) { std::cout << getNameOfFeature(f.id) << std::endl; std::cout << " current mode: "; switch(f.current_mode) { case DC1394_FEATURE_MODE_MANUAL: std::cout << "manual"; break; case DC1394_FEATURE_MODE_AUTO: std::cout << "auto"; break; case DC1394_FEATURE_MODE_ONE_PUSH_AUTO: std::cout << "one-push"; break; } std::cout << std::endl; std::cout << " min: " << f.min << " max: " << f.max << " value: " << f.value << std::endl; if (f.absolute_capable==DC1394_TRUE) { std::cout << " abs:min: " << f.abs_min << " max: " << f.abs_max << " value: " << f.abs_value << std::endl; } } } */ dc1394_camera_free(camera); } dc1394_camera_free_list(list); }
int main(int argc, const char * argv[]) { dc1394_t *d; dc1394camera_list_t *list; dc1394error_t err; dc1394camera_t *camera; dc1394format7modeset_t modeset; dc1394video_frame_t *frame; FILE* imagefile; char filename[256]; int i = 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"); dc1394_free(d); return 1; } printf("Detected %d cameras\n", list->num); // Assume that Ladybug 5 is detected as camera #0 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); dc1394_free(d); } dc1394_camera_free_list(list); printf("Using camera %s %s\n", camera->vendor, camera->model); // Report camera info err = dc1394_camera_print_info(camera, stdout); DC1394_ERR_RTN(err, "Could not print camera info"); // Setup video mode, etc... err = dc1394_video_set_operation_mode(camera, DC1394_OPERATION_MODE_1394B); DC1394_ERR_RTN(err, "Could not set B mode"); err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_MAX); DC1394_ERR_RTN(err, "Could not set max speed"); err = dc1394_video_set_mode(camera, DC1394_VIDEO_MODE_FORMAT7_0); DC1394_ERR_RTN(err, "Could not set DC1394_VIDEO_MODE_FORMAT7_0"); // Get format7 mode info err = dc1394_format7_get_modeset(camera, &modeset); DC1394_ERR_RTN(err, "Could not get format 7 mode info\n"); print_format7_info(&modeset); // Set format 7 roi err = dc1394_format7_set_roi(camera, DC1394_VIDEO_MODE_FORMAT7_0, modeset.mode[0].color_coding, modeset.mode[0].max_packet_size, modeset.mode[0].pos_x, modeset.mode[0].pos_y, modeset.mode[0].max_size_x, modeset.mode[0].max_size_y); DC1394_ERR_RTN(err, "Could not set max ROI"); // Set capture err = dc1394_capture_setup(camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT); DC1394_ERR_RTN(err, "Could not setup capture"); err = dc1394_video_set_transmission(camera, DC1394_ON); DC1394_ERR_RTN(err, "Could not start transmission"); while (i < NFRAMES) { // Capture image printf("Capturing image %d\n", i); err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame); DC1394_ERR_RTN(err, "Could not dequeue a frame"); // Do something with the image print_frame_info(frame); // Save the image sprintf(filename, "%05d.pgm",i); imagefile = fopen(filename, "wb"); if ( imagefile == NULL ) { printf("Could not save image\n"); continue; } fprintf(imagefile, "P5\n%u %u 255\n", frame->size[0], frame->size[1]); fwrite(frame->image, 1, frame->image_bytes, imagefile); fclose(imagefile); printf("Saved image %s\n", filename); err = dc1394_capture_enqueue(camera, frame); DC1394_ERR_RTN(err, "Could enqueue a frame"); i++; } dc1394_camera_free(camera); dc1394_free(d); return 0; }