Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 1 | #ifndef _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_ |
| 2 | #define _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_ |
| 3 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 4 | #include "aos/util/global_factory.h" |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 5 | #include "aos/vision/blob/range_image.h" |
| 6 | #include "aos/vision/events/epoll_events.h" |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 7 | #include "aos/vision/image/camera_params.pb.h" |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 8 | #include "aos/vision/image/image_types.h" |
| 9 | |
| 10 | namespace aos { |
| 11 | namespace vision { |
| 12 | |
| 13 | class BlobStreamViewer; |
| 14 | |
| 15 | // Implement per-filter to draw debug viewer information from the filter to |
| 16 | // the debug BlobStreamViewer. |
| 17 | class FilterHarness { |
| 18 | public: |
| 19 | virtual ~FilterHarness() {} |
| 20 | |
| 21 | // Apply the filter-specific thresholding logic. |
| 22 | // Blob sources may not have this called at all. |
| 23 | virtual RangeImage Threshold(ImagePtr image) = 0; |
| 24 | |
| 25 | // Each filter can only be used by one debug viewer. This will |
| 26 | // get called before calling any other methods. |
| 27 | virtual void InstallViewer(BlobStreamViewer * /*viewer*/) {} |
| 28 | |
| 29 | // One frame worth of blobs. Returns if the frame is "interesting". |
| 30 | virtual bool HandleBlobs(BlobList imgs, ImageFormat fmt) = 0; |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 31 | |
| 32 | // One frame worth of blobs. Returns if the frame is "interesting". |
| 33 | // Fast version that does no drawing. |
| 34 | virtual bool JustCheckForTarget(BlobList imgs, ImageFormat fmt) { |
| 35 | return HandleBlobs(std::move(imgs), fmt); |
| 36 | } |
| 37 | |
| 38 | // Register key press handler. |
| 39 | virtual std::function<void(uint32_t)> RegisterKeyPress() { |
| 40 | return std::function<void(uint32_t)>(); |
| 41 | } |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | // For ImageSource implementations only. Allows registering key press events |
| 45 | // and installing new blob lists and jpegs. |
| 46 | class DebugFrameworkInterface { |
| 47 | public: |
| 48 | virtual ~DebugFrameworkInterface() {} |
| 49 | |
| 50 | void InstallKeyPress(std::function<void(uint32_t)> key_press_event) { |
| 51 | key_press_events_.emplace_back(std::move(key_press_event)); |
| 52 | } |
| 53 | |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 54 | // The return value bool here for all of these is |
| 55 | // if the frame is "interesting" ie has a target. |
| 56 | virtual bool NewJpeg(DataRef data) = 0; |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 57 | |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 58 | virtual bool NewBlobList(BlobList blob_list, ImageFormat fmt) = 0; |
| 59 | |
| 60 | virtual bool JustCheckForTarget(BlobList imgs, ImageFormat fmt) = 0; |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 61 | |
| 62 | // Expose a EpollLoop to allow waiting for events. |
| 63 | virtual aos::events::EpollLoop *Loop() = 0; |
| 64 | |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 65 | virtual const CameraParams &camera_params() = 0; |
| 66 | |
| 67 | virtual BlobStreamViewer *viewer() = 0; |
| 68 | |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 69 | protected: |
| 70 | const std::vector<std::function<void(uint32_t)>> &key_press_events() { |
| 71 | return key_press_events_; |
| 72 | } |
| 73 | |
| 74 | private: |
| 75 | std::vector<std::function<void(uint32_t)>> key_press_events_; |
| 76 | }; |
| 77 | |
| 78 | // Implemented by each source type. Will stream frames to |
| 79 | // DebugFrameworkInterface. |
| 80 | class ImageSource { |
| 81 | public: |
| 82 | virtual ~ImageSource() {} |
| 83 | |
| 84 | // Printed when you call: debug_viewer help. |
| 85 | virtual const char *GetHelpMessage() { return " No help string :(\n"; } |
| 86 | |
| 87 | // Start streaming frames to DebugFrameworkInterface. |
| 88 | virtual void Init(const std::string &args, |
| 89 | DebugFrameworkInterface *interface) = 0; |
| 90 | }; |
| 91 | |
| 92 | // Factory for ImageSource. |
| 93 | SETUP_FACTORY(ImageSource); |
| 94 | |
| 95 | #define REGISTER_IMAGE_SOURCE(key, SubClass) \ |
| 96 | REGISTER_SUBCLASS_BY_KEY(key, ::aos::vision::ImageSource, SubClass) |
| 97 | |
| 98 | // Runs loop and never returns. |
| 99 | // Feeds into a generic filter. |
Parker Schuh | cd258b8 | 2017-04-09 16:28:29 -0700 | [diff] [blame] | 100 | void DebugFrameworkMain(int argc, char **argv, FilterHarness *filter, |
| 101 | CameraParams camera_params); |
Parker Schuh | 9064111 | 2017-02-25 12:18:36 -0800 | [diff] [blame] | 102 | |
| 103 | } // namespace vision |
| 104 | } // namespace aos |
| 105 | |
| 106 | #endif // _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_ |