2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-10-26 23:37:00 -07:00
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#ifndef CSCORE_CVSINKIMPL_H_
|
|
|
|
|
#define CSCORE_CVSINKIMPL_H_
|
2016-10-26 23:37:00 -07:00
|
|
|
|
2018-10-31 20:22:58 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2016-10-26 23:37:00 -07:00
|
|
|
#include <atomic>
|
2018-10-31 20:22:58 -07:00
|
|
|
#include <functional>
|
2016-10-26 23:37:00 -07:00
|
|
|
#include <thread>
|
|
|
|
|
|
2018-10-31 20:22:58 -07:00
|
|
|
#include <opencv2/core/core.hpp>
|
2018-07-29 12:53:41 -07:00
|
|
|
#include <wpi/Twine.h>
|
2018-10-31 20:22:58 -07:00
|
|
|
#include <wpi/condition_variable.h>
|
2016-10-26 23:37:00 -07:00
|
|
|
|
2018-10-31 20:22:58 -07:00
|
|
|
#include "Frame.h"
|
2016-10-26 23:37:00 -07:00
|
|
|
#include "SinkImpl.h"
|
|
|
|
|
|
|
|
|
|
namespace cs {
|
|
|
|
|
|
|
|
|
|
class SourceImpl;
|
|
|
|
|
|
|
|
|
|
class CvSinkImpl : public SinkImpl {
|
|
|
|
|
public:
|
2018-10-31 20:22:58 -07:00
|
|
|
CvSinkImpl(const wpi::Twine& name, wpi::Logger& logger, Notifier& notifier,
|
|
|
|
|
Telemetry& telemetry);
|
|
|
|
|
CvSinkImpl(const wpi::Twine& name, wpi::Logger& logger, Notifier& notifier,
|
|
|
|
|
Telemetry& telemetry,
|
2016-10-26 23:37:00 -07:00
|
|
|
std::function<void(uint64_t time)> processFrame);
|
|
|
|
|
~CvSinkImpl() override;
|
|
|
|
|
|
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
|
|
uint64_t GrabFrame(cv::Mat& image);
|
2017-02-17 01:17:12 -08:00
|
|
|
uint64_t GrabFrame(cv::Mat& image, double timeout);
|
2016-10-26 23:37:00 -07:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void ThreadMain();
|
|
|
|
|
|
|
|
|
|
std::atomic_bool m_active; // set to false to terminate threads
|
|
|
|
|
std::thread m_thread;
|
|
|
|
|
std::function<void(uint64_t time)> m_processFrame;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace cs
|
|
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#endif // CSCORE_CVSINKIMPL_H_
|