blob: 83a1ebd3c22b0acee604aa327b629726de40716e [file] [log] [blame]
Parker Schuh2a1447c2019-02-17 00:25:29 -08001#ifndef _Y2019_VISION_TARGET_FINDER_H_
2#define _Y2019_VISION_TARGET_FINDER_H_
3
4#include "aos/vision/blob/region_alloc.h"
5#include "aos/vision/blob/threshold.h"
6#include "aos/vision/blob/transpose.h"
Ben Fredricksonf7b68522019-03-02 21:19:42 -08007#include "aos/vision/blob/contour.h"
Parker Schuh2a1447c2019-02-17 00:25:29 -08008#include "aos/vision/debug/overlay.h"
9#include "aos/vision/math/vector.h"
10#include "y2019/vision/target_types.h"
11
12namespace y2019 {
13namespace vision {
14
15using aos::vision::ImageRange;
16using aos::vision::RangeImage;
17using aos::vision::BlobList;
18using aos::vision::Vector;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080019using aos::vision::ContourNode;
Parker Schuh2a1447c2019-02-17 00:25:29 -080020
21class TargetFinder {
22 public:
23 TargetFinder();
24 // Turn a raw image into blob range image.
25 aos::vision::RangeImage Threshold(aos::vision::ImagePtr image);
26
27 // Value against which we threshold.
Austin Schuh2851e7f2019-03-06 20:45:19 -080028 static uint8_t GetThresholdValue() { return 100; }
Parker Schuh2a1447c2019-02-17 00:25:29 -080029
30 // filter out obvious or durranged blobs.
31 void PreFilter(BlobList *imgs);
32
Austin Schuhe5015972019-03-09 17:47:34 -080033 ContourNode *GetContour(const RangeImage &blob);
34 ::std::vector<::Eigen::Vector2f> UnWarpContour(ContourNode *start) const;
Ben Fredricksonf7b68522019-03-02 21:19:42 -080035
Parker Schuh2a1447c2019-02-17 00:25:29 -080036 // Turn a blob into a polgygon.
Austin Schuhe5015972019-03-09 17:47:34 -080037 std::vector<aos::vision::Segment<2>> FillPolygon(
38 const ::std::vector<::Eigen::Vector2f> &contour, bool verbose);
Parker Schuh2a1447c2019-02-17 00:25:29 -080039
40 // Turn a bloblist into components of a target.
41 std::vector<TargetComponent> FillTargetComponentList(
Austin Schuh32ffac22019-03-09 22:42:02 -080042 const std::vector<std::vector<aos::vision::Segment<2>>> &seg_list,
43 bool verbose);
Parker Schuh2a1447c2019-02-17 00:25:29 -080044
45 // Piece the compenents together into a target.
46 std::vector<Target> FindTargetsFromComponents(
47 const std::vector<TargetComponent> component_list, bool verbose);
48
49 // Given a target solve for the transformation of the template target.
50 IntermediateResult ProcessTargetToResult(const Target &target, bool verbose);
51
52 std::vector<IntermediateResult> FilterResults(
Ben Fredricksona8c3d552019-03-03 14:14:53 -080053 const std::vector<IntermediateResult> &results, uint64_t print_rate);
Parker Schuh2a1447c2019-02-17 00:25:29 -080054
55 // Get the local overlay for debug if we are doing that.
56 aos::vision::PixelLinesOverlay *GetOverlay() { return &overlay_; }
57
58 // Convert target location into meters and radians.
59 void GetAngleDist(const aos::vision::Vector<2> &target, double down_angle,
60 double *dist, double *angle);
61
62 // Return the template target in a normalized space.
63 const Target &GetTemplateTarget() { return target_template_; }
64
65 const IntrinsicParams &intrinsics() const { return intrinsics_; }
Alex Perry3bf1bee2019-02-23 20:01:15 -080066 IntrinsicParams *mutable_intrinsics() { return &intrinsics_; }
Parker Schuh2a1447c2019-02-17 00:25:29 -080067
68 private:
69 // Find a loosly connected target.
70 double DetectConnectedTarget(const RangeImage &img);
71
72 aos::vision::PixelLinesOverlay overlay_;
73
74 aos::vision::AnalysisAllocator alloc_;
75
76 // The template for the default target in the standard space.
Austin Schuh4d6e9bd2019-03-08 19:54:17 -080077 const Target target_template_;
Parker Schuh2a1447c2019-02-17 00:25:29 -080078
79 IntrinsicParams intrinsics_;
80
81 ExtrinsicParams default_extrinsics_;
Ben Fredricksona8c3d552019-03-03 14:14:53 -080082
83 // Counts for logging.
84 size_t frame_count_;
85 size_t valid_result_count_;
Parker Schuh2a1447c2019-02-17 00:25:29 -080086};
87
88} // namespace vision
89} // namespace y2019
90
91#endif