Skip to content

Commit

Permalink
Refactoring of pixelFactor default to CvSink class
Browse files Browse the repository at this point in the history
  • Loading branch information
MrRedness committed Nov 21, 2023
1 parent 0c3905a commit aebec19
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 77 deletions.
30 changes: 0 additions & 30 deletions cscore/src/main/native/cpp/CvSinkImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<void(uint64_t time)> 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,
Expand Down Expand Up @@ -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<CvSinkImpl>(name, inst.logger, inst.notifier,
inst.telemetry));
}

CS_Sink CreateCvSink(std::string_view name, VideoMode::PixelFormat pixelFormat,
CS_Status* status) {
auto& inst = Instance::GetInstance();
Expand All @@ -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<void(uint64_t time)> processFrame,
CS_Status* status) {
auto& inst = Instance::GetInstance();
return inst.CreateSink(
CS_SINK_CV, std::make_shared<CvSinkImpl>(name, inst.logger, inst.notifier,
inst.telemetry, processFrame));
}

CS_Sink CreateCvSinkCallback(std::string_view name,
VideoMode::PixelFormat pixelFormat,
std::function<void(uint64_t time)> processFrame,
Expand Down
5 changes: 0 additions & 5 deletions cscore/src/main/native/cpp/CvSinkImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(uint64_t time)> processFrame);
CvSinkImpl(std::string_view name, wpi::Logger& logger, Notifier& notifier,
Telemetry& telemetry, VideoMode::PixelFormat pixelFormat,
std::function<void(uint64_t time)> processFrame);
Expand Down
4 changes: 0 additions & 4 deletions cscore/src/main/native/include/cscore_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(uint64_t time)> processFrame,
CS_Status* status);
CS_Sink CreateCvSinkCallback(std::string_view name,
VideoMode::PixelFormat pixelFormat,
std::function<void(uint64_t time)> processFrame,
Expand Down
45 changes: 7 additions & 38 deletions cscore/src/main/native/include/cscore_cv.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ class CvSink : public ImageSink {
public:
CvSink() = default;

/**
* Create a sink for accepting OpenCV images.
*
* <p>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.
*
Expand All @@ -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.
Expand All @@ -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<void(uint64_t time)> processFrame);

/**
* Create a sink for accepting OpenCV images in a separate thread.
*
* <p>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<void(uint64_t time)> processFrame);
CvSink(std::string_view name,
std::function<void(uint64_t time)> processFrame,
VideoMode::PixelFormat pixelFormat = VideoMode::PixelFormat::kBGR);

/**
* Wait for the next frame and get the image.
Expand Down Expand Up @@ -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<void(uint64_t time)> processFrame) {
m_handle = CreateCvSinkCallback(name, processFrame, &m_status);
}

inline CvSink::CvSink(std::string_view name, VideoMode::PixelFormat pixelFormat,
std::function<void(uint64_t time)> processFrame) {
std::function<void(uint64_t time)> processFrame,
VideoMode::PixelFormat pixelFormat) {
m_handle = CreateCvSinkCallback(name, pixelFormat, processFrame, &m_status);
}

Expand Down

0 comments on commit aebec19

Please sign in to comment.