From: <tum...@li...> - 2012-01-27 18:37:06
|
Revision: 984 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=984&view=rev Author: moesenle Date: 2012-01-27 18:36:55 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@gm...> Date: Fri Jan 27 19:36:01 2012 +0100 commit 260b7704746b8185e64e3ccb0284ec3054176ff2 Author: Dejan Pangercic <dej...@gm...> Date: Fri Jan 27 19:34:40 2012 +0100 zbar compiled w/o video support, cpp example of zbar client commit 60392bba300cd3b7908678100b1645ff182ef8d1 Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 22:04:18 2010 +0200 public export commit 24765aef5f57c082d078c5b599947ed71d0c8437 Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 22:02:29 2010 +0200 added a launch file commit c358c7210ee1c53d032b34118fb84b15c35b9c68 Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 21:59:21 2010 +0200 created a node for barcode reading, input: image output: type,value exchanged c for c++ interface tested TODO: find a n..... that will port to cop:-) commit 0fd52914acf001cc75df60a84dffc0395a2e769b Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 21:24:21 2010 +0200 c++ implementation of zbar commit 1c567129b5432e62765bd0e87f1bc18f2a126bd2 Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 21:23:38 2010 +0200 added dependency git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/CMakeLists.txt Added Paths: ----------- perception/zbar_barcode_reader_node/src/scan_image.cpp Modified: perception/zbar_barcode_reader_node/CMakeLists.txt =================================================================== --- perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-27 18:36:44 UTC (rev 983) +++ perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-27 18:36:55 UTC (rev 984) @@ -31,5 +31,8 @@ rosbuild_add_executable(zbar_barcode_reader src/zbar_barcode_reader.c) target_link_libraries(zbar_barcode_reader MagickWand MagickCore) +rosbuild_add_executable(zbar_barcode_reader_cpp src/scan_image.cpp) +target_link_libraries(zbar_barcode_reader_cpp MagickWand MagickCore Magick++) + rosbuild_add_executable(zbar_barcode_reader_node src/zbar_barcode_reader_node.cpp) target_link_libraries(zbar_barcode_reader_node Magick++) \ No newline at end of file Added: perception/zbar_barcode_reader_node/src/scan_image.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/scan_image.cpp (rev 0) +++ perception/zbar_barcode_reader_node/src/scan_image.cpp 2012-01-27 18:36:55 UTC (rev 984) @@ -0,0 +1,54 @@ +#include <iostream> +#include <Magick++.h> +#include <zbar.h> +#define STR(s) #s + +using namespace std; +using namespace zbar; + +int main (int argc, char **argv) +{ + if(argc < 2) return(1); + +#ifdef MAGICK_HOME + // http://www.imagemagick.org/Magick++/ + // under Windows it is necessary to initialize the ImageMagick + // library prior to using the Magick++ library + Magick::InitializeMagick(MAGICK_HOME); +#endif + + // create a reader + ImageScanner scanner; + + // configure the reader + scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + + // obtain image data + Magick::Image magick(argv[1]); // read an image file + int width = magick.columns(); // extract dimensions + int height = magick.rows(); + Magick::Blob blob; // extract the raw data + magick.modifyImage(); + magick.write(&blob, "GRAY", 8); + const void *raw = blob.data(); + + // wrap image data + Image image(width, height, "Y800", raw, width * height); + + // scan the image for barcodes + int n = scanner.scan(image); + + // extract results + for(Image::SymbolIterator symbol = image.symbol_begin(); + symbol != image.symbol_end(); + ++symbol) { + // do something useful with results + cout << "decoded " << symbol->get_type_name() + << " symbol \"" << symbol->get_data() << '"' << endl; + } + + // clean up + image.set_data(NULL, 0); + + return(0); +} Property changes on: perception/zbar_barcode_reader_node/src/scan_image.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tum...@li...> - 2012-01-30 20:53:15
|
Revision: 985 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=985&view=rev Author: moesenle Date: 2012-01-30 20:53:08 +0000 (Mon, 30 Jan 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:49:26 2012 +0100 commit 7d2243e92e66feb8b1f48eab599384708ffa3da7 Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:48:26 2012 +0100 object recognition using barcoo working, major refactoring of the barcode_reader_node.zpp needed commit 73c93f2f13c5445cfc3955773a323c5e98deada8 Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:47:14 2012 +0100 examples for tinyxml and loading of images with curl and opencv commit c358c7210ee1c53d032b34118fb84b15c35b9c68 Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 21:59:21 2010 +0200 created a node for barcode reading, input: image output: type,value exchanged c for c++ interface tested TODO: find a n..... that will port to cop:-) commit 0fd52914acf001cc75df60a84dffc0395a2e769b Author: Dejan Pangercic <dej...@cs...> Date: Sun Aug 29 21:24:21 2010 +0200 c++ implementation of zbar git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/CMakeLists.txt perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp Added Paths: ----------- perception/zbar_barcode_reader_node/src/curl_opencv.cpp perception/zbar_barcode_reader_node/src/tinyxml.cpp Modified: perception/zbar_barcode_reader_node/CMakeLists.txt =================================================================== --- perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-27 18:36:55 UTC (rev 984) +++ perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-30 20:53:08 UTC (rev 985) @@ -32,7 +32,13 @@ target_link_libraries(zbar_barcode_reader MagickWand MagickCore) rosbuild_add_executable(zbar_barcode_reader_cpp src/scan_image.cpp) -target_link_libraries(zbar_barcode_reader_cpp MagickWand MagickCore Magick++) +target_link_libraries(zbar_barcode_reader_cpp MagickWand MagickCore Magick++ curl) rosbuild_add_executable(zbar_barcode_reader_node src/zbar_barcode_reader_node.cpp) -target_link_libraries(zbar_barcode_reader_node Magick++) \ No newline at end of file +target_link_libraries(zbar_barcode_reader_node Magick++ curl) + +# rosbuild_add_executable(test_tinyxml src/tinyxml.cpp) +# target_link_libraries(test_tinyxml tinyxml) + +# rosbuild_add_executable(curl_opencv src/curl_opencv.cpp) +# target_link_libraries(curl_opencv curl) Added: perception/zbar_barcode_reader_node/src/curl_opencv.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/curl_opencv.cpp (rev 0) +++ perception/zbar_barcode_reader_node/src/curl_opencv.cpp 2012-01-30 20:53:08 UTC (rev 985) @@ -0,0 +1,95 @@ +#include <stdio.h> +#include <curl/curl.h> + +#include <cv.h> +#include <highgui.h> +using namespace cv; + +// ***************************************************************************** + +struct memoryStruct { + char *memory; + size_t 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; + + 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; +} + +// ***************************************************************************** + +int main(void) +{ + CURL *curl; // CURL objects + CURLcode res; + cv::Mat imgTmp; // image object + memoryStruct buffer; // memory buffer + + curl = curl_easy_init(); // init CURL library object/structure + + if(curl) { + + // set up the write to memory buffer + // (buffer starts off empty) + + buffer.memory = NULL; + buffer.size = 0; + + // (N.B. check this URL still works in browser in case image has moved) + + curl_easy_setopt(curl, CURLOPT_URL, "http://www.froodies.de/FroodiesImages/images/products/large/29278.jpg"); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // tell us what is happening + + // 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); + + // get the image from the specified URL + + res = curl_easy_perform(curl); + + // decode memory buffer using OpenCV + + imgTmp = cv::imdecode(cv::Mat(1, buffer.size, CV_8UC1, buffer.memory), CV_LOAD_IMAGE_UNCHANGED); + + // display image (if we got / decoded it correctly) + + namedWindow("Image from URL", CV_WINDOW_AUTOSIZE); + if (!(imgTmp.empty())) + { + imshow("Image from URL", imgTmp); + } + waitKey(0); + + + // always cleanup + + curl_easy_cleanup(curl); + free(buffer.memory); + + } + return 0; +} Property changes on: perception/zbar_barcode_reader_node/src/curl_opencv.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: perception/zbar_barcode_reader_node/src/tinyxml.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/tinyxml.cpp (rev 0) +++ perception/zbar_barcode_reader_node/src/tinyxml.cpp 2012-01-30 20:53:08 UTC (rev 985) @@ -0,0 +1,146 @@ +// tutorial demo program +//#include "stdafx.h" +#include "tinyxml.h" + +// ---------------------------------------------------------------------- +// STDOUT dump and indenting utility functions +// ---------------------------------------------------------------------- +const unsigned int NUM_INDENTS_PER_SPACE=2; + +const char * getIndent( unsigned int numIndents ) +{ + static const char * pINDENT=" + "; + static const unsigned int LENGTH=strlen( pINDENT ); + unsigned int n=numIndents*NUM_INDENTS_PER_SPACE; + if ( n > LENGTH ) n = LENGTH; + + return &pINDENT[ LENGTH-n ]; +} + +// same as getIndent but no "+" at the end +const char * getIndentAlt( unsigned int numIndents ) +{ + static const char * pINDENT=" "; + static const unsigned int LENGTH=strlen( pINDENT ); + unsigned int n=numIndents*NUM_INDENTS_PER_SPACE; + if ( n > LENGTH ) n = LENGTH; + + return &pINDENT[ LENGTH-n ]; +} + +int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent) +{ + if ( !pElement ) return 0; + + TiXmlAttribute* pAttrib=pElement->FirstAttribute(); + int i=0; + int ival; + double dval; + const char* pIndent=getIndent(indent); + printf("\n"); + while (pAttrib) + { + printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value()); + + if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS) printf( " int=%d", ival); + if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval); + printf( "\n" ); + i++; + pAttrib=pAttrib->Next(); + } + return i; +} + +void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 ) +{ + if ( !pParent ) return; + + TiXmlNode* pChild; + TiXmlText* pText; + int t = pParent->Type(); + //printf( "%s", getIndent(indent)); + int num; + + //switch ( t ) + //{ + // case TiXmlNode::DOCUMENT: + // printf( "Document" ); + // break; + + //case TiXmlNode::ELEMENT: + //case "picture_high": + // if (pParent->Value() == "picture_high") + // { + std::string pstring = pParent->Value(); + // std::cerr << "pstring: " << pstring << std::endl; + size_t found=pstring.rfind("picture_high"); + if (found!=std::string::npos) + { + std::cerr << "First child: " << pParent->FirstChild()->Value() << std::endl; + } + // std::cerr << "picture_high: " << int(found) << std::endl; + // exit(0); + // } + // printf( "Element value [%s]", pParent->Value() ); + // num=dump_attribs_to_stdout(pParent->ToElement(), indent+1); + // switch(num) + // { + // case 0: printf( " (No attributes)"); break; + // case 1: printf( "%s1 attribute", getIndentAlt(indent)); break; + // default: printf( "%s%d attributes", getIndentAlt(indent), num); break; + // } + // break; + + // case TiXmlNode::COMMENT: + // printf( "Comment: [%s]", pParent->Value()); + // break; + + // case TiXmlNode::UNKNOWN: + // printf( "Unknown" ); + // break; + + // case TiXmlNode::TEXT: + // pText = pParent->ToText(); + // printf( "Text: [%s]", pText->Value() ); + // break; + + // case TiXmlNode::DECLARATION: + // printf( "Declaration" ); + // break; + // default: + // break; + //} + //printf( "\n" ); + for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) + { + dump_to_stdout( pChild, indent+1 ); + } +} + +// load the named file and dump its structure to STDOUT +void dump_to_stdout(const char* pFilename) +{ + TiXmlDocument doc(pFilename); + bool loadOkay = doc.LoadFile(); + if (loadOkay) + { + printf("\n%s:\n", pFilename); + dump_to_stdout( &doc ); // defined later in the tutorial + } + else + { + printf("Failed to load file \"%s\"\n", pFilename); + } +} + +// ---------------------------------------------------------------------- +// main() for printing files named on the command line +// ---------------------------------------------------------------------- +int main(int argc, char* argv[]) +{ + for (int i=1; i<argc; i++) + { + dump_to_stdout(argv[i]); + } + return 0; +} Property changes on: perception/zbar_barcode_reader_node/src/tinyxml.cpp ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native 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-27 18:36:55 UTC (rev 984) +++ perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-01-30 20:53:08 UTC (rev 985) @@ -9,6 +9,9 @@ #include <string.h> #include "std_msgs/String.h" #include <sstream> +#include "curl/curl.h" +#include "tinyxml.h" +#include <highgui.h> //Magick++ lib #include <Magick++.h> @@ -18,8 +21,63 @@ 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: BarcodeReaderNode(ros::NodeHandle &n) : n_(n), it_(n_) @@ -35,7 +93,186 @@ { } + // 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; + + // 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; + // } + int getImage(std::string & image) + { + CURL *curl; // CURL objects + CURLcode res; + cv::Mat imgTmp; // image object + memoryStruct buffer; // memory buffer + + curl = curl_easy_init(); // init CURL library object/structure + + if(curl) + { + // set up the write to memory buffer + // (buffer starts off empty) + buffer.memory = NULL; + buffer.size = 0; + + // (N.B. check this URL still works in browser in case image has moved) + curl_easy_setopt(curl, CURLOPT_URL, image.c_str()); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); // tell us what is happening + + // 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); + + // get the image from the specified URL + res = curl_easy_perform(curl); + // decode memory buffer using OpenCV + imgTmp = cv::imdecode(cv::Mat(1, buffer.size, CV_8UC1, buffer.memory), CV_LOAD_IMAGE_UNCHANGED); + // display image (if we got / decoded it correctly) + + + if (!(imgTmp.empty())) + { + imshow("Image from URL", imgTmp); + } + cv::waitKey(3); + + // always cleanup + + curl_easy_cleanup(curl); + free(buffer.memory); + } + return 1; + } + + void findElement( TiXmlNode* pParent, std::string & picture) + { + if ( !pParent ) return; + + TiXmlNode* pChild; + //std::string picture ("Picture Not Found"); + std::string pstring = pParent->Value(); + // std::cerr << "pstring: " << pstring << std::endl; + size_t found=pstring.find("picture_high"); + if (found!=std::string::npos) + { + ROS_INFO_STREAM("First child: " << pParent->FirstChild()->Value()); + picture = pParent->FirstChild()->Value(); + return; + } + size_t found2=pstring.find("picture_low"); + if (found2!=std::string::npos && picture == "") + { + ROS_INFO_STREAM("First child: " << pParent->FirstChild()->Value()); + picture = pParent->FirstChild()->Value(); + return; + } + for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) + { + findElement(pChild, picture); + // std::cerr << "in for " << std::endl; + } + } + + + int visBarcooPicture(std::string buffer) + { + // std::cerr << "buffer: " << buffer << std::endl; + TiXmlDocument doc; + doc.Parse((const char*)buffer.c_str(), 0, TIXML_ENCODING_UTF8); + doc.SaveFile ("text.xml"); + std::string picture; + findElement (&doc, picture); + ROS_INFO_STREAM ("Picture link: " << picture); + if (picture == "") + return -1; + getImage (picture); + return 1; + } + + + int callBarcoo(std::string bar_code, std::string & buffer) + { + char errorBuffer[CURL_ERROR_SIZE]; + // Our curl objects + CURL *curl; + CURLcode result; + // Create our curl handle + curl = curl_easy_init(); + std::string full_url = "http://www.barcoo.com/api/get_product_complete?pi=" + bar_code + "&pins=ean&format=xml&source=ias-tum"; + ROS_INFO_STREAM("full_url: " << full_url); + + if (curl) + { + // Now set up all of the curl options + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); + 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_WRITEDATA, &buffer); + + // Attempt to retrieve the remote page + result = curl_easy_perform(curl); + + // Always cleanup + curl_easy_cleanup(curl); + + // Did we succeed? + if (result == CURLE_OK) + { + ROS_INFO_STREAM ("CURLE_OK"); + return 1; + } + else + { + ROS_INFO_STREAM ( "CURLE_NOT OK"); + ROS_ERROR_STREAM ("Error: [" << result << "] - " << errorBuffer); + return -1; + } + } + return -1; + } + void imageCallback(const sensor_msgs::ImageConstPtr& msg_ptr) { @@ -43,7 +280,7 @@ ROS_INFO("[BarcodeReaderNode: ] Image received"); try { - cv_image = bridge_.imgMsgToCv(msg_ptr, "passthrough"); + cv_image = bridge_.imgMsgToCv(msg_ptr, "mono8"); } catch (sensor_msgs::CvBridgeException error) { @@ -71,6 +308,7 @@ int n = scanner.scan(image); // extract results + std::stringstream ss; for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) @@ -80,16 +318,30 @@ << " barcode value " << symbol->get_data()); std_msgs::String msg; - std::stringstream ss; - ss << symbol->get_type_name() << "," << symbol->get_data(); + + //ss << symbol->get_type_name() << "," << symbol->get_data(); + ss << symbol->get_data(); msg.data = ss.str(); barcode_pub_.publish(msg); } if (n == 0) - ROS_WARN("Barcode not found"); + { + ROS_WARN("Barcode not found"); + return; + } if (n < 0) - ROS_ERROR("Error occured while finding barcode"); + { + ROS_ERROR("Error occured while finding barcode"); + return; + } + + std::string buffer; + if (callBarcoo(ss.str(), buffer) == 1) + { + // std::cerr << "buffer after callBarcoo " << buffer << std::endl; + visBarcooPicture (buffer); + } // clean up image.set_data(NULL, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tum...@li...> - 2012-01-31 11:07:55
|
Revision: 986 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=986&view=rev Author: moesenle Date: 2012-01-31 11:07:48 +0000 (Tue, 31 Jan 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 12:07:05 2012 +0100 commit 05ca8af0ca8c6b8e96876789e20ddceac4db4ecc Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 12:06:34 2012 +0100 added system deps commit ac04cfa29420148be13c98195eb1ea423b406457 Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:53:49 2012 +0100 not needed filed anymore commit e0ae46178d3e1ce6787ba2bb0d5924f142d4fc34 Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:49:26 2012 +0100 public export commit 694aac589283166617448c925b62fea7e506f343 Author: Dejan Pangercic <dej...@cs...> Date: Mon Jan 30 21:48:26 2012 +0100 object recognition using barcoo working, major refactoring of the barcode_reader_node.zpp needed git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/CMakeLists.txt perception/zbar_barcode_reader_node/manifest.xml Added Paths: ----------- perception/zbar_barcode_reader_node/rosdep.yaml Removed Paths: ------------- perception/zbar_barcode_reader_node/src/scan_image.cpp Modified: perception/zbar_barcode_reader_node/CMakeLists.txt =================================================================== --- perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-30 20:53:08 UTC (rev 985) +++ perception/zbar_barcode_reader_node/CMakeLists.txt 2012-01-31 11:07:48 UTC (rev 986) @@ -31,9 +31,6 @@ rosbuild_add_executable(zbar_barcode_reader src/zbar_barcode_reader.c) target_link_libraries(zbar_barcode_reader MagickWand MagickCore) -rosbuild_add_executable(zbar_barcode_reader_cpp src/scan_image.cpp) -target_link_libraries(zbar_barcode_reader_cpp MagickWand MagickCore Magick++ curl) - rosbuild_add_executable(zbar_barcode_reader_node src/zbar_barcode_reader_node.cpp) target_link_libraries(zbar_barcode_reader_node Magick++ curl) Modified: perception/zbar_barcode_reader_node/manifest.xml =================================================================== --- perception/zbar_barcode_reader_node/manifest.xml 2012-01-30 20:53:08 UTC (rev 985) +++ perception/zbar_barcode_reader_node/manifest.xml 2012-01-31 11:07:48 UTC (rev 986) @@ -13,7 +13,8 @@ <depend package="cv_bridge"/> <depend package="image_transport"/> <depend package="sensor_msgs"/> - + <rosdep name="libcurl"/> + <rosdep name="libtinyxml"/> </package> Added: perception/zbar_barcode_reader_node/rosdep.yaml =================================================================== --- perception/zbar_barcode_reader_node/rosdep.yaml (rev 0) +++ perception/zbar_barcode_reader_node/rosdep.yaml 2012-01-31 11:07:48 UTC (rev 986) @@ -0,0 +1,7 @@ +libcurl: + ubuntu: + 11.04: libcurl3 + +libtinyxml: + ubuntu: + 11.04: libtinyxml-dev Deleted: perception/zbar_barcode_reader_node/src/scan_image.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/scan_image.cpp 2012-01-30 20:53:08 UTC (rev 985) +++ perception/zbar_barcode_reader_node/src/scan_image.cpp 2012-01-31 11:07:48 UTC (rev 986) @@ -1,54 +0,0 @@ -#include <iostream> -#include <Magick++.h> -#include <zbar.h> -#define STR(s) #s - -using namespace std; -using namespace zbar; - -int main (int argc, char **argv) -{ - if(argc < 2) return(1); - -#ifdef MAGICK_HOME - // http://www.imagemagick.org/Magick++/ - // under Windows it is necessary to initialize the ImageMagick - // library prior to using the Magick++ library - Magick::InitializeMagick(MAGICK_HOME); -#endif - - // create a reader - ImageScanner scanner; - - // configure the reader - scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); - - // obtain image data - Magick::Image magick(argv[1]); // read an image file - int width = magick.columns(); // extract dimensions - int height = magick.rows(); - Magick::Blob blob; // extract the raw data - magick.modifyImage(); - magick.write(&blob, "GRAY", 8); - const void *raw = blob.data(); - - // wrap image data - Image image(width, height, "Y800", raw, width * height); - - // scan the image for barcodes - int n = scanner.scan(image); - - // extract results - for(Image::SymbolIterator symbol = image.symbol_begin(); - symbol != image.symbol_end(); - ++symbol) { - // do something useful with results - cout << "decoded " << symbol->get_type_name() - << " symbol \"" << symbol->get_data() << '"' << endl; - } - - // clean up - image.set_data(NULL, 0); - - return(0); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <tum...@li...> - 2012-02-05 18:32:45
|
Revision: 989 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=989&view=rev Author: moesenle Date: 2012-02-05 18:32:38 +0000 (Sun, 05 Feb 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@cs...> Date: Sun Feb 5 19:32:04 2012 +0100 commit 0d6623d44c2cb9056ee62606f63b79be374f2dfe Author: Dejan Pangercic <dej...@cs...> Date: Sun Feb 5 19:31:38 2012 +0100 refactored the code commit 2b90812f874db614252cc411ea9f6581e05cc527 Author: Dejan Pangercic <dej...@gm...> Date: Tue Jan 31 17:56:00 2012 +0100 public export git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/launch/barcode_reader.launch perception/zbar_barcode_reader_node/rosdep.yaml 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 16:56:47 UTC (rev 988) +++ perception/zbar_barcode_reader_node/launch/barcode_reader.launch 2012-02-05 18:32:38 UTC (rev 989) @@ -1,5 +1,12 @@ <launch> - <node pkg="zbar_barcode_reader_node" type="zbar_barcode_reader_node" name="barcode_reader_node" output="screen" respawn="true"> + <node pkg="zbar_barcode_reader_node" type="zbar_barcode_reader_node" name="barcode_reader_node" output="screen" respawn="false"> <param name="input_image_topic" type="string" value="/image_raw" /> + <param name="link1" type="string" value="http://www.barcoo.com/api/get_product_complete?pi=" /> + <param name="link2" type="string" value="&pins=ean&format=xml&source=ias-tum" /> + <param name="tag1" type="string" value="answer" /> + <param name="tag2" type="string" value="picture_high" /> + <param name="tag3" type="string" value="picture_low" /> + <param name="image_pattern" type="string" value="<meta property="og:image" content="" /> + </node> </launch> Modified: perception/zbar_barcode_reader_node/rosdep.yaml =================================================================== --- perception/zbar_barcode_reader_node/rosdep.yaml 2012-01-31 16:56:47 UTC (rev 988) +++ perception/zbar_barcode_reader_node/rosdep.yaml 2012-02-05 18:32:38 UTC (rev 989) @@ -1,7 +1,11 @@ libcurl: ubuntu: 11.04: libcurl3 + oneiric: libcurl3 libtinyxml: ubuntu: 11.04: libtinyxml-dev + oneiric: libtinyxml-dev + + 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 16:56:47 UTC (rev 988) +++ perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-02-05 18:32:38 UTC (rev 989) @@ -22,6 +22,13 @@ using namespace zbar; class BarcodeReaderNode { + std:: string link1_;// = "http://www.barcoo.com/api/get_product_complete?pi="; + std:: string link2_;// = "&pins=ean&format=xml&source=ias-tum"; + std:: string tag1_;// = "answer"; + std:: string tag2_;// = "picture_high"; + std:: string tag3_;// = "picture_low"; + std:: string pattern_;// = "<meta property=\"og:image\" content=\""; + TiXmlDocument doc; public: struct memoryStruct { @@ -39,8 +46,19 @@ BarcodeReaderNode(ros::NodeHandle &n) : n_(n), it_(n_) { - n_.param ("input_image_topic", input_image_topic_, std::string("/stereo/left/image_rect")); + //link1 = "http://www.barcoo.com/api/get_product_complete?pi="; + //link2 = "&pins=ean&format=xml&source=ias-tum"; + //tag1 = "answer"; + //tag2 = "picture_high"; + //tag3 = "picture_low"; + + n_.param ("input_image_topic", input_image_topic_, std::string("/image_raw")); n_.param ("outout_barcode_topic", output_barcode_topic_, std::string("barcode")); + n_.param ("link1", link1_, std::string("http://www.barcoo.com/api/get_product_complete?pi=")); + n_.param ("link2", link2_, std::string("&pins=ean&format=xml&source=ias-tum")); + n_.param ("tag2", tag2_, std::string("picture_high")); + n_.param ("tag3", tag3_, std::string("picture_low")); + n_.param ("image_pattern", pattern_, std::string("<meta property=\"og:image\" content=\"")); image_sub_ = it_.subscribe( input_image_topic_, 1, &BarcodeReaderNode::imageCallback, this); barcode_pub_ = @@ -67,7 +85,7 @@ { UserData *userdata = reinterpret_cast<UserData *>(data); struct memoryStruct *mem = userdata->memory; - BarcodeReaderNode *self = userdata->self; + //BarcodeReaderNode *self = userdata->self; size_t realsize = size * nmemb; mem->memory = (char *) @@ -100,11 +118,10 @@ return result; } - int getImage(std::string & image) + int getImage(std::string image, cv::Mat * imgTmp) { CURL *curl; // CURL objects CURLcode res; - cv::Mat imgTmp; // image object memoryStruct buffer; // memory buffer UserData userdata(&buffer, this); @@ -129,16 +146,7 @@ // get the image from the specified URL res = curl_easy_perform(curl); // decode memory buffer using OpenCV - imgTmp = cv::imdecode(cv::Mat(1, buffer.size, CV_8UC1, buffer.memory), CV_LOAD_IMAGE_UNCHANGED); - // display image (if we got / decoded it correctly) - - - if (!(imgTmp.empty())) - { - imshow("Barcoo img", imgTmp); - } - cv::waitKey(3); - + *imgTmp = cv::imdecode(cv::Mat(1, buffer.size, CV_8UC1, buffer.memory), CV_LOAD_IMAGE_UNCHANGED); // always cleanup curl_easy_cleanup(curl); @@ -147,52 +155,60 @@ return 1; } - void findElement( TiXmlNode* pParent, std::string & picture) + void findElement( TiXmlNode* pParent, std::string & picture, std:: string tag) { - if ( !pParent ) return; + //if ( !pParent ) return; TiXmlNode* pChild; - //std::string picture ("Picture Not Found"); std::string pstring = pParent->Value(); - // std::cerr << "pstring: " << pstring << std::endl; - size_t found=pstring.find("picture_high"); + + //Search for tag + size_t found=pstring.find(tag); if (found!=std::string::npos) - { - ROS_INFO_STREAM("First child: " << pParent->FirstChild()->Value()); - picture = pParent->FirstChild()->Value(); - return; - } - size_t found2=pstring.find("picture_low"); - if (found2!=std::string::npos && picture == "") - { - ROS_INFO_STREAM("First child: " << pParent->FirstChild()->Value()); - picture = pParent->FirstChild()->Value(); - return; - } - for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) - { - findElement(pChild, picture); - // std::cerr << "in for " << std::endl; - } + { + ROS_INFO_STREAM("First child: " << pParent->FirstChild()->Value()); + picture = pParent->FirstChild()->Value(); + return; + } + + for( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) + { + findElement(pChild, picture,tag); + } } - int visBarcooPicture(std::string buffer) + int getPictureLink(std::string buffer,std::string & picture) { - // std::cerr << "buffer: " << buffer << std::endl; - TiXmlDocument doc; doc.Parse((const char*)buffer.c_str(), 0, TIXML_ENCODING_UTF8); - std::string picture; - findElement (&doc, picture); + + //Check if there is a result + std:: string result; + cout << "ohhh my goooooood\n\n"; + findElement(&doc,result,tag1_); + if(result.compare("0") == 0) //This condition checks if there is a result in the XML file if not returns 0 + { + cout << "heloooooo barcode does not correspond to any object in the barcoo database"; + return 0; + } + else + cout << "ELSE ELSE ELSE\n"; + + //Search for first tag + findElement (&doc, picture,tag2_); + + if(picture == "") + findElement (&doc, picture,tag3_); //Search for second tag + ROS_INFO_STREAM ("Picture link: " << picture); if (picture == "") return -1; - getImage (picture); + return 1; } - int callBarcoo(std::string bar_code, std::string & buffer) + int getBarcooXML(std::string bar_code, std::string & buffer) { char errorBuffer[CURL_ERROR_SIZE]; // Our curl objects @@ -200,7 +216,7 @@ CURLcode result; // Create our curl handle curl = curl_easy_init(); - std::string full_url = "http://www.barcoo.com/api/get_product_complete?pi=" + bar_code + "&pins=ean&format=xml&source=ias-tum"; + std::string full_url = link1_ + bar_code + link2_; ROS_INFO_STREAM("full_url: " << full_url); if (curl) @@ -236,6 +252,45 @@ return -1; } + int getHTMLpage(std::string url, std::string & buffer) + { + char errorBuffer[CURL_ERROR_SIZE]; + // Our curl objects + CURL *curl; + CURLcode result; + // Create our curl handle + curl = curl_easy_init(); + if (curl) + { + // Now set up all of the curl options + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer); + curl_easy_setopt(curl, CURLOPT_URL, 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_WRITEDATA, &buffer); + + // Attempt to retrieve the remote page + result = curl_easy_perform(curl); + + // Always cleanup + curl_easy_cleanup(curl); + + // Did we succeed? + if (result == CURLE_OK) + { + + return 1; + } + else + { + return -1; + } + } + return -1; + } + void imageCallback(const sensor_msgs::ImageConstPtr& msg_ptr) { @@ -288,26 +343,70 @@ barcode_pub_.publish(msg); } if (n == 0) - { - ROS_WARN("Barcode not found"); - return; - } + { + ROS_WARN("Barcode not found"); + return; + } if (n < 0) - { - ROS_ERROR("Error occured while finding barcode"); - return; - } + { + ROS_ERROR("Error occured while finding barcode"); + return; + } std::string buffer; - if (callBarcoo(ss.str(), buffer) == 1) - { - // std::cerr << "buffer after callBarcoo " << buffer << std::endl; - visBarcooPicture (buffer); - } + //Get xml file from barcoo database + int res = getBarcooXML(ss.str(), buffer); + if(res != 1) + return; + // std::cerr << "buffer after callBarcoo " << buffer << std::endl; + //Search for info in the xml file + std::string pictureLink; + res = getPictureLink (buffer,pictureLink); + + + if(res == 0) //If barcode does not exist in the database return + { + cout << "Barcode does not exist in the barcoo datbase\n"; + return; + } + if(res == -1) //This condition is true when the image link is not given + { + //Look for an image in the HTML file + + //First find the link to the barcoo website of the file + std::string htmlPage; + std::string htmlLink; + findElement(&doc,htmlLink,"back_link"); + cout << "html link: "+htmlLink+"\n"; + //Download HTML page + getHTMLpage(htmlLink,htmlPage); + std::string ss = pattern_; + long position = htmlPage.find(ss, ss.length()) + ss.length(); + + std::string link; + while(htmlPage.at(position) !='"') + { + link += htmlPage.at(position); + position++; + } + pictureLink = link; + + } + //Get Image + if(!pictureLink.empty()) + { + cv::Mat imgTmp; // image object + getImage (pictureLink ,& imgTmp); + // display image + if (!(imgTmp.empty())) + { + imshow("Barcoo img", imgTmp); + } + } + cv::waitKey(3); // clean up image.set_data(NULL, 0); - } protected: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tum...@li...> - 2012-02-14 13:28:08
|
Revision: 993 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=993&view=rev Author: moesenle Date: 2012-02-14 13:27:57 +0000 (Tue, 14 Feb 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@gm...> Date: Tue Feb 14 14:27:37 2012 +0100 commit 87397cf1d1b5ccd96507252dcc26e0379750e2ba Author: Dejan Pangercic <dej...@gm...> Date: Tue Feb 14 14:27:08 2012 +0100 server side of service for trigering the barcode recognition from a QT client commit d9f59658e46f74926677d131c1941e1fed7e9fdb Author: Dejan Pangercic <dej...@cs...> Date: Sun Feb 5 19:32:04 2012 +0100 public export git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/CMakeLists.txt perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp Modified: perception/zbar_barcode_reader_node/CMakeLists.txt =================================================================== --- perception/zbar_barcode_reader_node/CMakeLists.txt 2012-02-13 09:08:17 UTC (rev 992) +++ perception/zbar_barcode_reader_node/CMakeLists.txt 2012-02-14 13:27:57 UTC (rev 993) @@ -19,7 +19,7 @@ #uncomment if you have defined messages #rosbuild_genmsg() #uncomment if you have defined services -#rosbuild_gensrv() +rosbuild_gensrv() #common commands for building c++ executables and libraries #rosbuild_add_library(${PROJECT_NAME} src/example.cpp) Modified: perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-02-13 09:08:17 UTC (rev 992) +++ perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-02-14 13:27:57 UTC (rev 993) @@ -12,6 +12,7 @@ #include "curl/curl.h" #include "tinyxml.h" #include <highgui.h> +#include <zbar_barcode_reader_node/enable_barcode_reader.h> //Magick++ lib #include <Magick++.h> @@ -29,6 +30,7 @@ std:: string tag3_;// = "picture_low"; std:: string pattern_;// = "<meta property=\"og:image\" content=\""; TiXmlDocument doc; + int enable_barcode_reader_; public: struct memoryStruct { @@ -64,12 +66,22 @@ barcode_pub_ = n_.advertise<std_msgs::String>(output_barcode_topic_, 1); cv::namedWindow ("Barcoo img"); + enable_barcode_reader_ = 0; + service_ = n.advertiseService("enable_barcode_reader_service", &BarcodeReaderNode::enable_barcode_reader,this); } ~BarcodeReaderNode() { cv::destroyAllWindows(); } + + bool enable_barcode_reader(zbar_barcode_reader_node::enable_barcode_reader::Request &req, + zbar_barcode_reader_node::enable_barcode_reader::Response &res ) + { + enable_barcode_reader_ = req.enable; + return true; + } + static void* CURL_realloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing @@ -79,7 +91,7 @@ else return malloc(size); } - + static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data) { @@ -290,10 +302,12 @@ } return -1; } - + void imageCallback(const sensor_msgs::ImageConstPtr& msg_ptr) { - + + if(!enable_barcode_reader_) + return; IplImage *cv_image = NULL; ROS_INFO("[BarcodeReaderNode: ] Image received"); try @@ -417,6 +431,7 @@ ros::Publisher barcode_pub_; sensor_msgs::CvBridge bridge_; std::string input_image_topic_, output_barcode_topic_; + ros::ServiceServer service_; }; int main(int argc, char** argv) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tum...@li...> - 2012-02-18 21:16:21
|
Revision: 994 http://tum-ros-pkg.svn.sourceforge.net/tum-ros-pkg/?rev=994&view=rev Author: moesenle Date: 2012-02-18 21:16:15 +0000 (Sat, 18 Feb 2012) Log Message: ----------- Author: Dejan Pangercic <dej...@cs...> Date: Sat Feb 18 22:09:16 2012 +0100 commit 15f57613e25e8ac1395a38f99f8bad776e07e8a4 Author: Dejan Pangercic <dej...@cs...> Date: Sat Feb 18 22:08:43 2012 +0100 new service definition and integration into the server commit d9f59658e46f74926677d131c1941e1fed7e9fdb Author: Dejan Pangercic <dej...@cs...> Date: Sun Feb 5 19:32:04 2012 +0100 public export git-commit Modified Paths: -------------- perception/zbar_barcode_reader_node/CMakeLists.txt perception/zbar_barcode_reader_node/manifest.xml perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp Added Paths: ----------- perception/zbar_barcode_reader_node/srv/ perception/zbar_barcode_reader_node/srv/enable_barcode_reader.srv Modified: perception/zbar_barcode_reader_node/CMakeLists.txt =================================================================== --- perception/zbar_barcode_reader_node/CMakeLists.txt 2012-02-14 13:27:57 UTC (rev 993) +++ perception/zbar_barcode_reader_node/CMakeLists.txt 2012-02-18 21:16:15 UTC (rev 994) @@ -17,7 +17,7 @@ set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib) #uncomment if you have defined messages -#rosbuild_genmsg() +rosbuild_genmsg() #uncomment if you have defined services rosbuild_gensrv() Modified: perception/zbar_barcode_reader_node/manifest.xml =================================================================== --- perception/zbar_barcode_reader_node/manifest.xml 2012-02-14 13:27:57 UTC (rev 993) +++ perception/zbar_barcode_reader_node/manifest.xml 2012-02-18 21:16:15 UTC (rev 994) @@ -12,9 +12,10 @@ <depend package="opencv2"/> <depend package="cv_bridge"/> <depend package="image_transport"/> - <depend package="sensor_msgs"/> + <depend package="sensor_msgs"/> <rosdep name="libcurl"/> - <rosdep name="libtinyxml"/> + <rosdep name="libtinyxml"/> + </package> Modified: perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp =================================================================== --- perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-02-14 13:27:57 UTC (rev 993) +++ perception/zbar_barcode_reader_node/src/zbar_barcode_reader_node.cpp 2012-02-18 21:16:15 UTC (rev 994) @@ -31,7 +31,8 @@ std:: string pattern_;// = "<meta property=\"og:image\" content=\""; TiXmlDocument doc; int enable_barcode_reader_; - + int image_received_; + int image_found_; public: struct memoryStruct { char *memory; @@ -65,9 +66,10 @@ input_image_topic_, 1, &BarcodeReaderNode::imageCallback, this); barcode_pub_ = n_.advertise<std_msgs::String>(output_barcode_topic_, 1); - cv::namedWindow ("Barcoo img"); + //cv::namedWindow ("Barcoo img"); enable_barcode_reader_ = 0; service_ = n.advertiseService("enable_barcode_reader_service", &BarcodeReaderNode::enable_barcode_reader,this); + image_received_ = 0; } ~BarcodeReaderNode() @@ -78,8 +80,31 @@ bool enable_barcode_reader(zbar_barcode_reader_node::enable_barcode_reader::Request &req, zbar_barcode_reader_node::enable_barcode_reader::Response &res ) { - enable_barcode_reader_ = req.enable; - return true; + enable_barcode_reader_ = req.enable; + while(!image_received_) + { + sleep(1); + } + + if(image_found_) + { + res.title.data = product_title; + res.subtitle.data = product_producer; + res.category_key.data = product_category; + res.image_msg = *ros_image; + enable_barcode_reader_ = 0; + image_received_ = 0; + image_found_ = 0; + enable_barcode_reader_ = 0; + + return true; + } + else + { + image_received_ = 0; + enable_barcode_reader_ = 0; + return false; + } } static void* CURL_realloc(void *ptr, size_t size) @@ -359,12 +384,14 @@ if (n == 0) { ROS_WARN("Barcode not found"); + image_received_ = 1; return; } if (n < 0) { ROS_ERROR("Error occured while finding barcode"); + image_received_ = 1; return; } @@ -372,7 +399,10 @@ //Get xml file from barcoo database int res = getBarcooXML(ss.str(), buffer); if(res != 1) + { + image_received_ = 1; return; + } // std::cerr << "buffer after callBarcoo " << buffer << std::endl; //Search for info in the xml file std::string pictureLink; @@ -382,6 +412,7 @@ if(res == 0) //If barcode does not exist in the database return { cout << "Barcode does not exist in the barcoo datbase\n"; + image_received_ = 1; return; } if(res == -1) //This condition is true when the image link is not given @@ -413,14 +444,35 @@ cv::Mat imgTmp; // image object getImage (pictureLink ,& imgTmp); // display image + //publish image if (!(imgTmp.empty())) { - imshow("Barcoo img", imgTmp); + //imshow("Barcoo img", imgTmp); + cv_bridge::CvImagePtr cv_ptr (new cv_bridge::CvImage); + + std::cerr<< "\n\n\n\n\nTESTESTESTESTESTn\n\n\n\n"; + + cv_ptr->header.stamp = ros::Time::now(); + cv_ptr->header.frame_id = "frame"; + cv_ptr->encoding = "bgr8"; + std::cerr<< "\n\n\n\n\nHELO00000n\n\n\n\n"; + cv_ptr->image = imgTmp; + std::cerr<< "\n\n\n\n\nHELOn\n\n\n\n"; + + ros_image = cv_ptr->toImageMsg(); + findElement(&doc,product_title,"title"); + findElement(&doc,product_producer,"producer"); + findElement(&doc,product_category,"category_key"); + + + + image_found_ = 1; } + image_received_ = 1; } cv::waitKey(3); // clean up - image.set_data(NULL, 0); + //image.set_data(NULL, 0); } protected: @@ -431,14 +483,21 @@ ros::Publisher barcode_pub_; sensor_msgs::CvBridge bridge_; std::string input_image_topic_, output_barcode_topic_; + sensor_msgs::ImagePtr ros_image; + std::string product_title; + std::string product_producer; + std::string product_category; ros::ServiceServer service_; }; int main(int argc, char** argv) { ros::init(argc, argv, "barcode_reader_node"); + ros::AsyncSpinner spinner(1); // Use 4 threads + spinner.start(); ros::NodeHandle n("~"); BarcodeReaderNode br(n); ros::spin(); + return 0; } Added: perception/zbar_barcode_reader_node/srv/enable_barcode_reader.srv =================================================================== --- perception/zbar_barcode_reader_node/srv/enable_barcode_reader.srv (rev 0) +++ perception/zbar_barcode_reader_node/srv/enable_barcode_reader.srv 2012-02-18 21:16:15 UTC (rev 994) @@ -0,0 +1,6 @@ +int64 enable +--- +std_msgs/String title +std_msgs/String subtitle +std_msgs/String category_key +sensor_msgs/Image image_msg \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |