blob: 633733adae1654d7f0cbb608b7648ba4a0d0c7d3 [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"
7#include "aos/vision/debug/overlay.h"
8#include "aos/vision/math/vector.h"
9#include "y2019/vision/target_types.h"
10
11namespace y2019 {
12namespace vision {
13
14using aos::vision::ImageRange;
15using aos::vision::RangeImage;
16using aos::vision::BlobList;
17using aos::vision::Vector;
18
19class TargetFinder {
20 public:
21 TargetFinder();
22 // Turn a raw image into blob range image.
23 aos::vision::RangeImage Threshold(aos::vision::ImagePtr image);
24
25 // Value against which we threshold.
26 uint8_t GetThresholdValue() { return 120; }
27
28 // filter out obvious or durranged blobs.
29 void PreFilter(BlobList *imgs);
30
31 // Turn a blob into a polgygon.
32 std::vector<aos::vision::Segment<2>> FillPolygon(const RangeImage &blob,
33 bool verbose);
34
35 // Turn a bloblist into components of a target.
36 std::vector<TargetComponent> FillTargetComponentList(
37 const std::vector<std::vector<aos::vision::Segment<2>>> &seg_list);
38
39 // Piece the compenents together into a target.
40 std::vector<Target> FindTargetsFromComponents(
41 const std::vector<TargetComponent> component_list, bool verbose);
42
43 // Given a target solve for the transformation of the template target.
44 IntermediateResult ProcessTargetToResult(const Target &target, bool verbose);
45
46 std::vector<IntermediateResult> FilterResults(
47 const std::vector<IntermediateResult> &results);
48
49 // Get the local overlay for debug if we are doing that.
50 aos::vision::PixelLinesOverlay *GetOverlay() { return &overlay_; }
51
52 // Convert target location into meters and radians.
53 void GetAngleDist(const aos::vision::Vector<2> &target, double down_angle,
54 double *dist, double *angle);
55
56 // Return the template target in a normalized space.
57 const Target &GetTemplateTarget() { return target_template_; }
58
59 const IntrinsicParams &intrinsics() const { return intrinsics_; }
60
61 private:
62 // Find a loosly connected target.
63 double DetectConnectedTarget(const RangeImage &img);
64
65 aos::vision::PixelLinesOverlay overlay_;
66
67 aos::vision::AnalysisAllocator alloc_;
68
69 // The template for the default target in the standard space.
70 Target target_template_;
71
72 IntrinsicParams intrinsics_;
73
74 ExtrinsicParams default_extrinsics_;
75};
76
77} // namespace vision
78} // namespace y2019
79
80#endif