YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
image_rotationTest.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/sig/Image.h>
12
14
15#include <array>
16#include <thread>
17
18#include <catch2/catch_amalgamated.hpp>
19#include <harness.h>
20
21TEST_CASE("pm::image_rotationTest", "[yarp::pm]")
22{
23 YARP_REQUIRE_PLUGIN("image_rotation", "portmonitor")
24
26
29
30 struct TestCase {
31 std::string carrier;
32 size_t expected_width;
33 size_t expected_height;
34 };
35
36 auto tc = GENERATE(
37 // No rotation - dimensions stay same
38 TestCase {"fast_tcp", 32, 16},
39 // 90 degree clockwise rotation - dimensions swap
40 TestCase {"fast_tcp+recv.portmonitor+file.image_rotation+options_rotate.rotate_cw+type.dll", 16, 32},
41 // 90 degree counter-clockwise rotation - dimensions swap
42 TestCase {"fast_tcp+recv.portmonitor+file.image_rotation+options_rotate.rotate_ccw+type.dll", 16, 32},
43 // 180 degree rotation - dimensions stay same
44 TestCase {"fast_tcp+recv.portmonitor+file.image_rotation+options_rotate.rotate_180+type.dll", 32, 16}
45 );
46
47 SECTION("Test image rotation with expected dimensions: " + std::to_string(tc.expected_width) + "x" + std::to_string(tc.expected_height))
48 {
51
52 sender.open("/send");
53 receiver.open("/recv");
54
55 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
56 REQUIRE(b);
57
58 // Create a test image with known dimensions (wider than tall)
59 const size_t original_width = 32;
60 const size_t original_height = 16;
61
63 img.resize(original_width, original_height);
64
65 // Fill with a pattern to verify rotation
66 for (size_t y = 0; y < original_height; y++) {
67 for (size_t x = 0; x < original_width; x++) {
68 img.pixel(x, y).r = static_cast<unsigned char>(x * 11);
69 img.pixel(x, y).g = static_cast<unsigned char>(y * 22);
70 img.pixel(x, y).b = 128;
71 }
72 }
73
74 sender.write();
75
77
78 yarp::sig::ImageOf<yarp::sig::PixelRgb>* received = receiver.read();
79 REQUIRE(received != nullptr);
80
81 // Verify dimensions changed according to rotation
82 CHECK(received->width() == tc.expected_width);
83 CHECK(received->height() == tc.expected_height);
84
85 receiver.close();
86 sender.close();
87 }
88
90}
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 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:751
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1118
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
Typed image class.
Definition Image.h:603
T & pixel(size_t x, size_t y)
Definition Image.h:619
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
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
TEST_CASE("pm::image_rotationTest", "[yarp::pm]")
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