From aebec19ec7b340678db7014c2fbecee3c2110173 Mon Sep 17 00:00:00 2001 From: MrRedness <16584585+MrRedness@users.noreply.github.com> Date: Tue, 21 Nov 2023 17:00:11 -0500 Subject: [PATCH] Refactoring of pixelFactor default to CvSink class --- cscore/src/main/native/cpp/CvSinkImpl.cpp | 30 -------------- cscore/src/main/native/cpp/CvSinkImpl.h | 5 --- cscore/src/main/native/include/cscore_cpp.h | 4 -- cscore/src/main/native/include/cscore_cv.h | 45 ++++----------------- 4 files changed, 7 insertions(+), 77 deletions(-) diff --git a/cscore/src/main/native/cpp/CvSinkImpl.cpp b/cscore/src/main/native/cpp/CvSinkImpl.cpp index a5c3a7d44bf..bfe96adac1b 100644 --- a/cscore/src/main/native/cpp/CvSinkImpl.cpp +++ b/cscore/src/main/native/cpp/CvSinkImpl.cpp @@ -18,14 +18,6 @@ using namespace cs; -CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, - Notifier& notifier, Telemetry& telemetry) - : SinkImpl{name, logger, notifier, telemetry}, - m_pixelFormat{VideoMode::PixelFormat::kBGR} { - m_active = true; - // m_thread = std::thread(&CvSinkImpl::ThreadMain, this); -} - CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, Telemetry& telemetry, VideoMode::PixelFormat pixelFormat) @@ -34,12 +26,6 @@ CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, // m_thread = std::thread(&CvSinkImpl::ThreadMain, this); } -CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, - Notifier& notifier, Telemetry& telemetry, - std::function processFrame) - : SinkImpl{name, logger, notifier, telemetry}, - m_pixelFormat{VideoMode::PixelFormat::kBGR} {} - CvSinkImpl::CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, Telemetry& telemetry, VideoMode::PixelFormat pixelFormat, @@ -143,13 +129,6 @@ void CvSinkImpl::ThreadMain() { namespace cs { -CS_Sink CreateCvSink(std::string_view name, CS_Status* status) { - auto& inst = Instance::GetInstance(); - return inst.CreateSink( - CS_SINK_CV, std::make_shared(name, inst.logger, inst.notifier, - inst.telemetry)); -} - CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, CS_Status* status) { auto& inst = Instance::GetInstance(); @@ -158,15 +137,6 @@ CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, inst.telemetry, pixelFormat)); } -CS_Sink CreateCvSinkCallback(std::string_view name, - std::function processFrame, - CS_Status* status) { - auto& inst = Instance::GetInstance(); - return inst.CreateSink( - CS_SINK_CV, std::make_shared(name, inst.logger, inst.notifier, - inst.telemetry, processFrame)); -} - CS_Sink CreateCvSinkCallback(std::string_view name, VideoMode::PixelFormat pixelFormat, std::function processFrame, diff --git a/cscore/src/main/native/cpp/CvSinkImpl.h b/cscore/src/main/native/cpp/CvSinkImpl.h index 1231efaf358..da9392f39c6 100644 --- a/cscore/src/main/native/cpp/CvSinkImpl.h +++ b/cscore/src/main/native/cpp/CvSinkImpl.h @@ -24,13 +24,8 @@ class SourceImpl; class CvSinkImpl : public SinkImpl { public: - CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, - Telemetry& telemetry); CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, Telemetry& telemetry, VideoMode::PixelFormat pixelFormat); - CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, - Telemetry& telemetry, - std::function processFrame); CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier, Telemetry& telemetry, VideoMode::PixelFormat pixelFormat, std::function processFrame); diff --git a/cscore/src/main/native/include/cscore_cpp.h b/cscore/src/main/native/include/cscore_cpp.h index 174b533544c..28d2d9d2649 100644 --- a/cscore/src/main/native/include/cscore_cpp.h +++ b/cscore/src/main/native/include/cscore_cpp.h @@ -316,12 +316,8 @@ void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, */ CS_Sink CreateMjpegServer(std::string_view name, std::string_view listenAddress, int port, CS_Status* status); -CS_Sink CreateCvSink(std::string_view name, CS_Status* status); CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, CS_Status* status); -CS_Sink CreateCvSinkCallback(std::string_view name, - std::function processFrame, - CS_Status* status); CS_Sink CreateCvSinkCallback(std::string_view name, VideoMode::PixelFormat pixelFormat, std::function processFrame, diff --git a/cscore/src/main/native/include/cscore_cv.h b/cscore/src/main/native/include/cscore_cv.h index 2ad137692c5..d44d28d5f78 100644 --- a/cscore/src/main/native/include/cscore_cv.h +++ b/cscore/src/main/native/include/cscore_cv.h @@ -120,16 +120,6 @@ class CvSink : public ImageSink { public: CvSink() = default; - /** - * Create a sink for accepting OpenCV images. - * - *

WaitForFrame() must be called on the created sink to get each new - * image. - * - * @param name Source name (arbitrary unique identifier) - */ - explicit CvSink(std::string_view name); - /** * Create a sink for accepting OpenCV images. * @@ -139,7 +129,8 @@ class CvSink : public ImageSink { * @param name Source name (arbitrary unique identifier) * @param pixelFormat Source pixel format */ - explicit CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat); + explicit CvSink(std::string_view name, + VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR); /** * Create a sink for accepting OpenCV images in a separate thread. @@ -152,25 +143,11 @@ class CvSink : public ImageSink { * time=0 if an error occurred. processFrame should call GetImage() * or GetError() as needed, but should not call (except in very * unusual circumstances) WaitForImage(). - */ - CvSink(std::string_view name, - std::function processFrame); - - /** - * Create a sink for accepting OpenCV images in a separate thread. - * - *

A thread will be created that calls WaitForFrame() and calls the - * processFrame() callback each time a new frame arrives. - * - * @param name Source name (arbitrary unique identifier) * @param pixelFormat Source pixel format - * @param processFrame Frame processing function; will be called with a - * time=0 if an error occurred. processFrame should call GetImage() - * or GetError() as needed, but should not call (except in very - * unusual circumstances) WaitForImage(). */ - CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, - std::function processFrame); + CvSink(std::string_view name, + std::function processFrame, + VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR); /** * Wait for the next frame and get the image. @@ -211,22 +188,14 @@ inline void CvSource::PutFrame(cv::Mat& image) { PutSourceFrame(m_handle, image, &m_status); } -inline CvSink::CvSink(std::string_view name) { - m_handle = CreateCvSink(name, &m_status); -} - inline CvSink::CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat) { m_handle = CreateCvSink(name, pixelFormat, &m_status); } inline CvSink::CvSink(std::string_view name, - std::function processFrame) { - m_handle = CreateCvSinkCallback(name, processFrame, &m_status); -} - -inline CvSink::CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat, - std::function processFrame) { + std::function processFrame, + VideoMode::PixelFormat pixelFormat) { m_handle = CreateCvSinkCallback(name, pixelFormat, processFrame, &m_status); }