@@ -42,6 +42,11 @@ void TemplateComparator::analyze()
4242 double score = comp (lhs_roi, rhs_roi, param_.method );
4343 Result res = Result { .box = roi_, .score = score };
4444 add_results ({ std::move (res) }, param_.threshold );
45+
46+ if (debug_draw_) {
47+ auto draw = draw_result (roi_, score);
48+ handle_draw (draw);
49+ }
4550 }
4651
4752 cherry_pick ();
@@ -101,4 +106,34 @@ bool TemplateComparator::comp_score(double s1, double s2) const
101106 return low_score_better_ ? s1 > s2 : s1 < s2;
102107}
103108
109+ cv::Mat TemplateComparator::draw_result (const cv::Rect& roi, double score) const
110+ {
111+ int width = image_.cols + rhs_image_.cols ;
112+ int height = std::max (image_.rows , rhs_image_.rows );
113+ cv::Mat draw = cv::Mat::zeros (height, width, image_.type ());
114+
115+ image_.copyTo (draw (cv::Rect (0 , 0 , image_.cols , image_.rows )));
116+ rhs_image_.copyTo (draw (cv::Rect (image_.cols , 0 , rhs_image_.cols , rhs_image_.rows )));
117+
118+ const cv::Scalar roi_color (0 , 255 , 0 );
119+ const cv::Scalar score_color (0 , 0 , 255 );
120+
121+ cv::putText (draw, name_, cv::Point (5 , image_.rows - 5 ), cv::FONT_HERSHEY_SIMPLEX, 1 , roi_color, 2 );
122+
123+ cv::rectangle (draw, roi, roi_color, 1 );
124+ std::string roi_flag = std::format (" ROI: [{}, {}, {}, {}]" , roi.x , roi.y , roi.width , roi.height );
125+ cv::putText (draw, roi_flag, cv::Point (roi.x , roi.y - 5 ), cv::FONT_HERSHEY_PLAIN, 1.2 , roi_color, 1 );
126+
127+ cv::Rect rhs_roi (roi.x + image_.cols , roi.y , roi.width , roi.height );
128+ cv::rectangle (draw, rhs_roi, roi_color, 1 );
129+ cv::putText (draw, roi_flag, cv::Point (rhs_roi.x , rhs_roi.y - 5 ), cv::FONT_HERSHEY_PLAIN, 1.2 , roi_color, 1 );
130+
131+ cv::line (draw, roi.tl (), rhs_roi.tl (), roi_color, 1 );
132+
133+ std::string score_flag = std::format (" Score: {:.3f}" , score);
134+ cv::putText (draw, score_flag, cv::Point (roi.x , roi.y + roi.height + 30 ), cv::FONT_HERSHEY_SIMPLEX, 1 , score_color, 2 );
135+
136+ return draw;
137+ }
138+
104139MAA_VISION_NS_END
0 commit comments