Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <blort_ros/gldetector.h>
00042 #include <blort/Tracker/utilities.hpp>
00043 #include <blort/TomGine/tgModelLoader.h>
00044 #include <ros/console.h>
00045 #include <sstream>
00046 #include <iostream>
00047 #include <blort/blort/pal_util.h>
00048 #include <boost/foreach.hpp>
00049
00050 using namespace blort_ros;
00051
00052 GLDetector::GLDetector(const sensor_msgs::CameraInfo& camera_info, const std::string& config_root)
00053 {
00054
00055
00056
00057 rec3dcounter = 0;
00058 recovery_conf_threshold = 0.05;
00059
00060
00061 std::string tracking_ini(blort_ros::addRoot("config/tracking.ini", config_root));
00062 std::vector<std::string> ply_models(0), sift_files(0), model_names(0);
00063 GetPlySiftFilenames(tracking_ini.c_str(), ply_models, sift_files, model_names);
00064 blort::buildFromFiles(ply_models, sift_files, model_names, objects, sift_index);
00065
00066 recognizer = boost::shared_ptr<blortRecognizer::Recognizer3D>(
00067 new blortRecognizer::Recognizer3D(blortRecognizer::CameraParameter(camera_info), config_root, true));
00068 sift_files_count = 0;
00069 for(size_t i = 0; i < objects.size(); ++i)
00070 {
00071 for(size_t j = 0; j < objects[i].recog_data.size(); ++j)
00072 {
00073 recognizer->loadModelFromFile("Resources/sift/" + objects[i].recog_data[j].sift_file);
00074 sift_files_count++;
00075 }
00076 }
00077 image_ = cvCreateImage( cvSize(camera_info.width, camera_info.height), 8, 3 );
00078 }
00079
00080 bool GLDetector::recovery(std::vector<std::string> & obj_ids, const cv::Mat& image,
00081 blort_msgs::RecoveryCall::Response &resp)
00082 {
00083 last_image = image;
00084 *image_ = last_image;
00085
00086 return recoveryWithLast(obj_ids, resp);
00087 }
00088
00089 bool GLDetector::recoveryWithLast(std::vector<std::string> & obj_ids,
00090 blort_msgs::RecoveryCall::Response &resp)
00091 {
00092 double ticksBefore = cv::getTickCount();
00093
00094 std::map< std::string, boost::shared_ptr<TomGine::tgPose> > recPoses;
00095 std::map<std::string, double> confs;
00096 std::map<std::string, bool> select;
00097 BOOST_FOREACH(const blort::ObjectEntry& obj, objects)
00098 {
00099
00100 for(size_t j = 0; j < obj.recog_data.size(); ++j)
00101 {
00102 recPoses[obj.recog_data[j].sift_file] =
00103 boost::shared_ptr<TomGine::tgPose>(new TomGine::tgPose());
00104
00105 if(std::find(obj_ids.begin(), obj_ids.end(), obj.name) != obj_ids.end())
00106 {
00107 select[obj.recog_data[j].sift_file] = true;
00108 ROS_ERROR_STREAM("Recoverycall for sift file: " << obj.recog_data[j].sift_file);
00109 }
00110 else
00111 {
00112 select[obj.recog_data[j].sift_file] = false;
00113 }
00114 }
00115 }
00116 recognizer->recognize(image_, recPoses, confs, select);
00117
00118 bool found_one = false;
00119 resp.object_founds.resize(obj_ids.size());
00120 resp.Poses.resize(obj_ids.size());
00121 for(size_t i = 0; i < objects.size(); ++i)
00122 {
00123 blort::RecogData recog = blort::getBest(objects[i]);
00124 ROS_INFO_STREAM("object (" << objects[i].name
00125 << ") conf: " << confs[recog.sift_file]);
00126
00127 const bool found = ( confs[recog.sift_file] > recovery_conf_threshold );
00128 if(found)
00129 {
00130 found_one = true;
00131 resp.object_ids.push_back(objects[i].name);
00132 resp.object_founds.push_back(true);
00133 resp.Poses.push_back(blort_ros::tgPose2RosPose(*(recPoses[recog.sift_file])));
00134 }
00135 }
00136 ROS_WARN_STREAM("Tried to recover for the " << rec3dcounter++ << ". time.");
00137 ROS_INFO_STREAM("Recovery execution time: "
00138 << 1000*(cv::getTickCount() - ticksBefore)/cv::getTickFrequency()
00139 << " ms");
00140 return found_one;
00141 }
00142
00143 void GLDetector::reconfigure(blort_ros::DetectorConfig config)
00144 {
00145 recovery_conf_threshold = config.recovery_conf_threshold;
00146 }
00147
00148 cv::Mat GLDetector::getImage()
00149 {
00150 cv::Mat tmp;
00151 tmp = recognizer->getImage();
00152 return tmp.empty()?last_image:tmp;
00153 }
00154
00155 cv::Mat GLDetector::getDebugImage()
00156 {
00157 cv::Mat tmp;
00158 tmp = recognizer->getDebugImage();
00159 return tmp;
00160 }
00161
00162 GLDetector::~GLDetector()
00163 {
00164 cvReleaseImage(&image_);
00165 }