Go to the documentation of this file.00001
00021 #ifndef DESCRIPTOR_SURFACED_BASED_RECOGNITION_H
00022 #define DESCRIPTOR_SURFACED_BASED_RECOGNITION_H
00023
00024 #include <ros/ros.h>
00025 #include <dynamic_reconfigure/server.h>
00026 #include <asr_descriptor_surface_based_recognition/DescriptorSurfaceBasedRecognitionConfig.h>
00027 #include <message_filters/subscriber.h>
00028 #include <message_filters/synchronizer.h>
00029 #include <message_filters/sync_policies/approximate_time.h>
00030 #include <visualization_msgs/MarkerArray.h>
00031 #include <sensor_msgs/PointCloud2.h>
00032 #include <sensor_msgs/Image.h>
00033
00034 #include <Eigen/Dense>
00035
00036 #include <asr_msgs/AsrObject.h>
00037 #include <asr_object_database/ObjectMetaData.h>
00038 #include <asr_object_database/RecognizerListMeshes.h>
00039
00040 #include <asr_descriptor_surface_based_recognition/GetRecognizer.h>
00041 #include <asr_descriptor_surface_based_recognition/ReleaseRecognizer.h>
00042 #include <asr_descriptor_surface_based_recognition/GetObjectList.h>
00043 #include <asr_descriptor_surface_based_recognition/ClearAllRecognizers.h>
00044
00045 #include "threadpool/threadpool.hpp"
00046 #include "pose_validation.h"
00047 #include "object_descriptor.h"
00048 #include "pose_recognition.h"
00049 #include "object_2D_positions.h"
00050 #include "util.h"
00051
00052
00053 namespace descriptor_surface_based_recognition {
00054
00055 using namespace asr_descriptor_surface_based_recognition;
00056
00057 const static std::string NODE_NAME("asr_descriptor_surface_based_recognition");
00058
00059 const static std::string GET_RECOGNIZER_SERVICE_NAME("get_recognizer");
00060 const static std::string RELEASE_RECOGNIZER_SERVICE_NAME("release_recognizer");
00061 const static std::string GET_OBJECT_LIST_SERVICE_NAME("get_object_list");
00062 const static std::string CLEAR_ALL_RECOGNIZERS_SERVICE_NAME("clear_all_recognizers");
00063 const static std::string OBJECT_DB_SERVICE_OBJECT_TYPE ("/asr_object_database/object_meta_data");
00064 const static std::string OBJECT_DB_SERVICE_OBJECT_MESHES("/asr_object_database/recognizer_list_meshes");
00065
00069 const static std::string OUTPUT_EVALUATION_DIR("eval");
00070 const static std::string OUTPUT_EVALUATION_FILE_TIME("global_times.txt");
00071 const static std::string OUTPUT_EVALUATION_FILE_POSES("global_poses.txt");
00072
00076 const static std::string OBJECT_DATABASE_CATEGORY("descriptor");
00077
00079 extern std::string PACKAGE_PATH;
00080
00081
00082
00083 typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::Image, sensor_msgs::Image, sensor_msgs::PointCloud2> ApproximatePolicy;
00084 typedef message_filters::Synchronizer<ApproximatePolicy> ApproximateSync;
00085
00086
00090 class DescriptorSurfaceBasedRecognition {
00091
00092 private:
00093
00095 std::string image_color_topic_;
00096
00098 std::string image_mono_topic_;
00099
00101 std::string point_cloud_topic_;
00102
00104 std::string output_objects_topic_;
00105
00107 std::string output_marker_topic_;
00108
00110 std::string output_marker_bounding_box_topic_;
00111
00113 std::string output_cloud_topic_;
00114
00116 std::string output_image_topic_;
00117
00118
00120 ros::NodeHandle nh_;
00121
00123 dynamic_reconfigure::Server<DescriptorSurfaceBasedRecognitionConfig> reconfigure_server_;
00124
00126 DescriptorSurfaceBasedRecognitionConfig config_;
00127
00129 message_filters::Subscriber<sensor_msgs::Image> image_sub_;
00130 message_filters::Subscriber<sensor_msgs::Image> image_mono_sub_;
00131 message_filters::Subscriber<sensor_msgs::PointCloud2> pc_with_guppy_sub_;
00132
00134 ros::ServiceServer get_recognizer_service_;
00135 ros::ServiceServer release_recognizer_service_;
00136 ros::ServiceServer get_object_list_service_;
00137 ros::ServiceServer clear_all_recognizers_service_;
00138
00139 ros::ServiceClient object_db_service_client_;
00140 ros::ServiceClient object_db_meshes_service_client_;
00141
00143 boost::shared_ptr<ApproximateSync> sync_policy_;
00144
00146 ros::Publisher objects_pub_;
00147 ros::Publisher marker_pub_;
00148 ros::Publisher boxes_pub_;
00149 ros::Publisher cloud_pub_;
00150 ros::Publisher image_pub_;
00151
00152
00154 visualization_msgs::MarkerArrayPtr msgs_marker_array_;
00155 visualization_msgs::MarkerArrayPtr msgs_box_marker_array_;
00156
00158 boost::threadpool::pool thread_pool_;
00159
00161 std::vector<ObjectDescriptor> objects_;
00162
00164 std::vector<Ogre::MeshPtr> meshes_;
00165
00167 std::vector<Object2DPositions> last_frame_positions_;
00168
00170 PoseValidation pose_val_;
00171
00173 std::ofstream outstream_times_;
00174
00176 std::ofstream outstream_poses_;
00177
00179 int frame_counter_;
00180
00181
00182
00183
00184
00192 void rosCallback(const sensor_msgs::ImageConstPtr& input_image_guppy, const sensor_msgs::ImageConstPtr& input_image_guppy_mono, const sensor_msgs::PointCloud2ConstPtr& input_point_cloud_with_guppy);
00193
00200 void configCallback(DescriptorSurfaceBasedRecognitionConfig &config_, uint32_t level);
00201
00207 void threadTask(PoseRecognition *pose_rec);
00208
00218 asr_msgs::AsrObjectPtr createAsrMessage(PoseRecognition *pose_rec, int results_index, std_msgs::Header header);
00219
00226 void createMarker(asr_msgs::AsrObjectPtr &object, std::string &mesh_path);
00227
00231 void clearMarkers();
00232
00241 void createBoxMarker(RecognitionResult *result, std_msgs::Header header, rgb color, bool drawCompleteBoxes);
00242
00249 void overlaySceneWith2DResults(PoseRecognition *pose_rec, HalconCpp::HImage *scene_image);
00250
00257 pcl::PointCloud<pcl::PointXYZRGB>::Ptr createVisualizationCloud(std::vector<PoseRecognition*> &pose_recs, std_msgs::Header header);
00258
00264 bool processGetRecognizerRequest(GetRecognizer::Request &req, GetRecognizer::Response &res);
00265
00271 bool processReleaseRecognizerRequest(ReleaseRecognizer::Request &req, ReleaseRecognizer::Response &res);
00272
00278 bool processGetObjectListRequest(GetObjectList::Request &req, GetObjectList::Response &res);
00279
00285 bool processClearAllRecognizersRequest(ClearAllRecognizers::Request &req, ClearAllRecognizers::Response &res);
00286
00290 void initializeMeshes();
00291
00301 bool startObjectRecognition(std::string name, int count, bool use_pose_val);
00302
00308 void stopObjectRecognition(std::string name);
00309
00310 public:
00311
00315 DescriptorSurfaceBasedRecognition();
00316
00317 };
00318
00319 }
00320
00321 #endif