5
5
6
6
#include " imageRotation.h"
7
7
8
- #include < algorithm>
9
- #include < cmath>
10
-
11
8
#include < yarp/os/LogComponent.h>
12
9
#include < yarp/os/LogStream.h>
10
+
13
11
#include < yarp/sig/Image.h>
12
+
13
+ #include < algorithm>
14
+ #include < cmath>
14
15
#include < opencv2/highgui/highgui.hpp>
15
16
#include < opencv2/imgproc/imgproc.hpp>
16
17
#include < opencv2/videoio/videoio.hpp>
@@ -29,62 +30,42 @@ YARP_LOG_COMPONENT(IMAGEROTATION,
29
30
30
31
bool ImageRotation::create (const yarp::os::Property& options)
31
32
{
32
- // parse the user parameters
33
+ // parse the user parameters
33
34
yarp::os::Property m_user_params;
34
35
yCDebug (IMAGEROTATION) << " user params:" << options.toString ();
35
36
std::string str = options.find (" carrier" ).asString ();
36
37
getParamsFromCommandLine (str, m_user_params);
37
38
yCDebug (IMAGEROTATION) << " parsed params:" << m_user_params.toString ();
38
39
39
- // get the value of the parameters
40
- if (m_user_params.check (" options_rotate" ))
41
- {
40
+ // get the value of the parameters
41
+ if (m_user_params.check (" options_rotate" )) {
42
42
m_options_rotate_str = m_user_params.find (" options_rotate" ).asString ();
43
43
}
44
- if (m_user_params.check (" options_flip" ))
45
- {
44
+ if (m_user_params.check (" options_flip" )) {
46
45
m_options_flip_str = m_user_params.find (" options_flip" ).asString ();
47
46
}
48
47
49
- // translate the parameters in opencv
50
- if (m_options_rotate_str == std::string (" rotate_cw" ))
51
- {
48
+ // translate the parameters in opencv
49
+ if (m_options_rotate_str == std::string (" rotate_cw" )) {
52
50
m_rot_flags = cv::ROTATE_90_CLOCKWISE;
53
- }
54
- else if (m_options_rotate_str == std::string (" rotate_ccw" ))
55
- {
51
+ } else if (m_options_rotate_str == std::string (" rotate_ccw" )) {
56
52
m_rot_flags = cv::ROTATE_90_COUNTERCLOCKWISE;
57
- }
58
- else if (m_options_rotate_str == std::string (" rotate_180" ))
59
- {
53
+ } else if (m_options_rotate_str == std::string (" rotate_180" )) {
60
54
m_rot_flags = cv::ROTATE_180;
61
- }
62
- else if (m_options_rotate_str == std::string (" rotate_none" ))
63
- {
64
- }
65
- else
66
- {
55
+ } else if (m_options_rotate_str == std::string (" rotate_none" )) {
56
+ } else {
67
57
yCDebug (IMAGEROTATION) << " Invalid value of `options_rotate` parameter" ;
68
58
return false ;
69
59
}
70
60
71
- if (m_options_flip_str == std::string (" flip_x" ))
72
- {
61
+ if (m_options_flip_str == std::string (" flip_x" )) {
73
62
m_flip_code = 0 ;
74
- }
75
- else if (m_options_flip_str == std::string (" flip_y" ))
76
- {
63
+ } else if (m_options_flip_str == std::string (" flip_y" )) {
77
64
m_flip_code = 1 ;
78
- }
79
- else if (m_options_flip_str == std::string (" flip_xy" ))
80
- {
65
+ } else if (m_options_flip_str == std::string (" flip_xy" )) {
81
66
m_flip_code = -1 ;
82
- }
83
- else if (m_options_flip_str == std::string (" flip_none" ))
84
- {
85
- }
86
- else
87
- {
67
+ } else if (m_options_flip_str == std::string (" flip_none" )) {
68
+ } else {
88
69
yCDebug (IMAGEROTATION) << " Invalid value of `options_flip` parameter" ;
89
70
return false ;
90
71
}
@@ -112,12 +93,10 @@ void ImageRotation::getParamsFromCommandLine(std::string carrierString, yarp::os
112
93
split (carrierString, ' +' , parameters);
113
94
114
95
// Iterate over result strings
115
- for (std::string param : parameters)
116
- {
96
+ for (std::string param : parameters) {
117
97
// If there is no '.', then the param is bad formatted, skip it.
118
98
auto pointPosition = param.find (' .' );
119
- if (pointPosition == std::string::npos)
120
- {
99
+ if (pointPosition == std::string::npos) {
121
100
continue ;
122
101
}
123
102
@@ -127,7 +106,7 @@ void ImageRotation::getParamsFromCommandLine(std::string carrierString, yarp::os
127
106
std::string s = param.substr (pointPosition + 1 , param.length ());
128
107
paramValue.fromString (s.c_str ());
129
108
130
- // and append to the returned property
109
+ // and append to the returned property
131
110
prop.put (paramKey, paramValue);
132
111
}
133
112
return ;
@@ -146,14 +125,11 @@ bool ImageRotation::getparam(yarp::os::Property& params)
146
125
bool ImageRotation::accept (yarp::os::Things& thing)
147
126
{
148
127
auto * img = thing.cast_as <yarp::sig::Image>();
149
- if (img == nullptr )
150
- {
128
+ if (img == nullptr ) {
151
129
yCError (IMAGEROTATION, " Expected type Image, but got wrong data type!" );
152
130
return false ;
153
131
}
154
- if (img->getPixelCode () != VOCAB_PIXEL_RGB &&
155
- img->getPixelCode () != VOCAB_PIXEL_MONO_FLOAT)
156
- {
132
+ if (img->getPixelCode () != VOCAB_PIXEL_RGB && img->getPixelCode () != VOCAB_PIXEL_MONO_FLOAT) {
157
133
yCError (IMAGEROTATION, " Received image with invalid/unsupported pixelCode!" );
158
134
return false ;
159
135
}
@@ -162,70 +138,53 @@ bool ImageRotation::accept(yarp::os::Things& thing)
162
138
163
139
yarp::os::Things& ImageRotation::update (yarp::os::Things& thing)
164
140
{
165
- yarp::sig::Image* yarpimg = thing.cast_as <yarp::sig::Image >();
166
- if (yarpimg->getPixelCode () == VOCAB_PIXEL_RGB)
167
- {
141
+ yarp::sig::Image* yarpimg = thing.cast_as <yarp::sig::Image>();
142
+ if (yarpimg->getPixelCode () == VOCAB_PIXEL_RGB) {
168
143
m_cvInImage = yarp::cv::toCvMat (*yarpimg);
169
144
170
145
m_outImgRgb.resize (yarpimg->width (), yarpimg->height ());
171
146
m_outImgRgb.zero ();
172
147
173
- if (m_options_flip_str == " flip_none" && m_options_rotate_str != " rotation_none" )
174
- {
175
- // just rotation
148
+ if (m_options_flip_str == " flip_none" && m_options_rotate_str != " rotation_none" ) {
149
+ // just rotation
176
150
cv::rotate (m_cvInImage, m_cvOutImage1, m_rot_flags);
177
151
m_outImgRgb = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(m_cvOutImage1);
178
- }
179
- else if (m_options_flip_str != " flip_none" && m_options_rotate_str == " rotation_none" )
180
- {
181
- // just flip
152
+ } else if (m_options_flip_str != " flip_none" && m_options_rotate_str == " rotation_none" ) {
153
+ // just flip
182
154
cv::flip (m_cvInImage, m_cvOutImage1, m_flip_code);
183
155
m_outImgRgb = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(m_cvOutImage1);
184
- }
185
- else if (m_options_flip_str == " flip_none" && m_options_rotate_str == " rotation_none" )
186
- {
187
- // just copy
156
+ } else if (m_options_flip_str == " flip_none" && m_options_rotate_str == " rotation_none" ) {
157
+ // just copy
188
158
m_outImgRgb = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(m_cvInImage);
189
- }
190
- else
191
- {
192
- // first a rotation, then a flip
159
+ } else {
160
+ // first a rotation, then a flip
193
161
cv::rotate (m_cvInImage, m_cvOutImage1, m_rot_flags);
194
162
cv::flip (m_cvOutImage1, m_cvOutImage2, m_flip_code);
195
163
m_outImgRgb = yarp::cv::fromCvMat<yarp::sig::PixelRgb>(m_cvOutImage2);
196
164
}
197
165
m_th.setPortWriter (&m_outImgRgb);
198
- }
199
- else if (yarpimg->getPixelCode () == VOCAB_PIXEL_MONO_FLOAT)
200
- {
166
+ } else if (yarpimg->getPixelCode () == VOCAB_PIXEL_MONO_FLOAT) {
201
167
m_cvInImage = yarp::cv::toCvMat (*yarpimg);
202
168
203
169
m_outImgFloat.resize (yarpimg->width (), yarpimg->height ());
204
170
m_outImgFloat.zero ();
205
171
206
- if (m_options_flip_str == " flip_none" )
207
- {
172
+ if (m_options_flip_str == " flip_none" ) {
208
173
// just rotation
209
174
cv::rotate (m_cvInImage, m_cvOutImage1, m_rot_flags);
210
175
m_outImgFloat = yarp::cv::fromCvMat<yarp::sig::PixelFloat>(m_cvOutImage1);
211
- }
212
- else if (m_options_flip_str == " rotation_none" )
213
- {
176
+ } else if (m_options_flip_str == " rotation_none" ) {
214
177
// just flip
215
178
cv::flip (m_cvInImage, m_cvOutImage1, m_flip_code);
216
179
m_outImgFloat = yarp::cv::fromCvMat<yarp::sig::PixelFloat>(m_cvOutImage1);
217
- }
218
- else
219
- {
180
+ } else {
220
181
// first a rotation, then a flip
221
182
cv::rotate (m_cvInImage, m_cvOutImage1, m_rot_flags);
222
183
cv::flip (m_cvOutImage1, m_cvOutImage2, m_flip_code);
223
184
m_outImgFloat = yarp::cv::fromCvMat<yarp::sig::PixelFloat>(m_cvOutImage2);
224
185
}
225
186
m_th.setPortWriter (&m_outImgFloat);
226
- }
227
- else
228
- {
187
+ } else {
229
188
yCError (IMAGEROTATION, " Invalid Image type!" );
230
189
}
231
190
return m_th;
0 commit comments