From 977d2350dd7ca1838045ace0e4b15928c82dc478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergi=20Hern=C3=A0ndez=20Juan?= <shernand@iri.upc.edu> Date: Wed, 27 Mar 2013 10:27:56 +0000 Subject: [PATCH] Solved some bugs in the bumblebee driver. Added the possibility to change the framerate in the bumblebee camera. --- src/bumblebee.cpp | 48 +++++++++++++++++++++++---- src/bumblebee.h | 5 +++ src/examples/bumblebee.cpp | 12 ++++--- src/examples/firewire_camera_cont.cpp | 2 -- src/examples/ladybug.cpp | 2 +- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/bumblebee.cpp b/src/bumblebee.cpp index 27bcd0b..0ced744 100755 --- a/src/bumblebee.cpp +++ b/src/bumblebee.cpp @@ -44,6 +44,9 @@ void CBumblebee::set_config(unsigned int *left_off,unsigned int *top_off,unsigne uint64_t total_bytes; dc1394color_coding_t dc1394_coding; dc1394error_t error; + uint32_t min_bpp; + uint32_t max_bpp; + unsigned int bpp; // set the operation mode @@ -56,13 +59,36 @@ void CBumblebee::set_config(unsigned int *left_off,unsigned int *top_off,unsigne this->mode=DC1394_VIDEO_MODE_FORMAT7_3; // configure the camera if(coding==MONO) + { + this->coding=MONO; dc1394_coding=DC1394_COLOR_CODING_MONO16; + } else + { + this->coding=RAW; dc1394_coding=DC1394_COLOR_CODING_RAW16; + } + + // compute the desired frame rate + total_bytes=(*width)*(*height)*((int)DEPTH16/8); + error = dc1394_format7_get_packet_parameters(this->camera_handle,this->mode,&min_bpp,&max_bpp); + if ( error != DC1394_SUCCESS ) + { + DEBUG_INFO("failed.\n"); + /* handle the error */ + throw CFirewireInternalException(_HERE_,error); + } + bpp=(int)((*framerate)*total_bytes/(this->iso_rate*2)); + if(bpp<min_bpp || bpp>max_bpp) + { + DEBUG_INFO("failed.\n"); + /* handle exception */ + throw CFirewireCameraException(_HERE_,"Unsupported packet size. Please change the desired framerate."); + } error=dc1394_format7_set_roi(this->camera_handle, this->mode, dc1394_coding, - DC1394_USE_MAX_AVAIL, + bpp,//DC1394_USE_MAX_AVAIL, 0, 0, *width, @@ -72,12 +98,11 @@ void CBumblebee::set_config(unsigned int *left_off,unsigned int *top_off,unsigne // handle exceptions throw CFirewireInternalException(_HERE_,error); } - this->left_offset=*left_off; - this->top_offset=*top_off; + this->left_offset=0; + this->top_offset=0; this->width=*width; this->height=*height; - this->coding=coding; - this->depth=depth; + this->depth=DEPTH16; // compute the actual framerate error = dc1394_format7_get_total_bytes(this->camera_handle,this->mode,&total_bytes); if ( error != DC1394_SUCCESS ) @@ -97,6 +122,15 @@ void CBumblebee::set_config(unsigned int *left_off,unsigned int *top_off,unsigne this->set_num_DMA_buffers(4); } +void CBumblebee::get_stereo_config(unsigned int *width,unsigned int *height, float *framerate, depths_t *depth, codings_t *coding) +{ + (*width)=this->width; + (*height)=this->height; + (*framerate)=this->framerate; + (*depth)=this->stereo_depth; + (*coding)=this->stereo_coding; +} + void CBumblebee::get_stereo_image(char **left,char **right) { int depth; @@ -142,7 +176,7 @@ void CBumblebee::get_stereo_image(char **left,char **right) if(this->stereo_coding==RGB) { depth = (int)ceil((float)this->stereo_depth/8.0); - RGB_image=new unsigned char[this->width*this->height*depth]; + RGB_image=new unsigned char[this->width*2*this->height*depth]; // extract color from the bayer tile image // note: this will alias colors on the top and bottom rows dc1394_bayer_decoding_8bit( de_interleaved, @@ -197,7 +231,7 @@ void CBumblebee::get_stereo_image(char **left,char **right) if(this->stereo_coding==RGB) { depth = (int)ceil((float)this->stereo_depth/8.0); - RGB_image=new unsigned char[this->width*this->height*depth]; + RGB_image=new unsigned char[this->width*2*this->height*depth]; // extract color from the bayer tile image // note: this will alias colors on the top and bottom rows dc1394_bayer_decoding_8bit( de_interleaved, diff --git a/src/bumblebee.h b/src/bumblebee.h index d3663da..b7b9c59 100755 --- a/src/bumblebee.h +++ b/src/bumblebee.h @@ -34,6 +34,11 @@ class CBumblebee : public CPTGCamera */ void set_config(unsigned int *left_off,unsigned int *top_off,unsigned int *width,unsigned int *height, float *framerate, depths_t depth, codings_t coding); // stereo camera operation functions + /** + * \brief + * + */ + void get_stereo_config(unsigned int *width,unsigned int *height, float *framerate, depths_t *depth, codings_t *coding); /** * \brief * diff --git a/src/examples/bumblebee.cpp b/src/examples/bumblebee.cpp index afe0d15..982fc0f 100755 --- a/src/examples/bumblebee.cpp +++ b/src/examples/bumblebee.cpp @@ -7,7 +7,7 @@ #include <sstream> #include <iostream> -const int num_frames=100; +const int num_frames=10; int main(int argc, char *argv[]) { @@ -24,8 +24,7 @@ int main(int argc, char *argv[]) char *left=NULL,*right=NULL; std::string new_frame,filename; std::stringstream text; - uint64_t guid=0x0000b09d01006b6fb5; -// uint64_t guid=0x00B09D01007D6D85LL; + //uint64_t guid=0x0000b09d01006b6fb5; std::list<std::string> events; try @@ -36,13 +35,16 @@ int main(int argc, char *argv[]) server->init(); std::cout << "Num. Cam. : " << server->get_num_cameras() << std::endl; /* get the new camera with index 0 */ - /* get the new camera with guid = 0x00B09D01007D6D85 */ -// server->get_pgr_stereo_camera_guid(guid,&camera1); server->get_bumblebee_camera(0,&bumblebee); /* get the reference to the event server */ event_server=CEventServer::instance(); bumblebee->get_config(&left_off,&top_off,&width,&height,&framerate,&depth,&coding); + framerate=20; + bumblebee->set_config(&left_off,&top_off,&width,&height,&framerate,depth,coding); + bumblebee->get_stereo_config(&width,&height,&framerate,&depth,&coding); + std::cout << "Image size: " << width << "x" << height << std::endl; std::cout << "Fremerate: " << framerate << std::endl; + std::cout << "Color coding: " << (int)coding << "-" << (int)depth << std::endl; bumblebee->get_new_frame_event_id(new_frame); events.push_back(new_frame); bumblebee->start(); diff --git a/src/examples/firewire_camera_cont.cpp b/src/examples/firewire_camera_cont.cpp index 47c58cb..e8fca35 100644 --- a/src/examples/firewire_camera_cont.cpp +++ b/src/examples/firewire_camera_cont.cpp @@ -45,8 +45,6 @@ int main(int argc, char *argv[]) event_list.push_back(new_frame); /* configure the camera */ camera1->get_config(&left_off,&top_off,&width,&height,&framerate,&depth,&coding); - framerate=3.75; - height=4608; camera1->set_config(&left_off,&top_off,&width,&height,&framerate,depth,coding); std::cout << framerate << std::endl; /* start continuous acquisition */ diff --git a/src/examples/ladybug.cpp b/src/examples/ladybug.cpp index e047645..965fe9c 100755 --- a/src/examples/ladybug.cpp +++ b/src/examples/ladybug.cpp @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) ladybug->get_config(&left_off,&top_off,&width,&height,&framerate,&depth,&coding); std::cout << "Fremerate: " << framerate << std::endl; // coding=MONO; - framerate=30; + framerate=10; ladybug->set_config(&left_off,&top_off,&width,&height,&framerate,depth,coding); ladybug->get_new_frame_event_id(new_frame); events.push_back(new_frame); -- GitLab