Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2016-2017. 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 | namespace frc { |
| 11 | |
| 12 | /** |
| 13 | * Creates a new vision runner. It will take images from the {@code |
| 14 | * videoSource}, send them to the {@code pipeline}, and call the {@code |
| 15 | * listener} when the pipeline has finished to alert user code when it is safe |
| 16 | * to access the pipeline's outputs. |
| 17 | * |
| 18 | * @param videoSource the video source to use to supply images for the pipeline |
| 19 | * @param pipeline the vision pipeline to run |
| 20 | * @param listener a function to call after the pipeline has finished |
| 21 | * running |
| 22 | */ |
| 23 | template <typename T> |
| 24 | VisionRunner<T>::VisionRunner(cs::VideoSource videoSource, T* pipeline, |
| 25 | std::function<void(T&)> listener) |
| 26 | : VisionRunnerBase(videoSource), |
| 27 | m_pipeline(pipeline), |
| 28 | m_listener(listener) {} |
| 29 | |
| 30 | template <typename T> |
| 31 | void VisionRunner<T>::DoProcess(cv::Mat& image) { |
| 32 | m_pipeline->Process(image); |
| 33 | m_listener(*m_pipeline); |
| 34 | } |
| 35 | |
| 36 | } // namespace frc |