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 "trackerinterface.hpp" 00047 #include <blort_ros/TrackerConfidences.h> 00048 #include <blort_ros/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 namespace blort_ros 00058 { 00059 enum TrackerPublishMode 00060 { 00061 TRACKER_PUBLISH_GOOD = 0, 00062 TRACKER_PUBLISH_GOOD_AND_FAIR = 1, 00063 TRACKER_PUBLISH_ALL = 2 00064 }; 00065 00066 class GLTracker : public TrackerInterface 00067 { 00068 private: 00069 //config 00070 double conf_threshold; 00071 bool visualize_obj_pose; 00072 int publish_mode; 00073 00074 float recovery_conf_threshold; // threshold used in recovery mode to say OK to a pose proposal 00075 00076 // functionality 00077 TomGine::tgCamera::Parameter tgcam_params; 00078 TomGine::tgTimer timer; 00079 TomGine::tgPose cam_pose; 00080 Tracking::Tracker::Parameter track_params; 00081 00082 Tracking::TextureTracker tracker; // tracking module 00083 00084 //config files //FIXME 00085 std::string config_root_, ply_model_; 00086 std::string model_name, sift_file; // name of the current model 00087 std::string pose_cal; // filename with the pose calibration values 00088 00089 // Model for Tracker 00090 TomGine::tgPose trPose; // current pose of the object used by the tracker module 00091 int model_id; 00092 Tracking::movement_state movement; 00093 Tracking::quality_state quality; 00094 Tracking::confidence_state tracker_confidence; 00095 00096 // Initialise image 00097 IplImage *image; // iplimage object used be the former blort tracker module 00098 00099 // result variables 00100 TrackerConfidences tracker_confidences; 00101 geometry_msgs::Pose fixed_cam_pose; 00102 std::vector<geometry_msgs::Pose> result; 00103 00104 //reconf GUI hack 00105 bool last_reset; 00106 00107 public: 00108 GLTracker(const sensor_msgs::CameraInfo camera_info, 00109 const std::string& config_root, 00110 bool visualize_obj_pose = false); 00111 00113 virtual void recovery() {} 00114 00116 virtual void track(); 00117 00118 void reset(); 00119 00122 void reconfigure(blort_ros::TrackerConfig config); 00123 00128 void trackerControl(int code, int param = -1); 00129 00130 void resetWithPose(const geometry_msgs::Pose& new_pose); 00131 00133 TrackerConfidences getConfidences(){ return tracker_confidences; } 00134 00136 const std::vector<geometry_msgs::Pose>& getDetections(){ return result; } 00137 00139 const geometry_msgs::Pose getCameraReferencePose(){ return fixed_cam_pose; } 00140 00142 cv::Mat getImage(); 00143 00145 std::string getStatusString(); 00146 00147 void setVisualizeObjPose(bool enable){ visualize_obj_pose = enable; } 00148 00149 void setPublisMode(TrackerPublishMode mode){ publish_mode = mode; } 00150 00151 void resetParticleFilter(); 00152 00153 ~GLTracker(); 00154 00155 private: 00158 void update(); 00159 00162 void updatePoseResult(); 00163 }; 00164 } 00165 00166 #endif // GPUGLTRACKER_H