WPILibC++  unspecified
VisionRunner.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <atomic>
11 #include <functional>
12 #include <memory>
13 
14 #include "ErrorBase.h"
15 #include "cscore.h"
16 #include "vision/VisionPipeline.h"
17 
18 namespace frc {
19 
23 class VisionRunnerBase : public ErrorBase {
24  public:
25  explicit VisionRunnerBase(cs::VideoSource videoSource);
26  ~VisionRunnerBase() override;
27 
28  VisionRunnerBase(const VisionRunnerBase&) = delete;
29  VisionRunnerBase& operator=(const VisionRunnerBase&) = delete;
30 
31  void RunOnce();
32 
33  void RunForever();
34 
35  void Stop();
36 
37  protected:
38  virtual void DoProcess(cv::Mat& image) = 0;
39 
40  private:
41  std::unique_ptr<cv::Mat> m_image;
42  cs::CvSink m_cvSink;
43  std::atomic_bool m_enabled;
44 };
45 
53 template <typename T>
55  public:
56  VisionRunner(cs::VideoSource videoSource, T* pipeline,
57  std::function<void(T&)> listener);
58  virtual ~VisionRunner() = default;
59 
60  protected:
61  void DoProcess(cv::Mat& image) override;
62 
63  private:
64  T* m_pipeline;
65  std::function<void(T&)> m_listener;
66 };
67 } // namespace frc
68 
69 #include "VisionRunner.inc"
void RunForever()
A convenience method that calls runOnce() in an infinite loop.
Definition: VisionRunner.cpp:68
void Stop()
Stop a RunForever() loop.
Definition: VisionRunner.cpp:83
Definition: RobotController.cpp:14
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:86
VisionRunnerBase(cs::VideoSource videoSource)
Creates a new vision runner.
Definition: VisionRunner.cpp:23
Base class for most objects.
Definition: ErrorBase.h:74
Non-template base class for VisionRunner.
Definition: VisionRunner.h:23
A sink for user code to accept video frames as OpenCV images.
Definition: cscore_oo.h:555
A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot cod...
Definition: VisionRunner.h:54
void RunOnce()
Runs the pipeline one time, giving it the next image from the video source specified in the construct...
Definition: VisionRunner.cpp:46