00001 /********************************************************************* 00002 The MIT License (MIT) 00003 00004 Copyright (c) <2013> <Vojtech Novak> 00005 00006 Permission is hereby granted, free of charge, to any person obtaining a copy 00007 of this software and associated documentation files (the "Software"), to deal 00008 in the Software without restriction, including without limitation the rights 00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00010 copies of the Software, and to permit persons to whom the Software is 00011 furnished to do so, subject to the following conditions: 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00022 THE SOFTWARE. 00023 *********************************************************************/ 00024 00025 #ifndef TEXT_LOCATOR_TEXTLOCATOR_HPP_ 00026 #define TEXT_LOCATOR_TEXTLOCATOR_HPP_ 00027 //#include <sensor_msgs/PointCloud.h> 00028 #include <pcl-1.6/pcl/point_cloud.h> 00029 #include <pcl-1.6/pcl/point_types.h> 00030 #include <pcl_ros/point_cloud.h> 00031 #include <image_transport/image_transport.h> 00032 #include <cv_bridge/cv_bridge.h> 00033 #include <sensor_msgs/image_encodings.h> 00034 #include <opencv2/imgproc/imgproc.hpp> 00035 #include <opencv2/highgui/highgui.hpp> 00036 #include <boost/thread/locks.hpp> 00037 #include <boost/thread/pthread/mutex.hpp> 00038 #include "TRecognizer.hpp" 00039 #include "TDetector.hpp" 00040 00041 namespace ros_text_locator { 00042 00043 class TextLocator { 00044 private: 00045 TRecognizer rec; 00046 TDetector detector; 00047 const bool paramDebugMode; 00048 const bool recognitionEnabled; 00049 volatile bool newdata; 00050 ros::NodeHandle& nodehandler; 00051 const bool pclEnabled; 00052 00053 float rgb2IrX; 00054 float rgb2IrY; 00055 std::vector<Text2D> text2d; 00056 ros::Publisher pub; 00057 ros::Subscriber sub; 00058 ros::Subscriber sub2; 00059 cv_bridge::CvImageConstPtr cv_ptr; 00060 00061 void publish(pcl::PointXYZRGB &p1, pcl::PointXYZRGB &p2, std::string txt); 00062 void saveDbgImg(const sensor_msgs::ImageConstPtr& image); 00063 void monoCallback(const sensor_msgs::ImageConstPtr& image); 00064 void depthCallback( 00065 const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& depth); 00066 int rgbToIrX(int rgb); 00067 int rgbToIrY(int rgb); 00068 void init(); 00069 00070 public: 00071 TextLocator(); 00072 TextLocator(ros::NodeHandle &handle, 00073 tesseract::PageSegMode pgSegMode, std::string lang, 00074 std::vector<ccv_swt_param_t> params, const bool enableRecognition, 00075 const bool paramDebug, const bool enablePcl); 00076 void run(); 00077 00078 bool isRecognitionEnabled() const { 00079 return recognitionEnabled; 00080 } 00081 00082 bool isPclEnabled() const { 00083 return pclEnabled; 00084 } 00085 00086 TDetector& getDetector() { 00087 return detector; 00088 } 00089 00090 TRecognizer& getRecognizer() { 00091 return rec; 00092 } 00093 }; 00094 00095 } /* namespace ros_text_locator */ 00096 #endif /* TEXT_LOCATOR_TEXTLOCATOR_HPP_ */