blob: d5b345f578f3347010febb4facc705af4e545ace [file] [log] [blame]
Parker Schuh90641112017-02-25 12:18:36 -08001#ifndef _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_
2#define _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_
3
John Park33858a32018-09-28 23:05:48 -07004#include "aos/util/global_factory.h"
Parker Schuh90641112017-02-25 12:18:36 -08005#include "aos/vision/blob/range_image.h"
6#include "aos/vision/events/epoll_events.h"
Parker Schuhcd258b82017-04-09 16:28:29 -07007#include "aos/vision/image/camera_params.pb.h"
Parker Schuh90641112017-02-25 12:18:36 -08008#include "aos/vision/image/image_types.h"
9
10namespace aos {
11namespace vision {
12
13class BlobStreamViewer;
14
15// Implement per-filter to draw debug viewer information from the filter to
16// the debug BlobStreamViewer.
17class 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 Schuhcd258b82017-04-09 16:28:29 -070031
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 Schuh90641112017-02-25 12:18:36 -080042};
43
44// For ImageSource implementations only. Allows registering key press events
45// and installing new blob lists and jpegs.
46class 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 Schuhcd258b82017-04-09 16:28:29 -070054 // 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 Schuh90641112017-02-25 12:18:36 -080057
Parker Schuhcd258b82017-04-09 16:28:29 -070058 virtual bool NewBlobList(BlobList blob_list, ImageFormat fmt) = 0;
59
60 virtual bool JustCheckForTarget(BlobList imgs, ImageFormat fmt) = 0;
Parker Schuh90641112017-02-25 12:18:36 -080061
62 // Expose a EpollLoop to allow waiting for events.
63 virtual aos::events::EpollLoop *Loop() = 0;
64
Parker Schuhcd258b82017-04-09 16:28:29 -070065 virtual const CameraParams &camera_params() = 0;
66
67 virtual BlobStreamViewer *viewer() = 0;
68
Parker Schuh90641112017-02-25 12:18:36 -080069 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.
80class 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.
93SETUP_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 Schuhcd258b82017-04-09 16:28:29 -0700100void DebugFrameworkMain(int argc, char **argv, FilterHarness *filter,
101 CameraParams camera_params);
Parker Schuh90641112017-02-25 12:18:36 -0800102
103} // namespace vision
104} // namespace aos
105
106#endif // _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_