SMACC2
Loading...
Searching...
No Matches
cl_rgb::CpTableSegmenter Class Reference

#include <cp_table_segmenter.hpp>

Inheritance diagram for cl_rgb::CpTableSegmenter:
Inheritance graph
Collaboration diagram for cl_rgb::CpTableSegmenter:
Collaboration graph

Public Member Functions

 CpTableSegmenter (const SegmenterParams &params)
 
 ~CpTableSegmenter () override
 
void onInitialize () override
 
void setParams (const SegmenterParams &params)
 
SegmenterParams params () const
 
void setReference (const cv::Mat &bgr)
 
bool hasReference () const
 
cv::Mat foreground (const cv::Mat &bgr, const cv::Mat &tableMask) const
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
 ISmaccComponent (const ISmaccComponent &)=delete
 
ISmaccComponent & operator= (const ISmaccComponent &)=delete
 
 ISmaccComponent (ISmaccComponent &&)=delete
 
ISmaccComponent & operator= (ISmaccComponent &&)=delete
 
virtual std::string getName () const
 

Private Attributes

std::mutex mutex_
 
SegmenterParams params_
 
cv::Mat reference_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (const std::string &name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (const TArgs &... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (const std::string &name, const TArgs &... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachine * getStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachine * stateMachine_ = nullptr
 
ISmaccClient * owner_ = nullptr
 

Detailed Description

Definition at line 30 of file cp_table_segmenter.hpp.

Constructor & Destructor Documentation

◆ CpTableSegmenter()

cl_rgb::CpTableSegmenter::CpTableSegmenter ( const SegmenterParams & params)
explicit

Definition at line 22 of file cp_table_segmenter.cpp.

22: params_(params) {}
SegmenterParams params() const

◆ ~CpTableSegmenter()

cl_rgb::CpTableSegmenter::~CpTableSegmenter ( )
override

Definition at line 24 of file cp_table_segmenter.cpp.

24{}

Member Function Documentation

◆ foreground()

cv::Mat cl_rgb::CpTableSegmenter::foreground ( const cv::Mat & bgr,
const cv::Mat & tableMask ) const

Definition at line 72 of file cp_table_segmenter.cpp.

73{
74 cv::Mat reference;
75 {
76 std::lock_guard<std::mutex> lock(mutex_);
77 reference = reference_; // shares the pixels; they are never written after setReference
78 }
79 if (!reference.empty() && reference.size() == bgr.size())
80 {
81 return segmentAgainstReference(bgr, reference, tableMask, this->params());
82 }
83 return segmentForeground(bgr, tableMask, this->params());
84}
cv::Mat segmentAgainstReference(const cv::Mat &bgr, const cv::Mat &referenceBgr, const cv::Mat &tableMask, const SegmenterParams &params)
cv::Mat segmentForeground(const cv::Mat &bgr, const cv::Mat &tableMask, const SegmenterParams &params)

References mutex_, params(), reference_, cl_rgb::segmentAgainstReference(), and cl_rgb::segmentForeground().

Referenced by cl_rgb::CbSurveyTable::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasReference()

bool cl_rgb::CpTableSegmenter::hasReference ( ) const

Definition at line 54 of file cp_table_segmenter.cpp.

55{
56 std::lock_guard<std::mutex> lock(mutex_);
57 return !reference_.empty();
58}

References mutex_, and reference_.

◆ onInitialize()

void cl_rgb::CpTableSegmenter::onInitialize ( )
overridevirtual

Reimplemented from smacc2::ISmaccComponent.

Definition at line 26 of file cp_table_segmenter.cpp.

27{
28 const std::string path = this->params().referenceImagePath;
29 if (path.empty())
30 {
31 return;
32 }
33 const cv::Mat reference = cv::imread(path, cv::IMREAD_COLOR);
34 if (reference.empty())
35 {
36 RCLCPP_ERROR(
37 getLogger(),
38 "CpTableSegmenter: cannot read the reference image %s; segmenting by the table's own colour",
39 path.c_str());
40 return;
41 }
42 this->setReference(reference);
43 RCLCPP_INFO(
44 getLogger(), "CpTableSegmenter: reference image %s (%dx%d)", path.c_str(), reference.cols,
45 reference.rows);
46}
void setReference(const cv::Mat &bgr)
rclcpp::Logger getLogger() const

References smacc2::ISmaccComponent::getLogger(), params(), cl_rgb::SegmenterParams::referenceImagePath, and setReference().

Here is the call graph for this function:

◆ params()

SegmenterParams cl_rgb::CpTableSegmenter::params ( ) const

Definition at line 66 of file cp_table_segmenter.cpp.

67{
68 std::lock_guard<std::mutex> lock(mutex_);
69 return params_;
70}

References mutex_, and params_.

Referenced by foreground(), onInitialize(), and setParams().

Here is the caller graph for this function:

◆ setParams()

void cl_rgb::CpTableSegmenter::setParams ( const SegmenterParams & params)

Definition at line 60 of file cp_table_segmenter.cpp.

61{
62 std::lock_guard<std::mutex> lock(mutex_);
64}

References mutex_, params(), and params_.

Here is the call graph for this function:

◆ setReference()

void cl_rgb::CpTableSegmenter::setReference ( const cv::Mat & bgr)

Definition at line 48 of file cp_table_segmenter.cpp.

49{
50 std::lock_guard<std::mutex> lock(mutex_);
51 reference_ = bgr.clone();
52}

References mutex_, and reference_.

Referenced by onInitialize().

Here is the caller graph for this function:

Member Data Documentation

◆ mutex_

std::mutex cl_rgb::CpTableSegmenter::mutex_
mutableprivate

Definition at line 49 of file cp_table_segmenter.hpp.

Referenced by foreground(), hasReference(), params(), setParams(), and setReference().

◆ params_

SegmenterParams cl_rgb::CpTableSegmenter::params_
private

Definition at line 50 of file cp_table_segmenter.hpp.

Referenced by params(), and setParams().

◆ reference_

cv::Mat cl_rgb::CpTableSegmenter::reference_
private

Definition at line 51 of file cp_table_segmenter.hpp.

Referenced by foreground(), hasReference(), and setReference().


The documentation for this class was generated from the following files: