gltracker.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Modified BSD License)
00003  *
00004  *  Copyright (c) 2012, PAL Robotics, S.L.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of PAL Robotics, S.L. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * @file gpugltracker.h
00035  * @author Bence Magyar
00036  * @date April 2012
00037  * @version 0.1
00038  * @brief The GpuGLTracker class encapsulates the Tracker module of BLORT.
00039  * It provides a C++ interface but uses ROS classes for data transfer at some places.
00040  * This class is a more civilized version of the mechanism that is in Projects/Learnsifts/main.cpp.
00041  */
00042 
00043 #ifndef GPUGLTRACKER_H
00044 #define GPUGLTRACKER_H
00045 
00046 #include <blort_ros/trackerinterface.hpp>
00047 #include <blort_msgs/TrackerConfidences.h>
00048 #include <blort_msgs/TrackerCommand.h>
00049 #include <blort_ros/TrackerConfig.h>
00050 #include <geometry_msgs/Pose.h>
00051 #include <string>
00052 
00053 #include <blort/Tracker/TextureTracker.h>
00054 #include <blort/TomGine/tgModel.h>
00055 #include <blort/TomGine/tgTimer.h>
00056 
00057 #include <blort/ObjectEntry.h>
00058 
00059 namespace blort_ros
00060 {
00061   enum TrackerPublishMode
00062   {
00063     TRACKER_PUBLISH_GOOD = 0,
00064     TRACKER_PUBLISH_GOOD_AND_FAIR = 1,
00065     TRACKER_PUBLISH_ALL = 2
00066   };
00067 
00068   class GLTracker : public TrackerInterface
00069   {
00070   private:
00071     //config
00072     double conf_threshold;
00073     bool visualize_obj_pose;
00074     int publish_mode;
00075 
00076     float recovery_conf_threshold; // threshold used in recovery mode to say OK to a pose proposal
00077 
00078     // functionality
00079     TomGine::tgCamera::Parameter tgcam_params;
00080     TomGine::tgTimer timer;
00081     TomGine::tgPose cam_pose;
00082     Tracking::Tracker::Parameter track_params;
00083 
00084     Tracking::TextureTracker tracker;   // tracking module
00085 
00086     //config files
00087     std::string config_root_;
00088     std::string pose_cal;   // filename with the pose calibration values
00089 
00090     // Model for Tracker
00091     std::vector<blort::ObjectEntry> objects_;
00092     std::map<std::string, int> model_ids;
00093 
00094     // Protection mutex for multi-threaded access to the model/poses
00095     boost::mutex models_mutex;
00096 
00097     // Initialise image
00098     IplImage *image; // iplimage object used be the former blort tracker module
00099 
00100     // result variables
00101     //std::vector< boost::shared_ptr<blort_msgs::TrackerConfidences> > tracker_confidences;
00102     geometry_msgs::Pose fixed_cam_pose;
00103     std::map<std::string, geometry_msgs::Pose> result;
00104 
00105     //reconf GUI hack
00106     bool last_reset;
00107 
00108   public:
00109     GLTracker(const sensor_msgs::CameraInfo camera_info,
00110               const std::string& config_root,
00111               bool visualize_obj_pose = false);
00112 
00114     virtual void recovery() {}
00115 
00117     virtual void track();
00118 
00119     void reset(const std::vector<std::string> & params = std::vector<std::string>());
00120 
00123     void reconfigure(blort_ros::TrackerConfig config);
00124 
00129     void trackerControl(uint8_t code, const std::vector<std::string> & params);
00130 
00131     void resetWithPose(std::string obj_id, const geometry_msgs::Pose& new_pose);
00132 
00134     //const std::vector< boost::shared_ptr<blort_msgs::TrackerConfidences> > & getConfidences(){ return tracker_confidences; }
00135 
00137     std::map<std::string, geometry_msgs::Pose>& getDetections(){ return result; }
00138 
00140     const geometry_msgs::Pose getCameraReferencePose(){ return fixed_cam_pose; }
00141 
00143     cv::Mat getImage();
00144 
00146     const std::string & getModelName(size_t i) { return objects_[i].name; }
00147 
00148     void setVisualizeObjPose(bool enable){ visualize_obj_pose = enable; }
00149 
00150     void setPublishMode(TrackerPublishMode mode){ publish_mode = mode; }
00151 
00152     TrackerPublishMode getPublishMode() { return (TrackerPublishMode)publish_mode; }
00153 
00154     virtual void switchToTracking(const std::string& id);
00155 
00156     virtual void switchToRecovery(const std::string& id);
00157 
00158     virtual void switchTracking(const std::vector<std::string> & params);
00159 
00160     bool isTracked(const std::string& id);
00161     void setTracked(const std::string& id, bool tracked);
00162 
00163     const std::vector<blort::ObjectEntry>& getObjects() const;
00164 
00165     void enableAllTracking(bool enable);
00166 
00167     ~GLTracker();
00168 
00169   private:
00172     void update();
00173 
00176     void updatePoseResult(std::string i);
00177 
00178     void resetParticleFilter(std::string id);
00179 
00180     blort::ObjectEntry& getObjEntryByName(const std::string& name);
00181   };
00182 }
00183 
00184 #endif // GPUGLTRACKER_H


blort_ros
Author(s): Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:39