1 #include <cv_bridge/cv_bridge.h> 2 #include <homography_optimizer/unified.h> 4 #include <opencv2/highgui/highgui.hpp> 6 #include <std_msgs/Char.h> 7 #include <vtec_msgs/TrackingResult.h> 47 const float beta,
int bbox_size_x,
int bbox_size_y)
49 cv::Point2f p1(0, 0), p2(0, bbox_size_y), p3(bbox_size_x, 0), p4(bbox_size_x, bbox_size_y);
50 VTEC::warpPoints(p1, H);
51 VTEC::warpPoints(p2, H);
52 VTEC::warpPoints(p3, H);
53 VTEC::warpPoints(p4, H);
55 geometry_msgs::Point p;
77 msg.homography[0] = H.at<
double>(0, 0);
78 msg.homography[1] = H.at<
double>(0, 1);
79 msg.homography[2] = H.at<
double>(0, 2);
80 msg.homography[3] = H.at<
double>(1, 0);
81 msg.homography[4] = H.at<
double>(1, 1);
82 msg.homography[5] = H.at<
double>(1, 2);
83 msg.homography[6] = H.at<
double>(2, 0);
84 msg.homography[7] = H.at<
double>(2, 1);
85 msg.homography[8] = H.at<
double>(2, 2);
93 H = cv::Mat::eye(3, 3, CV_64F);
101 cv::Mat reference_template;
116 cur_img = cv_bridge::toCvShare(msg,
"mono8")->image;
117 vtec_msgs::TrackingResult result_msg;
118 result_msg.header = msg->header;
120 cv::imwrite(
"/home/mestrado/datasets/" + std::to_string(
image_index++) +
".jpg",
cur_img);
121 cv::Mat H_test =
H.clone();
122 float alpha_test =
alpha;
123 float beta_test =
beta;
127 bool force_reference_image_pub =
false;
131 ROS_INFO(
"Reference Image Selected");
134 force_reference_image_pub =
true;
147 cv::Mat current_template;
153 cv::Mat out_cur_template;
154 current_template.convertTo(out_cur_template, CV_8U);
155 sensor_msgs::ImagePtr stabilized_msg =
156 cv_bridge::CvImage(std_msgs::Header(),
"mono8", out_cur_template).toImageMsg();
157 stabilized_pub_ptr->
publish(stabilized_msg);
160 results_pub_ptr->
publish(result_msg);
164 sensor_msgs::ImagePtr reference_msg =
165 cv_bridge::CvImage(std_msgs::Header(),
"mono8",
out_ref_template).toImageMsg();
166 reference_pub_ptr->
publish(reference_msg);
183 cv::putText(
cur_img,
"press S to start tracking", cv::Point(30, 60), CV_FONT_HERSHEY_SIMPLEX, 1, 255, 3);
186 sensor_msgs::ImagePtr annotated_msg = cv_bridge::CvImage(std_msgs::Header(),
"mono8",
cur_img).toImageMsg();
187 annotated_msg->header.frame_id =
"camera";
188 annotated_pub_ptr->
publish(annotated_msg);
190 catch (cv_bridge::Exception& e)
192 ROS_ERROR(
"Could not convert from '%s' to 'mono8'.", msg->encoding.c_str());
203 switch (cmd_msg.data)
215 int main(
int argc,
char** argv)
217 ros::init(argc, argv,
"ibgho_tracker_node");
222 int MAX_NB_ITERATION_PER_LEVEL;
223 int MAX_NB_PYR_LEVEL;
224 double PIXEL_KEEP_RATE;
225 std::string reference_image_path;
226 std::string image_topic =
"usb_cam/image_raw";
227 std::string homography_type =
"full";
228 bool robust_flag =
false;
229 double fb_factor = 1.0;
235 nhPrivate.
param<
int>(
"max_nb_iter_per_level", MAX_NB_ITERATION_PER_LEVEL, 5);
236 nhPrivate.
param<
int>(
"max_nb_pyr_level", MAX_NB_PYR_LEVEL, 2);
237 nhPrivate.
param<
double>(
"sampling_rate", PIXEL_KEEP_RATE, 1.0);
238 nhPrivate.
getParam(
"image_topic", image_topic);
239 nhPrivate.
getParam(
"fb_factor", fb_factor);
244 annotated_pub_ptr = &annotated_pub;
247 stabilized_pub_ptr = &stabilized_pub;
250 reference_pub_ptr = &reference_pub;
253 results_pub_ptr = &results_pub;
261 unified_optimizer->initialize(MAX_NB_ITERATION_PER_LEVEL, MAX_NB_PYR_LEVEL, PIXEL_KEEP_RATE);
265 H = cv::Mat::eye(3, 3, CV_64F);
266 H.at<
double>(0, 2) = BBOX_POS_X;
267 H.at<
double>(1, 2) = BBOX_POS_Y;
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
image_transport::Publisher * annotated_pub_ptr
VTEC::UnifiedHomographyOptimizer * unified_optimizer
void publish(const boost::shared_ptr< M > &message) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Publisher * results_pub_ptr
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Publisher advertise(const std::string &base_topic, uint32_t queue_size, bool latch=false)
void cmdCallback(const std_msgs::Char cmd_msg)
Callback for the keyboard command.
ROSCPP_DECL void spin(Spinner &spinner)
image_transport::Publisher * reference_pub_ptr
void publish(const sensor_msgs::Image &message) const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void fillTrackingMsg(vtec_msgs::TrackingResult &msg, const double score, const cv::Mat &H, const float alpha, const float beta, int bbox_size_x, int bbox_size_y)
Fills a vtec_msgs/TrackingResult message.
void imageCallback(const sensor_msgs::ImageConstPtr &msg)
Callback to handle incoming images.
ros::Time last_ref_pub_time
bool getParam(const std::string &key, std::string &s) const
void start_tracking()
Starts a tracking.
image_transport::Publisher * stabilized_pub_ptr