RobotsIO
Loading...
Searching...
No Matches
SegmentationYarpPort.cpp
1/*
2 * Copyright (C) 2021 Istituto Italiano di Tecnologia (IIT)
3 *
4 * This software may be modified and distributed under the terms of the
5 * BSD 3-Clause license. See the accompanying LICENSE file for details.
6 */
7
8#include <RobotsIO/Utils/SegmentationYarpPort.h>
9
10#include <yarp/cv/Cv.h>
11
12using namespace RobotsIO::Utils;
13using namespace yarp::cv;
14using namespace yarp::sig;
15
16
17SegmentationYarpPort::SegmentationYarpPort(const std::string& port_prefix, const bool& provide_rgb) :
18 segmentation_in_(port_prefix + "/segmentation:i"),
19 rgb_out_(port_prefix + "/rgb:o"),
20 provide_rgb_(provide_rgb)
21{}
22
23
24SegmentationYarpPort::~SegmentationYarpPort()
25{}
26
27
28bool SegmentationYarpPort::reset()
29{
30 segmentation_in_.flush();
31
32 return true;
33}
34
35
36bool SegmentationYarpPort::is_stepping_required() const
37{
38 return false;
39}
40
41
43{
44 return -1;
45}
46
47
48std::pair<bool, cv::Mat> SegmentationYarpPort::segmentation(const bool& blocking)
49{
50 ImageOf<PixelMono>* yarp_mask = segmentation_in_.receive_data(blocking);
51
52 if (yarp_mask == nullptr)
53 {
54 cv_mask_in_ = cv::Mat();
55 return std::make_pair(false, cv::Mat());
56 }
57
58 yarp_mask_in_.copy(*yarp_mask);
59 cv_mask_in_ = toCvMat(yarp_mask_in_);
60 time_stamp_mask_in_ = segmentation_in_.time_stamp();
61
62 return std::make_pair(true, cv_mask_in_);
63}
64
65
67{
68 if (cv_mask_in_.empty())
69 return std::make_pair(false, cv::Mat());
70
71 return std::make_pair(true, cv_mask_in_);
72}
73
74
76{
77 return time_stamp_mask_in_;
78}
79
80
81void SegmentationYarpPort::set_rgb_image(const cv::Mat& image, const double& timestamp)
82{
83 if (!provide_rgb_)
84 return;
85
86 cv_rgb_out_ = image.clone();
87 yarp_rgb_out_ = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(cv_rgb_out_);
88
89 rgb_out_.set_time_stamp(timestamp);
90 rgb_out_.send_data(yarp_rgb_out_);
91}
std::pair< bool, cv::Mat > segmentation(const bool &blocking) override
virtual void set_rgb_image(const cv::Mat &image, const double &timestamp) override
SegmentationYarpPort(const std::string &port_prefix, const bool &provide_rgb)
std::pair< bool, cv::Mat > latest_segmentation() override