WPILibC++  2019.1.1-beta-2-8-g9207d78
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 "cscore.h"
15 #include "vision/VisionPipeline.h"
16 
17 namespace frc {
18 
23  public:
31  explicit VisionRunnerBase(cs::VideoSource videoSource);
32 
34 
35  VisionRunnerBase(const VisionRunnerBase&) = delete;
36  VisionRunnerBase& operator=(const VisionRunnerBase&) = delete;
37 
51  void RunOnce();
52 
60  void RunForever();
61 
65  void Stop();
66 
67  protected:
68  virtual void DoProcess(cv::Mat& image) = 0;
69 
70  private:
71  std::unique_ptr<cv::Mat> m_image;
72  cs::CvSink m_cvSink;
73  std::atomic_bool m_enabled;
74 };
75 
83 template <typename T>
85  public:
86  VisionRunner(cs::VideoSource videoSource, T* pipeline,
87  std::function<void(T&)> listener);
88  virtual ~VisionRunner() = default;
89 
90  protected:
91  void DoProcess(cv::Mat& image) override;
92 
93  private:
94  T* m_pipeline;
95  std::function<void(T&)> m_listener;
96 };
97 } // namespace frc
98 
99 #include "VisionRunner.inc"
void Stop()
Stop a RunForever() loop.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97
void RunOnce()
Runs the pipeline one time, giving it the next image from the video source specified in the construct...
void RunForever()
A convenience method that calls runOnce() in an infinite loop.
VisionRunnerBase(cs::VideoSource videoSource)
Creates a new vision runner.
VisionRunner(cs::VideoSource videoSource, T *pipeline, std::function< void(T &)> listener)
Creates a new vision runner.
Definition: VisionRunner.inc:23
Non-template base class for VisionRunner.
Definition: VisionRunner.h:22
A sink for user code to accept video frames as OpenCV images.
Definition: cscore_oo.h:927
A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot cod...
Definition: VisionRunner.h:84