WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
VisionRunner.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2016. 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 <functional>
11 #include <memory>
12 
13 #include "ErrorBase.h"
14 #include "cscore.h"
15 #include "vision/VisionPipeline.h"
16 
17 namespace frc {
18 
22 class VisionRunnerBase : public ErrorBase {
23  public:
24  explicit VisionRunnerBase(cs::VideoSource videoSource);
25  ~VisionRunnerBase() override;
26 
27  VisionRunnerBase(const VisionRunnerBase&) = delete;
28  VisionRunnerBase& operator=(const VisionRunnerBase&) = delete;
29 
30  void RunOnce();
31 
32  void RunForever();
33 
34  protected:
35  virtual void DoProcess(cv::Mat& image) = 0;
36 
37  private:
38  std::unique_ptr<cv::Mat> m_image;
39  cs::CvSink m_cvSink;
40 };
41 
49 template <typename T>
51  public:
52  VisionRunner(cs::VideoSource videoSource, T* pipeline,
53  std::function<void(T&)> listener);
54  virtual ~VisionRunner() = default;
55 
56  protected:
57  void DoProcess(cv::Mat& image) override;
58 
59  private:
60  T* m_pipeline;
61  std::function<void(T&)> m_listener;
62 };
63 } // namespace frc
64 
65 #include "VisionRunner.inc"
void RunForever()
A convenience method that calls runOnce() in an infinite loop.
Definition: VisionRunner.cpp:66
VisionRunnerBase(cs::VideoSource videoSource)
Creates a new vision runner.
Definition: VisionRunner.cpp:22
Base class for most objects.
Definition: ErrorBase.h:72
VisionRunner(cs::VideoSource videoSource, T *pipeline, std::function< void(T &)> listener)
Creates a new vision runner.
Definition: VisionRunner.inc:24
Non-template base class for VisionRunner.
Definition: VisionRunner.h:22
A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot cod...
Definition: VisionRunner.h:50
void RunOnce()
Runs the pipeline one time, giving it the next image from the video source specified in the construct...
Definition: VisionRunner.cpp:43