59 dc1394video_mode_t mode,
67 roi_.x_offset = newconfig.x_offset;
68 roi_.y_offset = newconfig.y_offset;
69 roi_.width = newconfig.roi_width;
70 roi_.height = newconfig.roi_height;
72 uint32_t packet_size = newconfig.format7_packet_size;
89 uint32_t sensor_width = 0, sensor_height = 0;
91 for (
int scan_mode = DC1394_VIDEO_MODE_FORMAT7_MIN;
92 scan_mode <= DC1394_VIDEO_MODE_FORMAT7_MAX;
95 uint32_t scan_width, scan_height;
98 if (dc1394_format7_get_max_image_size(camera,
99 (dc1394video_mode_t) scan_mode,
100 &scan_width, &scan_height)
104 if (scan_width > sensor_width)
105 sensor_width = scan_width;
107 if (scan_height > sensor_height)
108 sensor_height = scan_height;
111 if (DC1394_SUCCESS != dc1394_format7_get_max_image_size(camera, mode,
115 ROS_ERROR(
"Could not get max image size");
119 if (newconfig.binning_x == 0 || newconfig.binning_y == 0)
139 uint32_t unit_w, unit_h, unit_x, unit_y;
141 if (DC1394_SUCCESS != dc1394_format7_get_unit_size(camera, mode,
144 ROS_ERROR(
"Could not get ROI size units");
151 if (DC1394_SUCCESS != dc1394_format7_get_unit_position(camera, mode,
154 ROS_ERROR(
"Could not get ROI position units");
159 if (unit_x == 0) unit_x = 1;
160 if (unit_y == 0) unit_y = 1;
166 << unit_w <<
"x" << unit_h
168 << unit_x <<
"x" << unit_y
173 <<
roi_.x_offset <<
", " <<
roi_.y_offset
180 dc1394_format7_set_image_position(camera, mode, 0, 0);
182 if ((
roi_.width % unit_w) || (
roi_.height % unit_h))
185 ROS_ERROR(
"Requested image size invalid; (w,h) must be" 186 " a multiple of (%d, %d)", unit_w, unit_h);
196 if (DC1394_SUCCESS != dc1394_format7_set_image_size(camera, mode,
204 if ((
roi_.x_offset % unit_x) || (
roi_.y_offset % unit_y))
206 ROS_ERROR(
"Requested image position invalid; (x,y) must" 207 " be a multiple of (%d, %d)", unit_x, unit_y);
211 if (DC1394_SUCCESS != dc1394_format7_set_image_position(camera, mode,
215 ROS_ERROR(
"Could not set position of ROI");
222 newconfig.format7_color_coding);
224 if (DC1394_SUCCESS != dc1394_format7_set_color_coding(camera, mode,
231 uint32_t rec_packet_size;
234 != dc1394_format7_get_recommended_packet_size(camera, mode,
237 ROS_ERROR(
"Could not get default packet size");
241 if (0 == packet_size)
242 packet_size = rec_packet_size;
244 uint32_t unit_bytes, max_bytes;
247 != dc1394_format7_get_packet_parameters(camera, mode,
248 &unit_bytes, &max_bytes))
250 ROS_ERROR(
"Could not determine maximum and increment for packet size");
254 if (packet_size % unit_bytes
255 || (max_bytes > 0 && packet_size > max_bytes))
257 ROS_ERROR(
"Invalid packet size: %d. Must be a " 258 "multiple of %d, at most %d [%d]",
259 packet_size, unit_bytes, max_bytes, rec_packet_size);
263 if (DC1394_SUCCESS != dc1394_format7_set_packet_size(camera, mode,
270 if (
coding_ == DC1394_COLOR_CODING_RAW8
271 ||
coding_ == DC1394_COLOR_CODING_RAW16)
273 if (DC1394_SUCCESS != dc1394_format7_get_color_filter(camera, mode,
276 ROS_ERROR(
"Could not determine color pattern");
292 extern std::string
bayer_string(dc1394color_filter_t pattern,
unsigned int bits);
300 case DC1394_COLOR_CODING_MONO8:
301 image.step = image.width;
302 image_size = image.height * image.step;
304 image.is_bigendian =
false;
305 image.data.resize(image_size);
306 memcpy(&image.data[0], capture_buffer, image_size);
308 case DC1394_COLOR_CODING_YUV411:
309 image.step = image.width * 3;
310 image_size = image.height * image.step;
312 image.data.resize(image_size);
314 reinterpret_cast<unsigned char *> (&image.data[0]),
315 image.width * image.height);
317 case DC1394_COLOR_CODING_YUV422:
318 image.step = image.width * 3;
319 image_size = image.height * image.step;
321 image.data.resize(image_size);
322 yuv::uyvy2rgb(reinterpret_cast<unsigned char *> (capture_buffer),
323 reinterpret_cast<unsigned char *> (&image.data[0]),
324 image.width * image.height);
326 case DC1394_COLOR_CODING_YUV444:
327 image.step=image.width * 3;
328 image_size = image.height * image.step;
330 image.data.resize(image_size);
331 yuv::uyv2rgb(reinterpret_cast<unsigned char *> (capture_buffer),
332 reinterpret_cast<unsigned char *> (&image.data[0]),
333 image.width * image.height);
335 case DC1394_COLOR_CODING_RGB8:
336 image.step=image.width*3;
337 image_size = image.height*image.step;
339 image.data.resize(image_size);
340 memcpy(&image.data[0], capture_buffer, image_size);
342 case DC1394_COLOR_CODING_MONO16:
343 image.step=image.width*2;
344 image_size = image.height*image.step;
346 image.is_bigendian =
true;
347 image.data.resize(image_size);
348 memcpy(&image.data[0], capture_buffer, image_size);
350 case DC1394_COLOR_CODING_RGB16:
351 image.step = image.width * 6;
352 image_size = image.height * image.step;
354 image.is_bigendian =
true;
355 image.data.resize(image_size);
356 memcpy(&image.data[0], capture_buffer, image_size);
358 case DC1394_COLOR_CODING_MONO16S:
359 image.step = image.width * 2;
360 image_size = image.height * image.step;
362 image.is_bigendian =
true;
363 image.data.resize(image_size);
364 memcpy(&image.data[0], capture_buffer, image_size);
366 case DC1394_COLOR_CODING_RGB16S:
367 image.step = image.width * 6;
368 image_size = image.height * image.step;
370 image.is_bigendian =
true;
371 image.data.resize(image_size);
372 memcpy(&image.data[0], capture_buffer, image_size);
374 case DC1394_COLOR_CODING_RAW8:
375 image.step = image.width;
376 image_size = image.height * image.step;
378 image.data.resize(image_size);
379 memcpy(&image.data[0], capture_buffer, image_size);
381 case DC1394_COLOR_CODING_RAW16:
382 image.step = image.width * 2;
383 image_size = image.height * image.step;
385 image.is_bigendian =
true;
386 image.data.resize(image_size);
387 memcpy(&image.data[0], capture_buffer, image_size);
414 else if (cinfo.width ==
roi_.width && cinfo.height ==
roi_.height)
421 << cinfo.width <<
"x" << cinfo.height
422 <<
") matches neither full Format7 size (" 424 <<
") nor ROI size (" 425 <<
roi_.width <<
"x" <<
roi_.height <<
")");
448 cinfo.roi.do_rectify =
false;
450 if (cinfo.K[0] == 0.0)
453 bool roiMatchesCalibration = (cinfo.width ==
roi_.width
454 && cinfo.height ==
roi_.height);
459 if (!roiMatchesCalibration)
462 cinfo.roi.do_rectify =
true;
468 if (!roiMatchesCalibration)
472 cinfo.roi.do_rectify =
true;
camera1394stereo::Camera1394StereoConfig Config
libdc1394 enumerated modes interface
void uyvy2rgb(unsigned char *src, unsigned char *dest, unsigned long long int NumPixels)
dc1394color_coding_t getColorCoding(dc1394camera_t *camera, dc1394video_mode_t video_mode, std::string &color_coding)
YUV to RGB conversion functions.
const std::string TYPE_16SC3
const std::string TYPE_16UC3
#define ROS_WARN_STREAM_THROTTLE(rate, args)
#define ROS_INFO_STREAM(args)
void uyyvyy2rgb(const unsigned char *src, unsigned char *dest, unsigned long long int NumPixels)
#define ROS_ERROR_STREAM(args)
void uyv2rgb(const unsigned char *src, unsigned char *dest, unsigned long long int NumPixels)
const std::string TYPE_16SC1