Parker Schuh | 2a1447c | 2019-02-17 00:25:29 -0800 | [diff] [blame] | 1 | #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 | |
| 11 | namespace y2019 { |
| 12 | namespace vision { |
| 13 | |
| 14 | using aos::vision::ImageRange; |
| 15 | using aos::vision::RangeImage; |
| 16 | using aos::vision::BlobList; |
| 17 | using aos::vision::Vector; |
| 18 | |
| 19 | class 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_; } |
Alex Perry | 3bf1bee | 2019-02-23 20:01:15 -0800 | [diff] [blame^] | 60 | IntrinsicParams *mutable_intrinsics() { return &intrinsics_; } |
Parker Schuh | 2a1447c | 2019-02-17 00:25:29 -0800 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | // Find a loosly connected target. |
| 64 | double DetectConnectedTarget(const RangeImage &img); |
| 65 | |
| 66 | aos::vision::PixelLinesOverlay overlay_; |
| 67 | |
| 68 | aos::vision::AnalysisAllocator alloc_; |
| 69 | |
| 70 | // The template for the default target in the standard space. |
| 71 | Target target_template_; |
| 72 | |
| 73 | IntrinsicParams intrinsics_; |
| 74 | |
| 75 | ExtrinsicParams default_extrinsics_; |
| 76 | }; |
| 77 | |
| 78 | } // namespace vision |
| 79 | } // namespace y2019 |
| 80 | |
| 81 | #endif |