YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
imageRotation.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "imageRotation.h"
7
9#include <yarp/os/LogStream.h>
10
11#include <yarp/sig/Image.h>
12#include <yarp/sig/ImageUtils.h>
13
14#include <algorithm>
15#include <cmath>
16
17using namespace yarp::os;
18using namespace yarp::sig;
19
20namespace {
22 "yarp.carrier.portmonitor.image_rotation",
26 nullptr)
27
28} //anonymous namespace
29
31{
32 if (options.check("options_rotate"))
33 {
34 const std::string val = options.find("options_rotate").asString();
35 if (val == "rotate_cw") { m_rotate_option = yarp::sig::utils::RotateOption::rotate_cw; }
36 else if (val == "rotate_ccw") { m_rotate_option = yarp::sig::utils::RotateOption::rotate_ccw; }
37 else if (val == "rotate_180") { m_rotate_option = yarp::sig::utils::RotateOption::rotate_180; }
38 else if (val == "rotate_none"){ m_rotate_option = yarp::sig::utils::RotateOption::rotate_none; }
39 else
40 {
41 yCDebug(IMAGEROTATION) << "Invalid value of `options_rotate` parameter:" << val;
42 return false;
43 }
44 }
45
46 if (options.check("options_flip"))
47 {
48 const std::string val = options.find("options_flip").asString();
49 if (val == "flip_x") { m_flip_option = yarp::sig::utils::FlipOption::flip_x; }
50 else if (val == "flip_y") { m_flip_option = yarp::sig::utils::FlipOption::flip_y; }
51 else if (val == "flip_xy") { m_flip_option = yarp::sig::utils::FlipOption::flip_xy; }
52 else if (val == "flip_none"){ m_flip_option = yarp::sig::utils::FlipOption::flip_none; }
53 else
54 {
55 yCDebug(IMAGEROTATION) << "Invalid value of `options_flip` parameter:" << val;
56 return false;
57 }
58 }
59
60 return true;
61}
62
66
68{
69 return false;
70}
71
73{
74 return false;
75}
76
78{
79 auto* img = thing.cast_as<yarp::sig::Image>();
80 if (img == nullptr) {
81 yCError(IMAGEROTATION, "Expected type Image, but got wrong data type!");
82 return false;
83 }
84 if (img->getPixelCode() != VOCAB_PIXEL_RGB && img->getPixelCode() != VOCAB_PIXEL_MONO_FLOAT) {
85 yCError(IMAGEROTATION, "Received image with invalid/unsupported pixelCode!");
86 return false;
87 }
88 return true;
89}
90
92{
93 yarp::sig::Image* yarpimg = thing.cast_as<yarp::sig::Image>();
94 if (yarpimg->getPixelCode() == VOCAB_PIXEL_RGB)
95 {
96 yarp::sig::utils::rotate(m_outImgRgb, *yarpimg, m_rotate_option, m_flip_option);
97 m_th.setPortWriter(&m_outImgRgb);
98 }
99 else if (yarpimg->getPixelCode() == VOCAB_PIXEL_MONO_FLOAT)
100 {
101 yarp::sig::utils::rotate(m_outImgFloat, *yarpimg, m_rotate_option, m_flip_option);
102 m_th.setPortWriter(&m_outImgFloat);
103 }
104 else {
105 yCError(IMAGEROTATION, "Invalid Image type!");
106 }
107 return m_th;
108}
@ VOCAB_PIXEL_MONO_FLOAT
Definition Image.h:53
@ VOCAB_PIXEL_RGB
Definition Image.h:44
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
void destroy() override
This will be called when the portmonitor object destroyes.
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:892
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:852
@ LogTypeReserved
Definition Log.h:98
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Base class for generic things.
Definition Things.h:18
T * cast_as()
Definition Things.h:53
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
Definition Things.cpp:26
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
Base class for storing images.
Definition Image.h:79
virtual int getPixelCode() const
Gets pixel type identifier.
Definition Image.cpp:375
#define yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13
bool rotate(yarp::sig::Image &OutImg, const yarp::sig::Image &InImg, RotateOption rotateflag=RotateOption::rotate_none, FlipOption flipflag=FlipOption::flip_none)
Rotate and/or flip an image.