blob: 85cf452ab643dbaed99501f3aecbd60e83793231 [file] [log] [blame]
Parker Schuh2a1447c2019-02-17 00:25:29 -08001#include "y2019/vision/target_finder.h"
2
3#include "aos/vision/blob/hierarchical_contour_merge.h"
4
5using namespace aos::vision;
6
7namespace y2019 {
8namespace vision {
9
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080010TargetFinder::TargetFinder() : target_template_(Target::MakeTemplate()) {}
Parker Schuh2a1447c2019-02-17 00:25:29 -080011
12aos::vision::RangeImage TargetFinder::Threshold(aos::vision::ImagePtr image) {
13 const uint8_t threshold_value = GetThresholdValue();
14 return aos::vision::DoThreshold(image, [&](aos::vision::PixelRef &px) {
15 if (px.g > threshold_value && px.b > threshold_value &&
16 px.r > threshold_value) {
17 return true;
18 }
19 return false;
20 });
21}
22
23// Filter blobs on size.
24void TargetFinder::PreFilter(BlobList *imgs) {
25 imgs->erase(
26 std::remove_if(imgs->begin(), imgs->end(),
27 [](RangeImage &img) {
28 // We can drop images with a small number of
29 // pixels, but images
30 // must be over 20px or the math will have issues.
31 return (img.npixels() < 100 || img.height() < 25);
32 }),
33 imgs->end());
34}
35
Ben Fredricksonf7b68522019-03-02 21:19:42 -080036ContourNode* TargetFinder::GetContour(const RangeImage &blob) {
37 alloc_.reset();
38 return RangeImgToContour(blob, &alloc_);
39}
40
Ben Fredricksonec575822019-03-02 22:03:20 -080041// TODO(ben): These values will be moved into the constants.h file.
Ben Fredricksonf7b68522019-03-02 21:19:42 -080042namespace {
43
Ben Fredricksonec575822019-03-02 22:03:20 -080044constexpr double f_x = 481.4957;
45constexpr double c_x = 341.215;
46constexpr double f_y = 484.314;
47constexpr double c_y = 251.29;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080048
Ben Fredricksonec575822019-03-02 22:03:20 -080049constexpr double f_x_prime = 363.1424;
50constexpr double c_x_prime = 337.9895;
51constexpr double f_y_prime = 366.4837;
52constexpr double c_y_prime = 240.0702;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080053
Ben Fredricksonec575822019-03-02 22:03:20 -080054constexpr double k_1 = -0.2739;
55constexpr double k_2 = 0.01583;
56constexpr double k_3 = 0.04201;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080057
58constexpr int iterations = 7;
59
60}
61
Austin Schuhe5015972019-03-09 17:47:34 -080062::Eigen::Vector2f UnWarpPoint(const Point point) {
Ben Fredricksonec575822019-03-02 22:03:20 -080063 const double x0 = ((double)point.x - c_x) / f_x;
64 const double y0 = ((double)point.y - c_y) / f_y;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080065 double x = x0;
66 double y = y0;
67 for (int i = 0; i < iterations; i++) {
68 const double r_sqr = x * x + y * y;
69 const double coeff =
Ben Fredricksonec575822019-03-02 22:03:20 -080070 1.0 + r_sqr * (k_1 + k_2 * r_sqr * (1.0 + k_3 * r_sqr));
Ben Fredricksonf7b68522019-03-02 21:19:42 -080071 x = x0 / coeff;
72 y = y0 / coeff;
73 }
Austin Schuhe5015972019-03-09 17:47:34 -080074 const double nx = x * f_x_prime + c_x_prime;
75 const double ny = y * f_y_prime + c_y_prime;
76 return ::Eigen::Vector2f(nx, ny);
Ben Fredricksonf7b68522019-03-02 21:19:42 -080077}
78
Austin Schuhe5015972019-03-09 17:47:34 -080079::std::vector<::Eigen::Vector2f> TargetFinder::UnWarpContour(
80 ContourNode *start) const {
81 ::std::vector<::Eigen::Vector2f> result;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080082 ContourNode *node = start;
83 while (node->next != start) {
Austin Schuhe5015972019-03-09 17:47:34 -080084 result.push_back(UnWarpPoint(node->pt));
Ben Fredricksonf7b68522019-03-02 21:19:42 -080085 node = node->next;
86 }
Austin Schuhe5015972019-03-09 17:47:34 -080087 result.push_back(UnWarpPoint(node->pt));
88 return result;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080089}
90
Parker Schuh2a1447c2019-02-17 00:25:29 -080091// TODO: Try hierarchical merge for this.
92// Convert blobs into polygons.
93std::vector<aos::vision::Segment<2>> TargetFinder::FillPolygon(
Austin Schuhe5015972019-03-09 17:47:34 -080094 const ::std::vector<::Eigen::Vector2f> &contour, bool verbose) {
Parker Schuh2a1447c2019-02-17 00:25:29 -080095 if (verbose) printf("Process Polygon.\n");
Parker Schuh2a1447c2019-02-17 00:25:29 -080096
Austin Schuhe5015972019-03-09 17:47:34 -080097 ::std::vector<::Eigen::Vector2f> slopes;
Parker Schuh2a1447c2019-02-17 00:25:29 -080098
99 // Collect all slopes from the contour.
Austin Schuhe5015972019-03-09 17:47:34 -0800100 ::Eigen::Vector2f previous_point = contour[0];
101 for (size_t i = 0; i < contour.size(); ++i) {
102 ::Eigen::Vector2f next_point = contour[(i + 1) % contour.size()];
Parker Schuh2a1447c2019-02-17 00:25:29 -0800103
Austin Schuhe5015972019-03-09 17:47:34 -0800104 slopes.push_back(next_point - previous_point);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800105
Austin Schuhe5015972019-03-09 17:47:34 -0800106 previous_point = next_point;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800107 }
108
Austin Schuhe5015972019-03-09 17:47:34 -0800109 const int num_points = slopes.size();
110 auto get_pt = [&slopes, num_points](int i) {
111 return slopes[(i + num_points * 2) % num_points];
Austin Schuh335eef12019-03-02 17:04:17 -0800112 };
Parker Schuh2a1447c2019-02-17 00:25:29 -0800113
Austin Schuh6a484962019-03-09 21:51:27 -0800114 // Bigger objects should be more filtered. Filter roughly proportional to the
115 // perimeter of the object.
116 const int range = slopes.size() / 50;
117 if (verbose) printf("Corner range: %d.\n", range);
118
Austin Schuhe5015972019-03-09 17:47:34 -0800119 ::std::vector<::Eigen::Vector2f> filtered_slopes = slopes;
Austin Schuh335eef12019-03-02 17:04:17 -0800120 // Three box filter makith a guassian?
121 // Run gaussian filter over the slopes 3 times. That'll get us pretty close
122 // to running a gausian over it.
123 for (int k = 0; k < 3; ++k) {
Austin Schuh6a484962019-03-09 21:51:27 -0800124 const int window_size = ::std::max(2, range);
Austin Schuhe5015972019-03-09 17:47:34 -0800125 for (size_t i = 0; i < slopes.size(); ++i) {
126 ::Eigen::Vector2f a = ::Eigen::Vector2f::Zero();
Parker Schuh2a1447c2019-02-17 00:25:29 -0800127 for (int j = -window_size; j <= window_size; ++j) {
Austin Schuhe5015972019-03-09 17:47:34 -0800128 ::Eigen::Vector2f p = get_pt(j + i);
129 a += p;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800130 }
Austin Schuhe5015972019-03-09 17:47:34 -0800131 a /= (window_size * 2 + 1);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800132
Austin Schuhe5015972019-03-09 17:47:34 -0800133 filtered_slopes[i] = a;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800134 }
Austin Schuhe5015972019-03-09 17:47:34 -0800135 slopes = filtered_slopes;
Austin Schuh335eef12019-03-02 17:04:17 -0800136 }
Austin Schuh6a484962019-03-09 21:51:27 -0800137 if (verbose) printf("Point count: %zu.\n", slopes.size());
Parker Schuh2a1447c2019-02-17 00:25:29 -0800138
Austin Schuh6a484962019-03-09 21:51:27 -0800139 ::std::vector<float> corner_metric(slopes.size(), 0.0);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800140
Austin Schuh6a484962019-03-09 21:51:27 -0800141 for (size_t i = 0; i < slopes.size(); ++i) {
142 const ::Eigen::Vector2f a = get_pt(i - ::std::max(3, range));
143 const ::Eigen::Vector2f b = get_pt(i + ::std::max(3, range));
144 corner_metric[i] = (a - b).squaredNorm();
145 }
146
147 // We want to find the Nth highest peaks.
148 // Clever algorithm: Find the highest point. Then, walk forwards and
149 // backwards to find the next valley each direction which is over x% lower
150 // than the peak.
151 // We want to ignore those points in the future. Set them to 0.
152 // Repeat until we've found the Nth highest peak.
Parker Schuh2a1447c2019-02-17 00:25:29 -0800153
154 // Find all centers of corners.
Austin Schuhe5015972019-03-09 17:47:34 -0800155 // Because they round, multiple slopes may be a corner.
156 ::std::vector<size_t> edges;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800157
Austin Schuh6a484962019-03-09 21:51:27 -0800158 constexpr float peak_acceptance_ratio = 0.16;
159 constexpr float valley_ratio = 0.75;
160
161 float highest_peak_value = 0.0;
162
163 // Nth higest points.
Austin Schuh32ffac22019-03-09 22:42:02 -0800164 while (edges.size() < 5) {
Austin Schuh6a484962019-03-09 21:51:27 -0800165 const ::std::vector<float>::iterator max_element =
166 ::std::max_element(corner_metric.begin(), corner_metric.end());
167 const size_t highest_index =
168 ::std::distance(corner_metric.begin(), max_element);
169 const float max_value = *max_element;
Austin Schuh32ffac22019-03-09 22:42:02 -0800170 if (edges.size() == 0) {
Austin Schuh6a484962019-03-09 21:51:27 -0800171 highest_peak_value = max_value;
172 }
Austin Schuh32ffac22019-03-09 22:42:02 -0800173 if (max_value < highest_peak_value * peak_acceptance_ratio &&
174 edges.size() == 4) {
Austin Schuh6a484962019-03-09 21:51:27 -0800175 if (verbose)
176 printf("Rejecting index: %zu, %f (%f %%)\n", highest_index, max_value,
177 max_value / highest_peak_value);
178 break;
179 }
180 const float valley_value = max_value * valley_ratio;
181
182 if (verbose)
183 printf("Highest index: %zu, %f (%f %%)\n", highest_index, max_value,
184 max_value / highest_peak_value);
185
Austin Schuh32ffac22019-03-09 22:42:02 -0800186 bool foothill = false;
Austin Schuh6a484962019-03-09 21:51:27 -0800187 {
188 float min_value = max_value;
189 size_t fwd_index = (highest_index + 1) % corner_metric.size();
190 while (true) {
191 const float current_value = corner_metric[fwd_index];
Austin Schuh32ffac22019-03-09 22:42:02 -0800192
193 if (current_value == -1.0) {
194 if (min_value >= valley_value) {
195 if (verbose) printf("Foothill\n");
196 foothill = true;
197 }
198 break;
199 }
200
Austin Schuh6a484962019-03-09 21:51:27 -0800201 min_value = ::std::min(current_value, min_value);
202
Austin Schuh32ffac22019-03-09 22:42:02 -0800203 if (min_value < valley_value && current_value > min_value) {
Austin Schuh6a484962019-03-09 21:51:27 -0800204 break;
205 }
206 // Kill!!!
Austin Schuh32ffac22019-03-09 22:42:02 -0800207 corner_metric[fwd_index] = -1.0;
Austin Schuh6a484962019-03-09 21:51:27 -0800208
209 fwd_index = (fwd_index + 1) % corner_metric.size();
Parker Schuh2a1447c2019-02-17 00:25:29 -0800210 }
211 }
Austin Schuh6a484962019-03-09 21:51:27 -0800212
213 {
214 float min_value = max_value;
215 size_t rev_index =
216 (highest_index - 1 + corner_metric.size()) % corner_metric.size();
217 while (true) {
218 const float current_value = corner_metric[rev_index];
Austin Schuh32ffac22019-03-09 22:42:02 -0800219
220 if (current_value == -1.0) {
221 if (min_value >= valley_value) {
222 if (verbose) printf("Foothill\n");
223 foothill = true;
224 }
225 break;
226 }
227
Austin Schuh6a484962019-03-09 21:51:27 -0800228 min_value = ::std::min(current_value, min_value);
229
Austin Schuh32ffac22019-03-09 22:42:02 -0800230 if (min_value < valley_value && current_value > min_value) {
Austin Schuh6a484962019-03-09 21:51:27 -0800231 break;
232 }
233 // Kill!!!
Austin Schuh32ffac22019-03-09 22:42:02 -0800234 corner_metric[rev_index] = -1.0;
Austin Schuh6a484962019-03-09 21:51:27 -0800235
236 rev_index =
237 (rev_index - 1 + corner_metric.size()) % corner_metric.size();
238 }
Parker Schuh2a1447c2019-02-17 00:25:29 -0800239 }
Austin Schuh6a484962019-03-09 21:51:27 -0800240
Austin Schuh32ffac22019-03-09 22:42:02 -0800241 *max_element = -1.0;
242 if (!foothill) {
243 edges.push_back(highest_index);
244 }
Parker Schuh2a1447c2019-02-17 00:25:29 -0800245 }
246
Austin Schuh6a484962019-03-09 21:51:27 -0800247 ::std::sort(edges.begin(), edges.end());
Parker Schuh2a1447c2019-02-17 00:25:29 -0800248
249 if (verbose) printf("Edge Count (%zu).\n", edges.size());
250
Parker Schuh2a1447c2019-02-17 00:25:29 -0800251 // Run best-fits over each line segment.
Austin Schuhe5015972019-03-09 17:47:34 -0800252 ::std::vector<Segment<2>> seg_list;
Austin Schuh6a484962019-03-09 21:51:27 -0800253 if (edges.size() >= 3) {
Austin Schuhe5015972019-03-09 17:47:34 -0800254 for (size_t i = 0; i < edges.size(); ++i) {
255 // Include the corners in both line fits.
256 const size_t segment_start_index = edges[i];
257 const size_t segment_end_index =
258 (edges[(i + 1) % edges.size()] + 1) % contour.size();
Parker Schuh2a1447c2019-02-17 00:25:29 -0800259 float mx = 0.0;
260 float my = 0.0;
261 int n = 0;
Austin Schuhe5015972019-03-09 17:47:34 -0800262 for (size_t j = segment_start_index; j != segment_end_index;
263 (j = (j + 1) % contour.size())) {
264 mx += contour[j].x();
265 my += contour[j].y();
Parker Schuh2a1447c2019-02-17 00:25:29 -0800266 ++n;
267 // (x - [x] / N) ** 2 = [x * x] - 2 * [x] * [x] / N + [x] * [x] / N / N;
268 }
269 mx /= n;
270 my /= n;
271
272 float xx = 0.0;
273 float xy = 0.0;
274 float yy = 0.0;
Austin Schuhe5015972019-03-09 17:47:34 -0800275 for (size_t j = segment_start_index; j != segment_end_index;
276 (j = (j + 1) % contour.size())) {
277 const float x = contour[j].x() - mx;
278 const float y = contour[j].y() - my;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800279 xx += x * x;
280 xy += x * y;
281 yy += y * y;
282 }
283
284 // TODO: Extract common to hierarchical merge.
Austin Schuh335eef12019-03-02 17:04:17 -0800285 const float neg_b_over_2 = (xx + yy) / 2.0;
286 const float c = (xx * yy - xy * xy);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800287
Austin Schuh335eef12019-03-02 17:04:17 -0800288 const float sqr = sqrt(neg_b_over_2 * neg_b_over_2 - c);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800289
290 {
Austin Schuh335eef12019-03-02 17:04:17 -0800291 const float lam = neg_b_over_2 + sqr;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800292 float x = xy;
293 float y = lam - xx;
294
Austin Schuh335eef12019-03-02 17:04:17 -0800295 const float norm = hypot(x, y);
Parker Schuh2a1447c2019-02-17 00:25:29 -0800296 x /= norm;
297 y /= norm;
298
299 seg_list.push_back(
300 Segment<2>(Vector<2>(mx, my), Vector<2>(mx + x, my + y)));
301 }
302
303 /* Characteristic polynomial
304 1 lam^2 - (xx + yy) lam + (xx * yy - xy * xy) = 0
305
306 [a b]
307 [c d]
308
309 // covariance matrix.
310 [xx xy] [nx]
311 [xy yy] [ny]
312 */
313 }
314 }
315 if (verbose) printf("Poly Count (%zu).\n", seg_list.size());
316 return seg_list;
317}
318
319// Convert segments into target components (left or right)
320std::vector<TargetComponent> TargetFinder::FillTargetComponentList(
Austin Schuh32ffac22019-03-09 22:42:02 -0800321 const std::vector<std::vector<Segment<2>>> &seg_list, bool verbose) {
Parker Schuh2a1447c2019-02-17 00:25:29 -0800322 std::vector<TargetComponent> list;
323 TargetComponent new_target;
Austin Schuh335eef12019-03-02 17:04:17 -0800324 for (const std::vector<Segment<2>> &poly : seg_list) {
Parker Schuh2a1447c2019-02-17 00:25:29 -0800325 // Reject missized pollygons for now. Maybe rectify them here in the future;
Austin Schuh9f859ca2019-03-06 20:46:01 -0800326 if (poly.size() != 4) {
327 continue;
328 }
Austin Schuh32ffac22019-03-09 22:42:02 -0800329 ::std::vector<Vector<2>> corners;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800330 for (size_t i = 0; i < 4; ++i) {
Austin Schuh9f859ca2019-03-06 20:46:01 -0800331 Vector<2> corner = poly[i].Intersect(poly[(i + 1) % 4]);
332 if (::std::isnan(corner.x()) || ::std::isnan(corner.y())) {
333 break;
334 }
335 corners.push_back(corner);
336 }
337 if (corners.size() != 4) {
338 continue;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800339 }
340
341 // Select the closest two points. Short side of the rectangle.
342 double min_dist = -1;
Austin Schuh32ffac22019-03-09 22:42:02 -0800343 ::std::pair<size_t, size_t> closest;
Parker Schuh2a1447c2019-02-17 00:25:29 -0800344 for (size_t i = 0; i < 4; ++i) {
345 size_t next = (i + 1) % 4;
346 double nd = corners[i].SquaredDistanceTo(corners[next]);
347 if (min_dist == -1 || nd < min_dist) {
348 min_dist = nd;
349 closest.first = i;
350 closest.second = next;
351 }
352 }
353
354 // Verify our top is above the bottom.
355 size_t bot_index = closest.first;
356 size_t top_index = (closest.first + 2) % 4;
357 if (corners[top_index].y() < corners[bot_index].y()) {
358 closest.first = top_index;
359 closest.second = (top_index + 1) % 4;
360 }
361
362 // Find the major axis.
363 size_t far_first = (closest.first + 2) % 4;
364 size_t far_second = (closest.second + 2) % 4;
365 Segment<2> major_axis(
366 (corners[closest.first] + corners[closest.second]) * 0.5,
367 (corners[far_first] + corners[far_second]) * 0.5);
368 if (major_axis.AsVector().AngleToZero() > M_PI / 180.0 * 120.0 ||
369 major_axis.AsVector().AngleToZero() < M_PI / 180.0 * 60.0) {
370 // Target is angled way too much, drop it.
371 continue;
372 }
373
374 // organize the top points.
375 Vector<2> topA = corners[closest.first] - major_axis.B();
376 new_target.major_axis = major_axis;
377 if (major_axis.AsVector().AngleToZero() > M_PI / 2.0) {
378 // We have a left target since we are leaning positive.
379 new_target.is_right = false;
380 if (topA.AngleTo(major_axis.AsVector()) > 0.0) {
381 // And our A point is left of the major axis.
382 new_target.inside = corners[closest.second];
383 new_target.top = corners[closest.first];
384 } else {
385 // our A point is to the right of the major axis.
386 new_target.inside = corners[closest.first];
387 new_target.top = corners[closest.second];
388 }
389 } else {
390 // We have a right target since we are leaning negative.
391 new_target.is_right = true;
392 if (topA.AngleTo(major_axis.AsVector()) > 0.0) {
393 // And our A point is left of the major axis.
394 new_target.inside = corners[closest.first];
395 new_target.top = corners[closest.second];
396 } else {
397 // our A point is to the right of the major axis.
398 new_target.inside = corners[closest.second];
399 new_target.top = corners[closest.first];
400 }
401 }
402
403 // organize the top points.
404 Vector<2> botA = corners[far_first] - major_axis.A();
405 if (major_axis.AsVector().AngleToZero() > M_PI / 2.0) {
406 // We have a right target since we are leaning positive.
407 if (botA.AngleTo(major_axis.AsVector()) < M_PI) {
408 // And our A point is left of the major axis.
409 new_target.outside = corners[far_second];
410 new_target.bottom = corners[far_first];
411 } else {
412 // our A point is to the right of the major axis.
413 new_target.outside = corners[far_first];
414 new_target.bottom = corners[far_second];
415 }
416 } else {
417 // We have a left target since we are leaning negative.
418 if (botA.AngleTo(major_axis.AsVector()) < M_PI) {
419 // And our A point is left of the major axis.
420 new_target.outside = corners[far_first];
421 new_target.bottom = corners[far_second];
422 } else {
423 // our A point is to the right of the major axis.
424 new_target.outside = corners[far_second];
425 new_target.bottom = corners[far_first];
426 }
427 }
428
429 // This piece of the target should be ready now.
430 list.emplace_back(new_target);
Austin Schuh32ffac22019-03-09 22:42:02 -0800431 if (verbose) printf("Happy with a target\n");
Parker Schuh2a1447c2019-02-17 00:25:29 -0800432 }
433
434 return list;
435}
436
437// Match components into targets.
438std::vector<Target> TargetFinder::FindTargetsFromComponents(
439 const std::vector<TargetComponent> component_list, bool verbose) {
440 std::vector<Target> target_list;
441 using namespace aos::vision;
442 if (component_list.size() < 2) {
443 // We don't enough parts for a target.
444 return target_list;
445 }
446
447 for (size_t i = 0; i < component_list.size(); i++) {
448 const TargetComponent &a = component_list[i];
449 for (size_t j = 0; j < i; j++) {
450 bool target_valid = false;
451 Target new_target;
452 const TargetComponent &b = component_list[j];
453
454 // Reject targets that are too far off vertically.
455 Vector<2> a_center = a.major_axis.Center();
456 if (a_center.y() > b.bottom.y() || a_center.y() < b.top.y()) {
457 continue;
458 }
459 Vector<2> b_center = b.major_axis.Center();
460 if (b_center.y() > a.bottom.y() || b_center.y() < a.top.y()) {
461 continue;
462 }
463
464 if (a.is_right && !b.is_right) {
465 if (a.top.x() > b.top.x()) {
466 new_target.right = a;
467 new_target.left = b;
468 target_valid = true;
469 }
470 } else if (!a.is_right && b.is_right) {
471 if (b.top.x() > a.top.x()) {
472 new_target.right = b;
473 new_target.left = a;
474 target_valid = true;
475 }
476 }
477 if (target_valid) {
478 target_list.emplace_back(new_target);
479 }
480 }
481 }
482 if (verbose) printf("Possible Target: %zu.\n", target_list.size());
483 return target_list;
484}
485
486std::vector<IntermediateResult> TargetFinder::FilterResults(
Ben Fredricksona8c3d552019-03-03 14:14:53 -0800487 const std::vector<IntermediateResult> &results, uint64_t print_rate) {
Parker Schuh2a1447c2019-02-17 00:25:29 -0800488 std::vector<IntermediateResult> filtered;
489 for (const IntermediateResult &res : results) {
490 if (res.solver_error < 75.0) {
491 filtered.emplace_back(res);
492 }
493 }
Ben Fredricksona8c3d552019-03-03 14:14:53 -0800494 frame_count_++;
495 if (!filtered.empty()) {
496 valid_result_count_++;
497 }
498 if (print_rate > 0 && frame_count_ > print_rate) {
499 LOG(INFO, "Found (%zu / %zu)(%.2f) targets.\n", valid_result_count_,
500 frame_count_, (double)valid_result_count_ / (double)frame_count_);
501 frame_count_ = 0;
502 valid_result_count_ = 0;
503 }
504
Parker Schuh2a1447c2019-02-17 00:25:29 -0800505 return filtered;
506}
507
508} // namespace vision
509} // namespace y2019