@@ -106,15 +106,19 @@ namespace banana {
106
106
}
107
107
108
108
auto Analyzer::IsBananaContour (Contour const & contour) const -> bool {
109
- return cv::matchShapes (contour, this ->reference_contour_ , cv::CONTOURS_MATCH_I1, 0.0 ) > this ->settings_ .match_max_score ;
109
+ if (cv::matchShapes (contour, this ->reference_contour_ , cv::CONTOURS_MATCH_I1, 0.0 ) > this ->settings_ .match_max_score ) {
110
+ return false ;
111
+ }
112
+ auto const area = cv::contourArea (contour);
113
+ return settings_.min_area < area && area < settings_.max_area ;
110
114
}
111
115
112
116
auto Analyzer::FindBananaContours (cv::Mat const & image) const -> Contours {
113
117
auto filtered_image = ColorFilter (image, settings_.filter_lower_threshold_color , settings_.filter_upper_threshold_color );
114
118
SHOW_DEBUG_IMAGE (filtered_image, " color filtered image" );
115
119
116
120
// Removing noise
117
- auto const kernel = cv::getStructuringElement (cv::MORPH_RECT, cv::Size ( 5 , 5 ) );
121
+ auto const kernel = cv::getStructuringElement (cv::MORPH_RECT, { 5 , 5 } );
118
122
cv::morphologyEx (filtered_image, filtered_image, cv::MORPH_OPEN, kernel);
119
123
SHOW_DEBUG_IMAGE (filtered_image, " morph" );
120
124
@@ -126,7 +130,7 @@ namespace banana {
126
130
cv::findContours (filtered_image, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
127
131
128
132
std::erase_if (contours, [this ](auto const & contour) -> auto {
129
- return this ->IsBananaContour (contour);
133
+ return ! this ->IsBananaContour (contour);
130
134
});
131
135
132
136
return contours;
@@ -304,7 +308,7 @@ namespace banana {
304
308
// rotate the center line back so that it fits on the image
305
309
auto const rotated_center_line = this ->RotateContour (center_line_points2i, result.estimated_center , -result.rotation_angle );
306
310
307
- cv::polylines (draw_target, rotated_center_line, false , this ->settings_ .helper_annotation_color , 10 );
311
+ cv::polylines (draw_target, rotated_center_line, false , this ->settings_ .helper_annotation_color , 3 );
308
312
}
309
313
310
314
void Analyzer::PlotPCAResult (cv::Mat& draw_target, AnalysisResult const & result) const {
@@ -321,7 +325,7 @@ namespace banana {
321
325
auto annotated_image = cv::Mat{image};
322
326
323
327
for (auto const & [n, result] : std::ranges::enumerate_view (analysis_result)) {
324
- cv::drawContours (annotated_image, std::vector{{result.contour }}, -1 , this ->settings_ .contour_annotation_color , 10 );
328
+ cv::drawContours (annotated_image, std::vector{{result.contour }}, -1 , this ->settings_ .contour_annotation_color , 3 );
325
329
326
330
if (this ->settings_ .verbose_annotations ) {
327
331
cv::putText (annotated_image, std::to_string (n), result.estimated_center + cv::Point {35 , -35 }, cv::FONT_HERSHEY_COMPLEX_SMALL, 2 , this ->settings_ .helper_annotation_color );
0 commit comments