15 #include <gtest/gtest.h> 23 TEST(ImageConversion, roundTrip8UC3)
28 mapIn[
"layer"].setRandom();
29 const float minValue = -1.0;
30 const float maxValue = 1.0;
34 GridMapCvConverter::toImage<unsigned char, 3>(mapIn,
"layer", CV_8UC3, minValue, maxValue, image);
38 mapOut[
"layer"].setConstant(NAN);
39 GridMapCvConverter::addLayerFromImage<unsigned char, 3>(image,
"layer", mapOut, minValue, maxValue);
42 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
43 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
44 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
45 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
48 TEST(ImageConversion, roundTrip8UC4)
53 mapIn[
"layer"].setRandom();
54 mapIn[
"layer"](1, 2) = NAN;
55 const float minValue = -1.0;
56 const float maxValue = 1.0;
60 GridMapCvConverter::toImage<unsigned char, 4>(mapIn,
"layer", CV_8UC4, minValue, maxValue, image);
64 mapOut[
"layer"].setConstant(NAN);
65 GridMapCvConverter::addLayerFromImage<unsigned char, 4>(image,
"layer", mapOut, minValue, maxValue);
68 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
69 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
70 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
71 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
74 TEST(ImageConversion, roundTrip16UC1)
79 mapIn[
"layer"].setRandom();
80 const float minValue = -1.0;
81 const float maxValue = 1.0;
85 GridMapCvConverter::toImage<unsigned short, 1>(mapIn,
"layer", CV_16UC1, minValue, maxValue, image);
89 mapOut[
"layer"].setConstant(NAN);
90 GridMapCvConverter::addLayerFromImage<unsigned short, 1>(image,
"layer", mapOut, minValue, maxValue);
93 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
94 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
95 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
96 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
99 TEST(ImageConversion, roundTrip32FC1)
104 mapIn[
"layer"].setRandom();
105 const float minValue = -1.0;
106 const float maxValue = 1.0;
110 GridMapCvConverter::toImage<float, 1>(mapIn,
"layer", CV_32FC1, minValue, maxValue, image);
114 mapOut[
"layer"].setConstant(NAN);
115 GridMapCvConverter::addLayerFromImage<float, 1>(image,
"layer", mapOut, minValue, maxValue);
118 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
119 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
120 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
121 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
TEST(ImageConversion, roundTrip8UC3)
void expectNear(const M1 &A, const M2 &B, T tolerance, std::string const &message="")