34 #include <gtest/gtest.h> 36 #include <opencv2/core/core.hpp> 77 TEST(ImageUtilTests, GetOverlappingArea1)
79 cv::Rect rect(-5, -5, 10, 10);
80 cv::Rect rect2(-10, -5, 20, 10);
82 cv::Mat identity(2, 3, CV_32FC1);
83 identity.at<
float>(0,0) = 1;
84 identity.at<
float>(0,1) = 0;
85 identity.at<
float>(0,2) = 0;
86 identity.at<
float>(1,0) = 0;
87 identity.at<
float>(1,1) = 1;
88 identity.at<
float>(1,2) = 0;
93 cv::Mat shift_15_x(2, 3, CV_32FC1);
94 shift_15_x.at<
float>(0,0) = 1;
95 shift_15_x.at<
float>(0,1) = 0;
96 shift_15_x.at<
float>(0,2) = 15;
97 shift_15_x.at<
float>(1,0) = 0;
98 shift_15_x.at<
float>(1,1) = 1;
99 shift_15_x.at<
float>(1,2) = 0;
104 cv::Mat shift_5_x(2, 3, CV_32FC1);
105 shift_5_x.at<
float>(0,0) = 1;
106 shift_5_x.at<
float>(0,1) = 0;
107 shift_5_x.at<
float>(0,2) = 5;
108 shift_5_x.at<
float>(1,0) = 0;
109 shift_5_x.at<
float>(1,1) = 1;
110 shift_5_x.at<
float>(1,2) = 0;
115 cv::Mat shift_5_xy(2, 3, CV_32FC1);
116 shift_5_xy.at<
float>(0,0) = 1;
117 shift_5_xy.at<
float>(0,1) = 0;
118 shift_5_xy.at<
float>(0,2) = 5;
119 shift_5_xy.at<
float>(1,0) = 0;
120 shift_5_xy.at<
float>(1,1) = 1;
121 shift_5_xy.at<
float>(1,2) = 5;
127 TEST(ImageUtilTests, GetOverlappingArea2)
129 cv::Rect rect(-5, -5, 10, 10);
130 cv::Rect rect2(-10, -5, 20, 10);
132 cv::Mat rotate90(2, 3, CV_32FC1);
133 rotate90.at<
float>(0,0) = 0;
134 rotate90.at<
float>(0,1) = 1;
135 rotate90.at<
float>(0,2) = 0;
136 rotate90.at<
float>(1,0) = -1;
137 rotate90.at<
float>(1,1) = 0;
138 rotate90.at<
float>(1,2) = 0;
143 cv::Mat rotate180(2, 3, CV_32FC1);
144 rotate180.at<
float>(0,0) = -1;
145 rotate180.at<
float>(0,1) = 0;
146 rotate180.at<
float>(0,2) = 0;
147 rotate180.at<
float>(1,0) = 0;
148 rotate180.at<
float>(1,1) = -1;
149 rotate180.at<
float>(1,2) = 0;
154 cv::Mat rotate45(2, 3, CV_32FC1);
157 rotate45.at<
float>(0,2) = 0;
160 rotate45.at<
float>(1,2) = 0;
166 TEST(ImageUtilTests, TestProjectEllipse1)
168 cv::Mat ellipsoid1(3, 3, CV_32FC1);
169 ellipsoid1.at<
float>(0,0) = 1;
170 ellipsoid1.at<
float>(0,1) = 0;
171 ellipsoid1.at<
float>(0,2) = 0;
172 ellipsoid1.at<
float>(1,0) = 0;
173 ellipsoid1.at<
float>(1,1) = 1;
174 ellipsoid1.at<
float>(1,2) = 0;
175 ellipsoid1.at<
float>(2,0) = 0;
176 ellipsoid1.at<
float>(2,1) = 0;
177 ellipsoid1.at<
float>(2,2) = 1;
179 cv::Mat ellipse1(2, 2, CV_32FC1);
180 ellipse1.at<
float>(0,0) = 1;
181 ellipse1.at<
float>(0,1) = 0;
182 ellipse1.at<
float>(1,0) = 0;
183 ellipse1.at<
float>(1,1) = 1;
187 EXPECT_EQ(ellipse1.at<
float>(0, 0), projected1.at<
float>(0, 0));
188 EXPECT_EQ(ellipse1.at<
float>(0, 1), projected1.at<
float>(0, 1));
189 EXPECT_EQ(ellipse1.at<
float>(1, 0), projected1.at<
float>(1, 0));
190 EXPECT_EQ(ellipse1.at<
float>(1, 1), projected1.at<
float>(1, 1));
193 TEST(ImageUtilTests, TestProjectEllipse2)
195 cv::Mat ellipsoid1(3, 3, CV_32FC1);
196 ellipsoid1.at<
float>(0,0) = 10;
197 ellipsoid1.at<
float>(0,1) = 0;
198 ellipsoid1.at<
float>(0,2) = 0;
199 ellipsoid1.at<
float>(1,0) = 0;
200 ellipsoid1.at<
float>(1,1) = 15;
201 ellipsoid1.at<
float>(1,2) = 0;
202 ellipsoid1.at<
float>(2,0) = 0;
203 ellipsoid1.at<
float>(2,1) = 0;
204 ellipsoid1.at<
float>(2,2) = -35;
206 cv::Mat ellipse1(2, 2, CV_32FC1);
207 ellipse1.at<
float>(0,0) = 10;
208 ellipse1.at<
float>(0,1) = 0;
209 ellipse1.at<
float>(1,0) = 0;
210 ellipse1.at<
float>(1,1) = 15;
214 EXPECT_EQ(ellipse1.at<
float>(0, 0), projected1.at<
float>(0, 0));
215 EXPECT_EQ(ellipse1.at<
float>(0, 1), projected1.at<
float>(0, 1));
216 EXPECT_EQ(ellipse1.at<
float>(1, 0), projected1.at<
float>(1, 0));
217 EXPECT_EQ(ellipse1.at<
float>(1, 1), projected1.at<
float>(1, 1));
220 TEST(ImageUtilTests, TestProjectEllipse3)
222 cv::Mat ellipsoid1(3, 3, CV_32FC1);
223 ellipsoid1.at<
float>(0,0) = 10;
224 ellipsoid1.at<
float>(0,1) = 0;
225 ellipsoid1.at<
float>(0,2) = 0;
226 ellipsoid1.at<
float>(1,0) = 0;
227 ellipsoid1.at<
float>(1,1) = 15;
228 ellipsoid1.at<
float>(1,2) = 0;
229 ellipsoid1.at<
float>(2,0) = 0;
230 ellipsoid1.at<
float>(2,1) = 0;
231 ellipsoid1.at<
float>(2,2) = std::numeric_limits<double>::max() * 0.5;
233 cv::Mat ellipse1(2, 2, CV_32FC1);
234 ellipse1.at<
float>(0,0) = 10;
235 ellipse1.at<
float>(0,1) = 0;
236 ellipse1.at<
float>(1,0) = 0;
237 ellipse1.at<
float>(1,1) = 15;
241 EXPECT_EQ(ellipse1.at<
float>(0, 0), projected1.at<
float>(0, 0));
242 EXPECT_EQ(ellipse1.at<
float>(0, 1), projected1.at<
float>(0, 1));
243 EXPECT_EQ(ellipse1.at<
float>(1, 0), projected1.at<
float>(1, 0));
244 EXPECT_EQ(ellipse1.at<
float>(1, 1), projected1.at<
float>(1, 1));
250 TEST(ImageUtilTests, TestProjectEllipseInvalid1)
252 cv::Mat ellipsoid2(3, 3, CV_32FC1);
253 ellipsoid2.at<
float>(0,0) = 1;
254 ellipsoid2.at<
float>(0,1) = 0;
255 ellipsoid2.at<
float>(0,2) = 0;
256 ellipsoid2.at<
float>(1,0) = 0;
257 ellipsoid2.at<
float>(1,1) = 1;
258 ellipsoid2.at<
float>(1,2) = 0;
259 ellipsoid2.at<
float>(2,0) = 0;
260 ellipsoid2.at<
float>(2,1) = 0;
261 ellipsoid2.at<
float>(2,2) = 0;
265 EXPECT_TRUE(projected2.empty());
268 TEST(ImageUtilTests, TestProjectEllipseInvalid2)
270 cv::Mat ellipsoid2(2, 2, CV_32FC1);
271 ellipsoid2.at<
float>(0,0) = 1;
272 ellipsoid2.at<
float>(0,1) = 0;
273 ellipsoid2.at<
float>(1,0) = 0;
274 ellipsoid2.at<
float>(1,1) = 1;
278 EXPECT_TRUE(projected2.empty());
281 TEST(ImageUtilTests, TestProjectEllipseInvalid3)
283 cv::Mat ellipsoid2(2, 2, CV_32SC1);
284 ellipsoid2.at<int32_t>(0,0) = 1;
285 ellipsoid2.at<int32_t>(0,1) = 0;
286 ellipsoid2.at<int32_t>(1,0) = 0;
287 ellipsoid2.at<int32_t>(1,1) = 1;
291 EXPECT_TRUE(projected2.empty());
294 TEST(ImageUtilTests, TestGetEllipsePoints1)
296 cv::Mat ellipse(2, 2, CV_32FC1);
297 ellipse.at<
float>(0,0) = 1;
298 ellipse.at<
float>(0,1) = 0;
299 ellipse.at<
float>(1,0) = 0;
300 ellipse.at<
float>(1,1) = 1;
305 ASSERT_EQ(8, points.size());
307 EXPECT_FLOAT_EQ(1, points[0].
x());
308 EXPECT_NEAR(0, points[0].
y(), 0.000000001);
310 EXPECT_NEAR(0.7071067811865475243818940365, points[1].
x(), 0.000000001);
311 EXPECT_NEAR(0.7071067811865475243818940365, points[1].
y(), 0.000000001);
313 EXPECT_NEAR(0, points[2].
x(), 0.000000001);
314 EXPECT_FLOAT_EQ(1, points[2].
y());
316 EXPECT_NEAR(-0.7071067811865475243818940365, points[3].
x(), 0.000000001);
317 EXPECT_NEAR(0.7071067811865475243818940365, points[3].
y(), 0.000000001);
319 EXPECT_FLOAT_EQ(-1, points[4].
x());
320 EXPECT_NEAR(0, points[4].
y(), 0.000000001);
322 EXPECT_NEAR(-0.7071067811865475243818940365, points[5].
x(), 0.000000001);
323 EXPECT_NEAR(-0.7071067811865475243818940365, points[5].
y(), 0.000000001);
325 EXPECT_NEAR(0, points[6].
x(), 0.000000001);
326 EXPECT_FLOAT_EQ(-1, points[6].
y());
328 EXPECT_NEAR(0.7071067811865475243818940365, points[7].
x(), 0.000000001);
329 EXPECT_NEAR(-0.7071067811865475243818940365, points[7].
y(), 0.000000001);
333 int main(
int argc,
char **argv)
335 testing::InitGoogleTest(&argc, argv);
337 return RUN_ALL_TESTS();
static const long double _half_pi
cv::Mat ProjectEllipsoid(const cv::Mat &ellipsiod)
double GetOverlappingArea(const cv::Rect &rect, const cv::Mat &rigid_transform)
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool Intersects(const BoundingBox &box1, const BoundingBox &box2)
std::vector< tf::Vector3 > GetEllipsePoints(const cv::Mat &ellipse, const tf::Vector3 ¢er, double scale, int32_t num_points)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)
TEST(ImageUtilTests, Intersects)
cv::Rect_< double > BoundingBox