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 | |
| 4 | #include "aos/common/util/global_factory.h" |
| 5 | #include "aos/vision/blob/range_image.h" |
| 6 | #include "aos/vision/events/epoll_events.h" |
| 7 | #include "aos/vision/image/image_types.h" |
| 8 | |
| 9 | namespace aos { |
| 10 | namespace vision { |
| 11 | |
| 12 | class BlobStreamViewer; |
| 13 | |
| 14 | // Implement per-filter to draw debug viewer information from the filter to |
| 15 | // the debug BlobStreamViewer. |
| 16 | class FilterHarness { |
| 17 | public: |
| 18 | virtual ~FilterHarness() {} |
| 19 | |
| 20 | // Apply the filter-specific thresholding logic. |
| 21 | // Blob sources may not have this called at all. |
| 22 | virtual RangeImage Threshold(ImagePtr image) = 0; |
| 23 | |
| 24 | // Each filter can only be used by one debug viewer. This will |
| 25 | // get called before calling any other methods. |
| 26 | virtual void InstallViewer(BlobStreamViewer * /*viewer*/) {} |
| 27 | |
| 28 | // One frame worth of blobs. Returns if the frame is "interesting". |
| 29 | virtual bool HandleBlobs(BlobList imgs, ImageFormat fmt) = 0; |
| 30 | }; |
| 31 | |
| 32 | // For ImageSource implementations only. Allows registering key press events |
| 33 | // and installing new blob lists and jpegs. |
| 34 | class DebugFrameworkInterface { |
| 35 | public: |
| 36 | virtual ~DebugFrameworkInterface() {} |
| 37 | |
| 38 | void InstallKeyPress(std::function<void(uint32_t)> key_press_event) { |
| 39 | key_press_events_.emplace_back(std::move(key_press_event)); |
| 40 | } |
| 41 | |
| 42 | virtual void NewJpeg(DataRef data) = 0; |
| 43 | |
| 44 | virtual void NewBlobList(BlobList blob_list, ImageFormat fmt) = 0; |
| 45 | |
| 46 | // Expose a EpollLoop to allow waiting for events. |
| 47 | virtual aos::events::EpollLoop *Loop() = 0; |
| 48 | |
| 49 | protected: |
| 50 | const std::vector<std::function<void(uint32_t)>> &key_press_events() { |
| 51 | return key_press_events_; |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | std::vector<std::function<void(uint32_t)>> key_press_events_; |
| 56 | }; |
| 57 | |
| 58 | // Implemented by each source type. Will stream frames to |
| 59 | // DebugFrameworkInterface. |
| 60 | class ImageSource { |
| 61 | public: |
| 62 | virtual ~ImageSource() {} |
| 63 | |
| 64 | // Printed when you call: debug_viewer help. |
| 65 | virtual const char *GetHelpMessage() { return " No help string :(\n"; } |
| 66 | |
| 67 | // Start streaming frames to DebugFrameworkInterface. |
| 68 | virtual void Init(const std::string &args, |
| 69 | DebugFrameworkInterface *interface) = 0; |
| 70 | }; |
| 71 | |
| 72 | // Factory for ImageSource. |
| 73 | SETUP_FACTORY(ImageSource); |
| 74 | |
| 75 | #define REGISTER_IMAGE_SOURCE(key, SubClass) \ |
| 76 | REGISTER_SUBCLASS_BY_KEY(key, ::aos::vision::ImageSource, SubClass) |
| 77 | |
| 78 | // Runs loop and never returns. |
| 79 | // Feeds into a generic filter. |
| 80 | void DebugFrameworkMain(int argc, char **argv, FilterHarness *filter); |
| 81 | |
| 82 | } // namespace vision |
| 83 | } // namespace aos |
| 84 | |
| 85 | #endif // _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_ |