blob: a46812fd4e1cdff7775acaf7d560c5aabc2d45f3 [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 Schuh02f13f62019-02-16 16:42:41 -080058 virtual bool NewImage(ImageFormat fmt,
59 const std::function<bool(ImagePtr data)> &process) = 0;
60
Parker Schuhcd258b82017-04-09 16:28:29 -070061 virtual bool NewBlobList(BlobList blob_list, ImageFormat fmt) = 0;
62
63 virtual bool JustCheckForTarget(BlobList imgs, ImageFormat fmt) = 0;
Parker Schuh90641112017-02-25 12:18:36 -080064
65 // Expose a EpollLoop to allow waiting for events.
66 virtual aos::events::EpollLoop *Loop() = 0;
67
Parker Schuhcd258b82017-04-09 16:28:29 -070068 virtual const CameraParams &camera_params() = 0;
69
70 virtual BlobStreamViewer *viewer() = 0;
71
Parker Schuh90641112017-02-25 12:18:36 -080072 protected:
73 const std::vector<std::function<void(uint32_t)>> &key_press_events() {
74 return key_press_events_;
75 }
76
77 private:
78 std::vector<std::function<void(uint32_t)>> key_press_events_;
79};
80
81// Implemented by each source type. Will stream frames to
82// DebugFrameworkInterface.
83class ImageSource {
84 public:
85 virtual ~ImageSource() {}
86
87 // Printed when you call: debug_viewer help.
88 virtual const char *GetHelpMessage() { return " No help string :(\n"; }
89
90 // Start streaming frames to DebugFrameworkInterface.
91 virtual void Init(const std::string &args,
92 DebugFrameworkInterface *interface) = 0;
93};
94
95// Factory for ImageSource.
96SETUP_FACTORY(ImageSource);
97
98#define REGISTER_IMAGE_SOURCE(key, SubClass) \
99 REGISTER_SUBCLASS_BY_KEY(key, ::aos::vision::ImageSource, SubClass)
100
101// Runs loop and never returns.
102// Feeds into a generic filter.
Parker Schuhcd258b82017-04-09 16:28:29 -0700103void DebugFrameworkMain(int argc, char **argv, FilterHarness *filter,
104 CameraParams camera_params);
Parker Schuh90641112017-02-25 12:18:36 -0800105
106} // namespace vision
107} // namespace aos
108
109#endif // _AOS_VISION_DEBUG_DEBUG_FRAMEWORK_H_