From: <tum...@li...> - 2012-01-31 16:56:49
|
Revision: 987 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=987&view=rev Author: moesenle Date: 2012-01-31 16:56:40 +0000 (Tue, 31 Jan 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 17:55:00 2012 +0100 commit 0b6c0c9cb2a8e0f40e1b195cc0ae1472185c591a Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 17:54:39 2012 +0100 got rid of static functions (thx Lorenz) commit 4810db7739748ed8a5f4750d6a992fbaa4fb6a6e Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 13:04:23 2012 +0100 different default topic commit e73893c803108e9e9dc500fa1e77667da40da120 Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 12:07:05 2012 +0100 public export git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/launch/barcode_reader.launch perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp Modified: perception/zbar_barcode_reader_node/launch/barcode_reader.launch =================================================================== --- perception/zbar_barcode_reader_node/launch/barcode_reader.launch 2012-01-31 11:07:48 UTC (rev 986) +++ perception/zbar_barcode_reader_node/launch/barcode_reader.launch 2012-01-31 16:56:40 UTC (rev 987) @@ -1,5 +1,5 @@ <launch> <node pkg="zbar_barcode_reader_node" type="zbar_barcode_reader_node" name="barcode_reader_node" output="screen" respawn="true"> - <param name="input_image_topic" type="string" value="/image_topic_2" /> + <param name="input_image_topic" type="string" value="/image_raw" /> </node> </launch> Modified: perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-01-31 11:07:48 UTC (rev 986) +++ perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-01-31 16:56:40 UTC (rev 987) @@ -21,64 +21,21 @@ using namespace std; using namespace zbar; - static int writer(char *data, size_t size, size_t nmemb, - std::string *buffer) - { - // What we will return - int result = 0; - - // Is there anything in the buffer? - if (buffer != NULL) - { - // Append the data to the buffer - buffer->append(data, size * nmemb); - - // How much did we write? - result = size * nmemb; - } - - return result; - } - -static void* CURL_realloc(void *ptr, size_t size) -{ - /* There might be a realloc() out there that doesn't like reallocing - NULL pointers, so we take care of it here */ - if(ptr) - return realloc(ptr, size); - else - return malloc(size); -} - -struct memoryStruct { - char *memory; - size_t size; -}; - - size_t WriteMemoryCallback - (void *ptr, size_t size, size_t nmemb, void *data) - { - size_t realsize = size * nmemb; - struct memoryStruct *mem = (struct memoryStruct *)data; - - mem->memory = (char *) - CURL_realloc(mem->memory, mem->size + realsize + 1); - if (mem->memory) { - memcpy(&(mem->memory[mem->size]), ptr, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - } - return realsize; - } - - class BarcodeReaderNode { - // struct memoryStruct { - // char *memory; - // size_t size; - // }; public: + struct memoryStruct { + char *memory; + size_t size; + }; + + struct UserData { + memoryStruct *memory; + BarcodeReaderNode *self; + UserData(memoryStruct *memory, BarcodeReaderNode *self) + : memory(memory), self(self) {} + }; + BarcodeReaderNode(ros::NodeHandle &n) : n_(n), it_(n_) { @@ -86,63 +43,70 @@ n_.param ("outout_barcode_topic", output_barcode_topic_, std::string("barcode")); image_sub_ = it_.subscribe( input_image_topic_, 1, &BarcodeReaderNode::imageCallback, this); - barcode_pub_ = n_.advertise<std_msgs::String>(output_barcode_topic_, 1); + barcode_pub_ = + n_.advertise<std_msgs::String>(output_barcode_topic_, 1); + cv::namedWindow ("Barcoo img"); } ~BarcodeReaderNode() { - + cv::destroyAllWindows(); } - // void* CURL_realloc(void *ptr, size_t size) - // { - // /* There might be a realloc() out there that doesn't like reallocing - // NULL pointers, so we take care of it here */ - // if(ptr) - // return realloc(ptr, size); - // else - // return malloc(size); - // } + static void* CURL_realloc(void *ptr, size_t size) + { + /* There might be a realloc() out there that doesn't like reallocing + NULL pointers, so we take care of it here */ + if(ptr) + return realloc(ptr, size); + else + return malloc(size); + } - // size_t WriteMemoryCallback - // (void *ptr, size_t size, size_t nmemb, void *data) - // { - // size_t realsize = size * nmemb; - // struct memoryStruct *mem = (struct memoryStruct *)data; + static size_t WriteMemoryCallback + (void *ptr, size_t size, size_t nmemb, void *data) + { + UserData *userdata = reinterpret_cast<UserData *>(data); + struct memoryStruct *mem = userdata->memory; + BarcodeReaderNode *self = userdata->self; + size_t realsize = size * nmemb; - // mem->memory = (char *) - // CURL_realloc(mem->memory, mem->size + realsize + 1); - // if (mem->memory) { - // memcpy(&(mem->memory[mem->size]), ptr, realsize); - // mem->size += realsize; - // mem->memory[mem->size] = 0; - // } - // return realsize; - // } + mem->memory = (char *) + CURL_realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory) { + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + return realsize; + } + // This is the writer call back function used by curl - // int writer(char *data, size_t size, size_t nmemb, - // std::string *buffer) - // { - // // What we will return - // int result = 0; - - // // Is there anything in the buffer? - // if (buffer != NULL) - // { - // // Append the data to the buffer - // buffer->append(data, size * nmemb); - - // // How much did we write? - // result = size * nmemb; - // } - - // return result; - // } + static int writer(char *data, size_t size, size_t nmemb, + std::string *buffer) + { + // What we will return + int result = 0; + + // Is there anything in the buffer? + if (buffer != NULL) + { + // Append the data to the buffer + buffer->append(data, size * nmemb); + + // How much did we write? + result = size * nmemb; + } + + return result; + } + int getImage(std::string & image) { CURL *curl; // CURL objects CURLcode res; cv::Mat imgTmp; // image object memoryStruct buffer; // memory buffer + UserData userdata(&buffer, this); curl = curl_easy_init(); // init CURL library object/structure @@ -159,8 +123,8 @@ // tell libcurl where to write the image (to a dynamic memory buffer) - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, WriteMemoryCallback); - curl_easy_setopt(curl,CURLOPT_WRITEDATA, (void *) &buffer); + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, &BarcodeReaderNode::WriteMemoryCallback); + curl_easy_setopt(curl,CURLOPT_WRITEDATA, (void *) &userdata); // get the image from the specified URL res = curl_easy_perform(curl); @@ -171,7 +135,7 @@ if (!(imgTmp.empty())) { - imshow("Image from URL", imgTmp); + imshow("Barcoo img", imgTmp); } cv::waitKey(3); @@ -247,8 +211,8 @@ curl_easy_setopt(curl, CURLOPT_URL, full_url.c_str()); curl_easy_setopt(curl, CURLOPT_HEADER, 0); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &BarcodeReaderNode::writer); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &BarcodeReaderNode::writer); + // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); // Attempt to retrieve the remote page This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |