13 #include "visp_tracker/MovingEdgeSites.h" 14 #include "visp_tracker/KltPoints.h" 17 #include <visp3/gui/vpDisplayX.h> 18 #include <visp3/mbt/vpMbGenericTracker.h> 19 #include <visp3/core/vpTime.h> 22 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 26 # include <visp3/detection/vpDetectorDataMatrixCode.h> 27 # include <visp3/detection/vpDetectorQRCode.h> 38 #include "std_msgs/Int8.h" 39 #include "std_msgs/String.h" 45 tracker_config_path_(),
51 debug_display_(false),
61 std::string model_full_path;
66 model_path_= model_path_[model_path_.length()-1]==
'/'?model_path_:model_path_+std::string(
"/");
68 tracker_config_path_ = model_full_path+
".cfg";
69 ROS_INFO(
"model full path=%s",model_full_path.c_str());
76 if (! code_message_.empty()) {
77 ROS_WARN_STREAM(
"Track only code with message: \"" << code_message_ <<
"\"");
91 for (
unsigned int i=0; i < res.
size; ++i)
107 void Node::frameCallback(
const sensor_msgs::ImageConstPtr& image,
const sensor_msgs::CameraInfoConstPtr& cam_info){
108 boost::mutex::scoped_lock(
lock_);
120 vpMbTracker* tracker;
123 vpDisplayX*
d = NULL;
125 d =
new vpDisplayX();
128 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 134 #else // ViSP >= 2.10.0. In that case we use the detectors from ViSP 135 vpDetectorBase *detector = NULL;
137 detector =
new vpDetectorQRCode;
139 detector =
new vpDetectorDataMatrixCode;
143 int trackerType = vpMbGenericTracker::EDGE_TRACKER | vpMbGenericTracker::KLT_TRACKER;
144 tracker =
new vpMbGenericTracker(1, trackerType);
145 tracker->setCameraParameters(
cam_);
146 tracker->setDisplayFeatures(
true);
168 boost::mutex::scoped_lock(
lock_);
171 vpDisplay::setTitle(
I_,
"visp_auto_tracker debug display");
178 geometry_msgs::PoseStamped ps;
179 geometry_msgs::PoseWithCovarianceStamped ps_cov;
183 double t = vpTime::measureTimeMs();
184 boost::mutex::scoped_lock(
lock_);
189 tracking::TrackModel& track_model =
t_->get_state<tracking::TrackModel&>();
198 object_pose_publisher.
publish(ps);
202 if (object_pose_covariance_publisher.getNumSubscribers () > 0)
204 ps_cov.pose.pose = ps.pose;
208 for (
unsigned i = 0; i < track_model.covariance.getRows(); ++i)
210 for (
unsigned j = 0; j < track_model.covariance.getCols(); ++j)
212 unsigned idx = i * track_model.covariance.getCols() + j;
215 ps_cov.pose.covariance[idx] = track_model.covariance[i][j];
219 object_pose_covariance_publisher.publish(ps_cov);
223 if (status_publisher.getNumSubscribers () > 0)
225 std_msgs::Int8 status;
226 status.data = (
unsigned char)(*(
t_->current_state()));
227 status_publisher.publish(status);
231 if (moving_edge_sites_publisher.getNumSubscribers () > 0)
233 visp_tracker::MovingEdgeSitesPtr sites (
new visp_tracker::MovingEdgeSites);
236 if (*(
t_->current_state()) == 3) {
237 t_->updateMovingEdgeSites(sites);
241 moving_edge_sites_publisher.publish(sites);
245 if (klt_points_publisher.getNumSubscribers () > 0)
247 visp_tracker::KltPointsPtr klt (
new visp_tracker::KltPoints);
250 if (*(
t_->current_state()) == 3) {
251 t_->updateKltPoints(klt);
254 klt_points_publisher.publish(klt);
257 if (code_message_publisher.getNumSubscribers() > 0)
259 std_msgs::String message;
260 if (*(
t_->current_state()) == 3) {
261 #if VISP_VERSION_INT < VP_VERSION_INT(2,10,0) 262 message.data = detector->get_message();
268 message.data = std::string();
270 code_message_publisher.publish(message);
271 ROS_INFO_STREAM(
"Code with message \"" << message.data <<
"\" under tracking");
277 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_
#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
std::string tracker_ref_frame_
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