13 #include "visp_tracker/MovingEdgeSites.h" 14 #include "visp_tracker/KltPoints.h" 17 #include <visp/vpDisplayX.h> 18 #include <visp/vpMbEdgeKltTracker.h> 19 #include <visp/vpTime.h> 22 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 26 # include <visp/vpDetectorDataMatrixCode.h> 27 # include <visp/vpDetectorQRCode.h> 38 #include "std_msgs/Int8.h" 39 #include "std_msgs/String.h" 45 tracker_config_path_(),
50 debug_display_(false),
60 std::string model_full_path;
64 model_path_= model_path_[model_path_.length()-1]==
'/'?model_path_:model_path_+std::string(
"/");
66 tracker_config_path_ = model_full_path+
".cfg";
67 ROS_INFO(
"model full path=%s",model_full_path.c_str());
74 if (! code_message_.empty()) {
75 ROS_WARN_STREAM(
"Track only code with message: \"" << code_message_ <<
"\"");
89 for (
unsigned int i=0; i < res.
size; ++i)
105 void Node::frameCallback(
const sensor_msgs::ImageConstPtr& image,
const sensor_msgs::CameraInfoConstPtr& cam_info){
106 boost::mutex::scoped_lock(
lock_);
118 vpMbTracker* tracker;
121 vpDisplayX*
d = NULL;
123 d =
new vpDisplayX();
126 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 132 #else // ViSP >= 2.10.0. In that case we use the detectors from ViSP 133 vpDetectorBase *detector = NULL;
135 detector =
new vpDetectorQRCode;
137 detector =
new vpDetectorDataMatrixCode;
143 tracker =
new vpMbKltTracker();
145 tracker =
new vpMbEdgeKltTracker();
147 tracker =
new vpMbEdgeTracker();
150 tracker =
new vpMbEdgeKltTracker();
152 tracker->setCameraParameters(
cam_);
153 tracker->setDisplayFeatures(
true);
175 boost::mutex::scoped_lock(
lock_);
178 vpDisplay::setTitle(
I_,
"visp_auto_tracker debug display");
185 geometry_msgs::PoseStamped ps;
186 geometry_msgs::PoseWithCovarianceStamped ps_cov;
190 double t = vpTime::measureTimeMs();
191 boost::mutex::scoped_lock(
lock_);
196 tracking::TrackModel& track_model =
t_->get_state<tracking::TrackModel&>();
205 object_pose_publisher.
publish(ps);
209 if (object_pose_covariance_publisher.getNumSubscribers () > 0)
211 ps_cov.pose.pose = ps.pose;
215 for (
unsigned i = 0; i < track_model.covariance.getRows(); ++i)
217 for (
unsigned j = 0; j < track_model.covariance.getCols(); ++j)
219 unsigned idx = i * track_model.covariance.getCols() + j;
222 ps_cov.pose.covariance[idx] = track_model.covariance[i][j];
226 object_pose_covariance_publisher.publish(ps_cov);
230 if (status_publisher.getNumSubscribers () > 0)
232 std_msgs::Int8 status;
233 status.data = (
unsigned char)(*(
t_->current_state()));
234 status_publisher.publish(status);
238 if (moving_edge_sites_publisher.getNumSubscribers () > 0)
240 visp_tracker::MovingEdgeSitesPtr sites (
new visp_tracker::MovingEdgeSites);
243 if (*(
t_->current_state()) == 3) {
244 t_->updateMovingEdgeSites(sites);
248 moving_edge_sites_publisher.publish(sites);
252 if (klt_points_publisher.getNumSubscribers () > 0)
254 visp_tracker::KltPointsPtr klt (
new visp_tracker::KltPoints);
257 if (*(
t_->current_state()) == 3) {
258 t_->updateKltPoints(klt);
261 klt_points_publisher.publish(klt);
264 if (code_message_publisher.getNumSubscribers() > 0)
266 std_msgs::String message;
267 if (*(
t_->current_state()) == 3) {
268 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 269 message.data = detector->get_message();
275 message.data = std::string();
277 code_message_publisher.publish(message);
278 ROS_INFO_STREAM(
"Code with message \"" << message.data <<
"\" under tracking");
284 std::cout <<
"Tracking done in " << vpTime::measureTimeMs() - t <<
" ms" << std::endl;
std::string klt_points_topic
size_t get_code_message_index() const
void publish(const boost::shared_ptr< M > &message) const
vpCameraParameters toVispCameraParameters(const sensor_msgs::CameraInfo &cam_info)
std::string tracker_config_path_
std::string object_position_covariance_topic
std::string camera_info_topic
msm::back::state_machine< Tracker_ > Tracker
void init(std::string &config_file)
geometry_msgs::Pose toGeometryMsgsPose(const vpHomogeneousMatrix &mat)
std::string code_message_topic
Connection registerCallback(C &callback)
boost::shared_array< uint8_t > data
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::string code_message_
void set_pattern_name(std::string &name)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
std::string object_position_topic
MemoryResource get(const std::string &url)
void set_show_fps(bool show_fps)
uint32_t getNumSubscribers() const
#define ROS_INFO_STREAM(args)
void set_data_directory(std::string &dir)
std::string model_description_
std::string tracker_ref_frame
TRACKER_TYPE get_tracker_type() const
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
void set_code_message(const std::string &msg)
std::string moving_edge_sites_topic
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
vpImage< vpRGBa > toVispImageRGBa(const sensor_msgs::Image &src)
unsigned long queue_size_
DETECTOR_TYPE get_detector_type() const
std_msgs::Header image_header_
void frameCallback(const sensor_msgs::ImageConstPtr &image, const sensor_msgs::CameraInfoConstPtr &cam_info)
std::string get_mbt_cad_file() const