WPILibC++  2020.3.2
VisionRunner.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2016-2019 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 "cscore_cv.h"
16 #include "vision/VisionPipeline.h"
17 
18 namespace frc {
19 
24  public:
32  explicit VisionRunnerBase(cs::VideoSource videoSource);
33 
35 
36  VisionRunnerBase(const VisionRunnerBase&) = delete;
37  VisionRunnerBase& operator=(const VisionRunnerBase&) = delete;
38 
52  void RunOnce();
53 
61  void RunForever();
62 
66  void Stop();
67 
68  protected:
69  virtual void DoProcess(cv::Mat& image) = 0;
70 
71  private:
72  std::unique_ptr<cv::Mat> m_image;
73  cs::CvSink m_cvSink;
74  std::atomic_bool m_enabled;
75 };
76 
84 template <typename T>
86  public:
87  VisionRunner(cs::VideoSource videoSource, T* pipeline,
88  std::function<void(T&)> listener);
89  virtual ~VisionRunner() = default;
90 
91  protected:
92  void DoProcess(cv::Mat& image) override;
93 
94  private:
95  T* m_pipeline;
96  std::function<void(T&)> m_listener;
97 };
98 } // namespace frc
99 
100 #include "VisionRunner.inc"
frc::VisionRunnerBase::Stop
void Stop()
Stop a RunForever() loop.
frc::VisionRunnerBase
Non-template base class for VisionRunner.
Definition: VisionRunner.h:23
frc::VisionRunner
A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot cod...
Definition: VisionRunner.h:85
frc::VisionRunner::VisionRunner
VisionRunner(cs::VideoSource videoSource, T *pipeline, std::function< void(T &)> listener)
Creates a new vision runner.
Definition: VisionRunner.inc:23
frc::VisionRunnerBase::RunOnce
void RunOnce()
Runs the pipeline one time, giving it the next image from the video source specified in the construct...
frc::VisionRunnerBase::RunForever
void RunForever()
A convenience method that calls runOnce() in an infinite loop.
frc::VisionRunnerBase::VisionRunnerBase
VisionRunnerBase(cs::VideoSource videoSource)
Creates a new vision runner.
frc
A class that enforces constraints on the differential drive kinematics.
Definition: SPIAccelerometerSim.h:16
cs::VideoSource
A source for video that provides a sequence of frames.
Definition: cscore_oo.h:97