60 dc1394video_mode_t mode,
68 roi_.x_offset = newconfig.x_offset;
69 roi_.y_offset = newconfig.y_offset;
70 roi_.width = newconfig.roi_width;
71 roi_.height = newconfig.roi_height;
73 uint32_t packet_size = newconfig.format7_packet_size;
77 if (newconfig.bayer_method !=
"")
80 <<
"] not supported for Format7 modes." 81 <<
" Using image_proc instead.");
82 newconfig.bayer_method =
"";
85 const char* pattern = newconfig.bayer_pattern.c_str();
87 if ((bayer_pattern >= DC1394_COLOR_FILTER_MIN)
88 && (bayer_pattern <= DC1394_COLOR_FILTER_MAX))
95 << bayer_pattern <<
")] is invalid.");
100 uint32_t sensor_width = 0, sensor_height = 0;
102 for (
int scan_mode = DC1394_VIDEO_MODE_FORMAT7_MIN;
103 scan_mode <= DC1394_VIDEO_MODE_FORMAT7_MAX;
106 uint32_t scan_width, scan_height;
109 if (dc1394_format7_get_max_image_size(camera,
110 (dc1394video_mode_t) scan_mode,
111 &scan_width, &scan_height)
115 if (scan_width > sensor_width)
116 sensor_width = scan_width;
118 if (scan_height > sensor_height)
119 sensor_height = scan_height;
122 if (DC1394_SUCCESS != dc1394_format7_get_max_image_size(camera, mode,
126 ROS_ERROR(
"Could not get max image size");
130 if (newconfig.binning_x == 0 || newconfig.binning_y == 0)
150 uint32_t unit_w, unit_h, unit_x, unit_y;
152 if (DC1394_SUCCESS != dc1394_format7_get_unit_size(camera, mode,
155 ROS_ERROR(
"Could not get ROI size units");
162 if (DC1394_SUCCESS != dc1394_format7_get_unit_position(camera, mode,
165 ROS_ERROR(
"Could not get ROI position units");
170 if (unit_x == 0) unit_x = 1;
171 if (unit_y == 0) unit_y = 1;
177 << unit_w <<
"x" << unit_h
179 << unit_x <<
"x" << unit_y
184 <<
roi_.x_offset <<
", " <<
roi_.y_offset
191 dc1394_format7_set_image_position(camera, mode, 0, 0);
193 if ((
roi_.width % unit_w) || (
roi_.height % unit_h))
196 ROS_ERROR(
"Requested image size invalid; (w,h) must be" 197 " a multiple of (%d, %d)", unit_w, unit_h);
207 if (DC1394_SUCCESS != dc1394_format7_set_image_size(camera, mode,
215 if ((
roi_.x_offset % unit_x) || (
roi_.y_offset % unit_y))
217 ROS_ERROR(
"Requested image position invalid; (x,y) must" 218 " be a multiple of (%d, %d)", unit_x, unit_y);
222 if (DC1394_SUCCESS != dc1394_format7_set_image_position(camera, mode,
226 ROS_ERROR(
"Could not set position of ROI");
233 newconfig.format7_color_coding);
235 if (DC1394_SUCCESS != dc1394_format7_set_color_coding(camera, mode,
242 uint32_t rec_packet_size;
245 != dc1394_format7_get_recommended_packet_size(camera, mode,
248 ROS_ERROR(
"Could not get default packet size");
252 if (0 == packet_size)
253 packet_size = rec_packet_size;
255 uint32_t unit_bytes, max_bytes;
258 != dc1394_format7_get_packet_parameters(camera, mode,
259 &unit_bytes, &max_bytes))
261 ROS_ERROR(
"Could not determine maximum and increment for packet size");
265 if (packet_size % unit_bytes
266 || (max_bytes > 0 && packet_size > max_bytes))
268 ROS_ERROR(
"Invalid packet size: %d. Must be a " 269 "multiple of %d, at most %d [%d]",
270 packet_size, unit_bytes, max_bytes, rec_packet_size);
274 if (DC1394_SUCCESS != dc1394_format7_set_packet_size(camera, mode,
281 if (
coding_ == DC1394_COLOR_CODING_RAW8
282 ||
coding_ == DC1394_COLOR_CODING_RAW16)
285 color_filter = (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM;
286 if (DC1394_SUCCESS != dc1394_format7_get_color_filter(camera, mode,
289 ROS_ERROR(
"Could not determine color pattern");
292 if (
BayerPattern_ == (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM)
315 extern std::string
bayer_string(dc1394color_filter_t pattern,
324 case DC1394_COLOR_CODING_MONO8:
325 image.step = image.width;
326 image_size = image.height * image.step;
328 image.is_bigendian =
false;
329 image.data.resize(image_size);
330 memcpy(&image.data[0], capture_buffer, image_size);
332 case DC1394_COLOR_CODING_YUV411:
333 image.step = image.width * 3;
334 image_size = image.height * image.step;
336 image.data.resize(image_size);
338 reinterpret_cast<unsigned char *> (&image.data[0]),
339 image.width * image.height);
341 case DC1394_COLOR_CODING_YUV422:
342 image.step = image.width * 3;
343 image_size = image.height * image.step;
345 image.data.resize(image_size);
346 yuv::uyvy2rgb(reinterpret_cast<unsigned char *> (capture_buffer),
347 reinterpret_cast<unsigned char *> (&image.data[0]),
348 image.width * image.height);
350 case DC1394_COLOR_CODING_YUV444:
351 image.step=image.width * 3;
352 image_size = image.height * image.step;
354 image.data.resize(image_size);
355 yuv::uyv2rgb(reinterpret_cast<unsigned char *> (capture_buffer),
356 reinterpret_cast<unsigned char *> (&image.data[0]),
357 image.width * image.height);
359 case DC1394_COLOR_CODING_RGB8:
360 image.step=image.width*3;
361 image_size = image.height*image.step;
363 image.data.resize(image_size);
364 memcpy(&image.data[0], capture_buffer, image_size);
366 case DC1394_COLOR_CODING_MONO16:
367 image.step=image.width*2;
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_RGB16:
375 image.step = image.width * 6;
376 image_size = image.height * image.step;
378 image.is_bigendian =
true;
379 image.data.resize(image_size);
380 memcpy(&image.data[0], capture_buffer, image_size);
382 case DC1394_COLOR_CODING_MONO16S:
383 image.step = image.width * 2;
384 image_size = image.height * image.step;
386 image.is_bigendian =
true;
387 image.data.resize(image_size);
388 memcpy(&image.data[0], capture_buffer, image_size);
390 case DC1394_COLOR_CODING_RGB16S:
391 image.step = image.width * 6;
392 image_size = image.height * image.step;
394 image.is_bigendian =
true;
395 image.data.resize(image_size);
396 memcpy(&image.data[0], capture_buffer, image_size);
398 case DC1394_COLOR_CODING_RAW8:
399 image.step = image.width;
400 image_size = image.height * image.step;
402 image.data.resize(image_size);
403 memcpy(&image.data[0], capture_buffer, image_size);
405 case DC1394_COLOR_CODING_RAW16:
406 image.step = image.width * 2;
407 image_size = image.height * image.step;
409 image.is_bigendian =
true;
410 image.data.resize(image_size);
411 memcpy(&image.data[0], capture_buffer, image_size);
438 else if (cinfo.width ==
roi_.width && cinfo.height ==
roi_.height)
445 << cinfo.width <<
"x" << cinfo.height
446 <<
") matches neither full Format7 size (" 448 <<
") nor ROI size (" 449 <<
roi_.width <<
"x" <<
roi_.height <<
")");
472 cinfo.roi.do_rectify =
false;
474 if (cinfo.K[0] == 0.0)
477 bool roiMatchesCalibration = (cinfo.width ==
roi_.width
478 && cinfo.height ==
roi_.height);
483 if (!roiMatchesCalibration)
486 cinfo.roi.do_rectify =
true;
492 if (!roiMatchesCalibration)
496 cinfo.roi.do_rectify =
true;
512 pattern = (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM;
514 if (0 == strcmp(bayer,
"bggr"))
516 pattern = DC1394_COLOR_FILTER_BGGR;
518 else if (0 == strcmp(bayer,
"grbg"))
520 pattern = DC1394_COLOR_FILTER_GRBG;
522 else if (0 == strcmp(bayer,
"rggb"))
524 pattern = DC1394_COLOR_FILTER_RGGB;
526 else if (0 == strcmp(bayer,
"gbrg"))
528 pattern = DC1394_COLOR_FILTER_GBRG;
530 else if (0 != strcmp(bayer,
""))
532 ROS_ERROR(
"unknown bayer pattern [%s]", bayer);
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
#define ROS_WARN_STREAM(args)
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)
camera1394::Camera1394Config Config
#define ROS_ERROR_STREAM(args)
void uyv2rgb(const unsigned char *src, unsigned char *dest, unsigned long long int NumPixels)
const std::string TYPE_16SC1