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. |