24 #include <fvcams/bumblebee2.h> 26 #include <fvcams/cam_exceptions.h> 27 #include <core/exception.h> 28 #include <fvutils/system/camargp.h> 29 #include <fvutils/color/conversions.h> 36 # include <sys/endian.h> 37 #elif defined(__MACH__) && defined(__APPLE__) 38 # include <sys/_endian.h> 43 #include <utils/math/angle.h> 47 #include <dc1394/utils.h> 48 #include <dc1394/register.h> 49 #include <dc1394/conversions.h> 90 const unsigned int Bumblebee2Camera::ORIGINAL = 0;
93 const unsigned int Bumblebee2Camera::DEINTERLACED = 1;
96 const unsigned int Bumblebee2Camera::RGB_IMAGE = 2;
101 #define PGR_BAYER_TILE_MAPPING_REGISTER (0x1040) 103 #define PGR_SENSOR_BOARD_INFO_REGISTER (0x1f28) 106 #define PGR_REG_CONFIG_LENGTH (0x1FFC) 109 #define PGR_REG_CONFIG_DATA (0x2000) 112 #define PGR_REG_UNIT_DIRECTORY_OFFSET (0x0424) 115 #define PGR_REG_IMAGE_DATA_FORMAT (0x1048) 117 #define PTG_Y16_Data_Format_PGR_specific (0xFFFFFFFE) 120 #define PGR_REG_SERIAL_NUMBER (0x1F20) 135 DC1394_VIDEO_MODE_FORMAT7_3,
136 DC1394_ISO_SPEED_400,
141 _supports_color =
true;
142 _auto_acquire_sensor_info =
false;
151 if ( cap->
has(
"nbufs") ) {
154 if ( cap->
has(
"width") ) {
157 if ( cap->
has(
"height") ) {
160 if ( cap->
has(
"startx") ) {
163 if ( cap->
has(
"starty") ) {
166 if ( cap->
has(
"focus") ) {
169 if ( cap->
has(
"white_balance") ) {
172 if ( cap->
has(
"shutter") ) {
176 __buffer_deinterlaced = NULL;
186 DC1394_VIDEO_MODE_FORMAT7_3,
187 DC1394_ISO_SPEED_400,
190 _auto_acquire_sensor_info =
true;
192 _model = strdup(
"Bumblebee2");
203 if (__buffer_deinterlaced != NULL) free(__buffer_deinterlaced);
204 if (__buffer_rgb != NULL) free(__buffer_rgb);
217 dc1394error_t err = dc1394_get_control_register(
_camera, PGR_REG_SERIAL_NUMBER, &value );
218 if ( err != DC1394_SUCCESS ) {
219 throw Exception(
"Bumblebee2::serial_no: dc1394_get_control_register(PGR_REG_SERIAL_NUMBER) failed\n");
240 uint64_t tguid = ver_guid;
243 if ( tguid == 0xFFFFFFFF ) {
245 ver_guid &= 0xFFFFFFFF;
248 return (
guid() == ver_guid);
254 Bumblebee2Camera::get_sensor_info()
260 err = dc1394_get_control_register(
_camera, PGR_SENSOR_BOARD_INFO_REGISTER, &value );
261 if ( err != DC1394_SUCCESS )
263 throw Exception(
"Failed to read sensor borad info register");
266 unsigned char ucSensorInfo = 0xf & value;
268 switch( ucSensorInfo )
272 throw Exception(
"Illegal sensor board info detected!");
274 _supports_color =
true;
279 _supports_color =
false;
284 _supports_color =
true;
289 _supports_color =
false;
294 _supports_color =
true;
299 _supports_color =
false;
312 #if (defined(__WORDSIZE) && __WORDSIZE == 64) || (defined(LONG_BIT) && LONG_BIT == 64) 313 printf(
"GUID: 0x%016lx\n", (
long unsigned int)
guid());
315 printf(
"GUID: 0x%016llx\n",
guid());
324 dc1394camera_list_t *list;
326 if ( dc1394_camera_enumerate(
_dc1394, &list) != DC1394_SUCCESS ) {
327 throw Exception(
"Could not enumerate cameras");
332 for (
unsigned int i = 0; i < list->num; ++i) {
333 dc1394camera_t *tmpcam = dc1394_camera_new(
_dc1394, list->ids[i].guid);
334 if ( strncmp(
"Bumblebee2", tmpcam->model, strlen(
"Bumblebee2")) == 0) {
339 dc1394_camera_free(tmpcam);
355 if (_auto_acquire_sensor_info) {
362 throw Exception(
"Bumblebee2Camera::open: FirewireCamera::open dit not suceed");
369 #if __BYTE_ORDER == __LITTLE_ENDIAN 374 uint32_t presence : 1;
375 uint32_t reserved1 : 21;
377 uint32_t bayer_mono : 1;
378 uint32_t reserved2 : 7;
379 uint32_t data_format: 1;
383 err = dc1394_get_control_register(
_camera, PGR_REG_IMAGE_DATA_FORMAT, &(value.value) );
384 if ( err != DC1394_SUCCESS ) {
385 throw Exception(
"Bumblebee2::open: dc1394_get_control_register(PGR_REG_DATA_FORMAT) failed\n");
387 value.value &= PTG_Y16_Data_Format_PGR_specific;
388 value.idf.data_format = 0;
389 err = dc1394_set_control_register(
_camera, PGR_REG_IMAGE_DATA_FORMAT, value.value );
390 if ( err != DC1394_SUCCESS ) {
391 throw Exception(
"Bumblebee2::open: Setting PGR-specific mode on little-endian system failed\n");
404 if (__buffer_deinterlaced != NULL) {
405 free(__buffer_deinterlaced);
406 __buffer_deinterlaced = NULL;
408 if (__buffer_rgb != NULL) {
421 e.
append(
"Bumblebee2Camera::capture: failed to retrieve image");
422 if (
ORIGINAL == __image_num ) __buffer = NULL;
441 __image_num = image_num;
442 switch ( image_num ) {
443 case DEINTERLACED: __buffer = __buffer_deinterlaced;
break;
444 case RGB_IMAGE: __buffer = __buffer_rgb;
break;
445 default: __buffer = NULL;
break;
458 return( strncmp(
_camera->model,
"Bumblebee2", strlen(
"Bumblebee2") ) == 0);
466 dc1394_deinterlace_stereo(
_frame->image, __buffer_deinterlaced,
479 dc1394_bayer_decoding_8bit( __buffer_deinterlaced, __buffer_rgb,
481 __bayer_pattern, DC1394_BAYER_METHOD_NEAREST );
497 unsigned int width,
unsigned int height)
499 dc1394_deinterlace_stereo( raw16, deinterlaced, width, 2 * height );
520 unsigned int width,
unsigned int height,
521 bayer_pattern_t bayer_pattern)
523 dc1394color_filter_t dc_bayer_pattern;
525 switch (bayer_pattern) {
527 case BAYER_PATTERN_YYYY:
528 dc_bayer_pattern = (dc1394color_filter_t) 0;
530 case BAYER_PATTERN_RGGB:
531 dc_bayer_pattern = DC1394_COLOR_FILTER_RGGB;
533 case BAYER_PATTERN_GBRG:
534 dc_bayer_pattern = DC1394_COLOR_FILTER_GBRG;
536 case BAYER_PATTERN_GRBG:
537 dc_bayer_pattern = DC1394_COLOR_FILTER_GRBG;
539 case BAYER_PATTERN_BGGR:
540 dc_bayer_pattern = DC1394_COLOR_FILTER_BGGR;
544 dc1394_bayer_decoding_8bit( deinterlaced, rgb, width, 2 * height,
545 dc_bayer_pattern, DC1394_BAYER_METHOD_NEAREST );
554 Bumblebee2Camera::get_bayer_tile()
557 if (dc1394_get_control_register(
_camera, PGR_BAYER_TILE_MAPPING_REGISTER, &value) != DC1394_SUCCESS ) {
558 throw Exception(
"Could not query bayer tile register");
566 __bayer_pattern = (dc1394color_filter_t) 0;
569 __bayer_pattern = DC1394_COLOR_FILTER_RGGB;
572 __bayer_pattern = DC1394_COLOR_FILTER_GBRG;
575 __bayer_pattern = DC1394_COLOR_FILTER_GRBG;
578 __bayer_pattern = DC1394_COLOR_FILTER_BGGR;
597 err = dc1394_get_control_register(
_camera, PGR_REG_CONFIG_LENGTH, &value );
598 if ( err != DC1394_SUCCESS ) {
599 throw Exception(
"dc1394_get_control_register(PGR_REG_CONFIG_LENGTH) failed\n");
603 unsigned long file_size_bytes = value;
604 if( file_size_bytes == 0 ) {
608 FILE* file = fopen( filename,
"w" );
610 throw Exception(
"Can't open temporary file\n" );
615 for(
unsigned long offset = 0 ; offset < file_size_bytes; offset += 4 ) {
616 err = dc1394_get_control_register(
_camera,
617 PGR_REG_CONFIG_DATA + offset,
620 if( err != DC1394_SUCCESS ) {
621 Exception e(
"Failed to get control register");
622 e.
append(
"Can't get control register 0x%x\n",
623 (
int) (PGR_REG_CONFIG_DATA+offset) );
628 for(
int i = 24; i >= 0; i -= 8 ) {
629 fputc( ( (value>>i) & 0xFF ), file );
virtual ~Bumblebee2Camera()
Destructor.
bool _opened
true if camera has been opened, false otherwise
virtual void open()
Open the camera.
int _format7_width
Format7 width.
virtual unsigned int pixel_width()
Width of image in pixels.
virtual void parse_set_focus(const char *focus)
Parse focus and set value.
virtual void set_image_number(unsigned int image_num)
Set image number to retrieve.
static const unsigned int RGB_IMAGE
From bayer tile decoded RGB image.
virtual void print_info()
Print out camera information.
virtual unsigned int pixel_height()
Height of image in pixels.
static const unsigned int DEINTERLACED
Deinterlaced image.
void write_triclops_config_from_camera_to_file(const char *filename)
Retrieve config from camera.
Fawkes library namespace.
Capturing a frame failed.
void decode_bayer()
Extract RGB color image from the bayer tile image.
virtual void close()
Close camera.
virtual uint32_t serial_no() const
Get BB2 serial no.
std::string cam_id() const
Get camera ID.
dc1394video_frame_t * _frame
Last captured DC1394 video frame.
Camera not opened exception.
static const unsigned int ORIGINAL
Original image in RAW16.
virtual uint64_t guid() const
Get Firewire GUID of camera.
virtual void parse_set_white_balance(const char *white_balance)
Parse white balance and set value.
bool _device_opened
true if device has been opened, false otherwise
bool is_bumblebee2()
Check if connected camera is a Bumblebee2.
virtual void capture()
Capture an image.
bool has(std::string s) const
Check if an parameter was given.
virtual void parse_set_shutter(const char *shutter)
Parse shutter and set value.
Base class for exceptions in Fawkes.
virtual void print_info()
Print out camera information.
virtual void close()
Close camera.
char * _model
Camera model, used in open to identify the camera, if empty first found camera is used...
int _format7_height
Format7 height.
void deinterlace_stereo()
De-interlace the 16 bit data into 2 bayer tile pattern images.
dc1394color_coding_t _format7_coding
Format7 color coding.
virtual void open()
Open the camera.
dc1394camera_t * _camera
DC1394 camera handle.
virtual void capture()
Capture an image.
Bumblebee2Camera()
Constructor.
int _format7_startx
Format7 ROI Start X coordinate.
int _num_buffers
Number of DMA buffers.
std::string get(std::string s) const
Get the value of the given parameter.
virtual bool verify_guid(uint64_t ver_guid) const
Verify GUID validity.
dc1394_t * _dc1394
DC1394 main context.
void append(const char *format,...)
Append messages to the message list.
virtual void open_device()
Open the desired device.
virtual unsigned char * buffer()
Get access to current image buffer.
int _format7_starty
Format7 ROI Start Y coordinate.