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 "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
00049 using namespace blort_ros;
00050
00051 GLDetector::GLDetector(const sensor_msgs::CameraInfo& camera_info, const std::string& config_root)
00052 {
00053
00054
00055
00056 rec3dcounter = 0;
00057 recovery_conf_threshold = 0.05;
00058
00059
00060 std::string tracking_ini(pal_blort::addRoot("bin/tracking.ini", config_root));
00061 std::string ply_model;
00062 GetPlySiftFilenames(tracking_ini.c_str(), ply_model, sift_file, model_name);
00063 recognizer = boost::shared_ptr<blortRecognizer::Recognizer3D>(
00064 new blortRecognizer::Recognizer3D(blortRecognizer::CameraParameter(camera_info), config_root, true));
00065 recognizer->loadModelFromFile(sift_file);
00066 image_ = cvCreateImage( cvSize(camera_info.width, camera_info.height), 8, 3 );
00067 }
00068
00069 bool GLDetector::recovery(const cv::Mat& image,
00070 blort_ros::RecoveryCall::Response &resp)
00071 {
00072 last_image = image;
00073 *image_ = last_image;
00074
00075 return recoveryWithLast(resp);
00076 }
00077
00078 bool GLDetector::recoveryWithLast(blort_ros::RecoveryCall::Response &resp)
00079 {
00080 double ticksBefore = cv::getTickCount();
00081
00082 TomGine::tgPose recPose;
00083 float conf;
00084 ROS_INFO("\n");
00085 recognizer->recognize(image_, recPose, conf);
00086
00087 ROS_INFO("object conf: %f", conf);
00088 ROS_WARN("Tried to recover for the %d. time.", rec3dcounter++);
00089 ROS_INFO("Recovery execution time: %f ms",
00090 1000*(cv::getTickCount() - ticksBefore)/cv::getTickFrequency());
00091
00092
00093 if(conf > recovery_conf_threshold)
00094 {
00095 resp.Pose = pal_blort::tgPose2RosPose(recPose);
00096 return true;
00097 }
00098 else
00099 {
00100 ROS_INFO_STREAM("GLDetector::recoveryWithLast: returning false because confidence <= " << recovery_conf_threshold);
00101 return false;
00102 }
00103 }
00104
00105 void GLDetector::reconfigure(blort_ros::DetectorConfig config)
00106 {
00107 recovery_conf_threshold = config.recovery_conf_threshold;
00108 }
00109
00110 cv::Mat GLDetector::getImage()
00111 {
00112 cv::Mat tmp;
00113 tmp = recognizer->getImage();
00114 return tmp.empty()?last_image:tmp;
00115 }
00116
00117 cv::Mat GLDetector::getDebugImage()
00118 {
00119 cv::Mat tmp;
00120 tmp = recognizer->getDebugImage();
00121 return tmp;
00122 }
00123
00124 GLDetector::~GLDetector()
00125 {
00126 cvReleaseImage(&image_);
00127 }