YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
segmentationimage_to_rgbTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
11#include <yarp/os/Carriers.h>
12#include <yarp/sig/Image.h>
13
15
16#include <array>
17#include <thread>
18
19#include <catch2/catch_amalgamated.hpp>
20#include <harness.h>
21
22TEST_CASE("pm::segmentationimage_to_rgbTest", "[yarp::pm]")
23{
24 YARP_REQUIRE_PLUGIN("segmentationimage_to_rgb", "portmonitor")
25
27
29
30 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
31
33
34 struct TestCase {
35 std::string carrier;
36 bool use_converter;
37 };
38
39 auto tc = GENERATE(
40 TestCase {"fast_tcp", false},
41 TestCase {"fast_tcp+recv.portmonitor+file.segmentationimage_to_rgb+type.dll", true}
42 );
43
44 SECTION("Test segmentation image to RGB conversion")
45 {
48
49 sender.open("/send");
50 receiver.open("/recv");
51
52 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
53 REQUIRE(b);
54
55 // Create a test segmentation image (mono image with pixel codes)
56 const size_t width = 16;
57 const size_t height = 16;
58
59 yarp::sig::FlexImage& img = sender.prepare();
61 img.resize(width, height);
62
63 // Fill with some segmentation labels (0-255)
64 unsigned char* rawImg = img.getRawImage();
65 for (size_t y = 0; y < height; y++) {
66 for (size_t x = 0; x < width; x++) {
67 unsigned char label = static_cast<unsigned char>((x + y) % 10);
68 rawImg[y * width + x] = label;
69 }
70 }
71
72 sender.write();
73
75
76 yarp::sig::FlexImage* received = receiver.read();
77 REQUIRE(received != nullptr);
78
79 CHECK(received->width() == width);
80 CHECK(received->height() == height);
81
82 if (tc.use_converter) {
83 // Should be converted to RGB
84 CHECK(received->getPixelCode() == VOCAB_PIXEL_RGB);
85 } else {
86 // Should remain mono
87 CHECK(received->getPixelCode() == VOCAB_PIXEL_MONO);
88 }
89
90 receiver.close();
91 sender.close();
92 }
93
95}
@ VOCAB_PIXEL_MONO
Definition Image.h:42
@ VOCAB_PIXEL_RGB
Definition Image.h:44
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
Definition Carriers.cpp:238
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:784
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
Image class with user control of representation details.
Definition Image.h:361
void setPixelCode(int imgPixelCode)
Definition Image.h:364
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
unsigned char * getRawImage() const
Access to the internal image buffer.
Definition Image.cpp:462
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:387
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:375
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16
TEST_CASE("pm::segmentationimage_to_rgbTest", "[yarp::pm]")