34 #include <Base/Image/Image.hh>
35 #include <Base/Image/ImageIO.hh>
36 #include <dc1394/dc1394.h>
43 #define NUM_DMA_BUFFERS 4
51 void cleanup_and_exit(dc1394camera_t *camera)
53 dc1394_video_set_transmission(camera, DC1394_OFF);
54 dc1394_capture_stop(camera);
55 dc1394_camera_free(camera);
59 int main(
int argc,
char *argv[])
61 dc1394camera_t *camera;
62 dc1394framerate_t framerate = DC1394_FRAMERATE_15;
63 dc1394video_mode_t video_mode = DC1394_VIDEO_MODE_800x600_MONO8;
64 dc1394color_coding_t color_coding = DC1394_COLOR_CODING_MONO8;
65 dc1394video_frame_t *frame = NULL;
70 bool show_features =
false;
71 bool detect_video_mode =
true;
74 image_number = atoi(argv[1]);
75 if (image_number < 1) image_number = 1;
81 dc1394camera_list_t *list;
82 err = dc1394_camera_enumerate (dc, &list);
83 DC1394_ERR_RTN(err,
"Failed to enumerate cameras");
85 dc1394_log_error(
"No cameras found");
89 camera = dc1394_camera_new(dc, list->ids[0].guid);
91 dc1394_log_error(
"Failed to initialize camera with guid %d", (
int)list->ids[0].guid);
94 dc1394_camera_free_list(list);
96 cout <<
"Using camera with GUID " << camera->guid << endl;
101 if (detect_video_mode)
104 dc1394video_modes_t video_modes;
105 err = dc1394_video_get_supported_modes(camera, &video_modes);
106 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Can't get video modes");
109 bool found_mode =
false;
110 for (
int i = video_modes.num-1; i>= 0; i--) {
111 if (!dc1394_is_video_mode_scalable(video_modes.modes[i])) {
112 dc1394_get_color_coding_from_video_mode(camera, video_modes.modes[i], &color_coding);
113 if (color_coding == DC1394_COLOR_CODING_MONO8) {
114 video_mode = video_modes.modes[i];
121 dc1394_log_error(
"Could not get a valid MONO8 mode");
122 cleanup_and_exit(camera);
125 err = dc1394_get_color_coding_from_video_mode(camera, video_mode, &color_coding);
126 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not get color coding");
129 dc1394framerates_t framerates;
130 err = dc1394_video_get_supported_framerates(camera, video_mode, &framerates);
131 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not get framerates");
132 framerate = framerates.framerates[framerates.num-1];
139 if (color_coding != DC1394_COLOR_CODING_MONO8 &&
140 color_coding != DC1394_COLOR_CODING_RGB8) {
141 dc1394_log_error(
"Color coding has to be MONO8 or RGB8");
142 cleanup_and_exit(camera);
145 err = dc1394_video_set_iso_speed(camera, DC1394_ISO_SPEED_400);
146 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not set iso speed");
148 err = dc1394_video_set_mode(camera, video_mode);
149 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not set video mode");
151 err = dc1394_video_set_framerate(camera, framerate);
152 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not set framerate");
154 err = dc1394_capture_setup(camera, NUM_DMA_BUFFERS, DC1394_CAPTURE_FLAGS_DEFAULT);
155 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not setup camera\n"
156 "Make sure that the video mode and framerate are\n"
157 "supported by your camera");
163 dc1394featureset_t features;
164 err = dc1394_feature_get_all(camera, &features);
165 if (err != DC1394_SUCCESS) {
166 dc1394_log_warning(
"Could not get feature set");
169 dc1394_feature_print_all(&features, stdout);
176 unsigned int width, height;
178 dc1394_get_image_size_from_video_mode(camera, video_mode, &width, &height);
179 dc1394_framerate_as_float(framerate, &fps);
180 const bool grey_image = (color_coding == DC1394_COLOR_CODING_MONO8);
181 const unsigned int channels = (grey_image ? 1 : 3);
182 const unsigned int bytes = channels * width * height;
186 cout <<
"Starting capture with image size " << width <<
" x "
187 << height <<
" (" << (grey_image ?
"MONO8" :
"RGB8") <<
") with "
188 << fps <<
" frames/sec" << endl;
193 err = dc1394_video_set_transmission(camera, DC1394_ON);
194 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
195 "Could not start camera iso transmission");
197 for (
int image_no = 0; image_no < image_number; image_no++)
202 err = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
203 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not capture a frame");
205 memcpy(image.GetImageData(), frame->image, bytes);
212 sprintf(filename,
"image-%04d.%s", image_no, grey_image ?
"pgm" :
"ppm");
230 cout <<
"Wrote " << filename << endl << flush;
235 err = dc1394_capture_enqueue(camera, frame);
241 dc1394_video_set_transmission(camera, DC1394_OFF);
242 DC1394_ERR_CLN_RTN(err, cleanup_and_exit(camera),
"Could not stop the camera");
243 dc1394_capture_stop(camera);
244 dc1394_camera_free(camera);
247 cout <<
"Closed camera connection" << endl;
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.