15 #include <gtest/gtest.h> 25 for(
int r = 0; r < m.rows(); r++)
27 for(
int c = 0; c < m.cols(); c++)
29 if (std::isnan(m(r,c)))
37 TEST(ImageConversion, roundTrip8UC3)
42 mapIn[
"layer"].setRandom();
44 const float minValue = -1.0;
45 const float maxValue = 1.0;
50 GridMapCvConverter::toImage<unsigned char, 3>(mapIn,
"layer", CV_8UC3, minValue, maxValue, image);
54 mapOut[
"layer"].setConstant(NAN);
55 GridMapCvConverter::addLayerFromImage<unsigned char, 3>(image,
"layer", mapOut, minValue, maxValue);
58 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
59 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
60 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
61 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
64 TEST(ImageConversion, roundTrip8UC4)
69 mapIn[
"layer"].setRandom();
71 const float minValue = -1.0;
72 const float maxValue = 1.0;
77 GridMapCvConverter::toImage<unsigned char, 4>(mapIn,
"layer", CV_8UC4, minValue, maxValue, image);
81 mapOut[
"layer"].setConstant(NAN);
82 GridMapCvConverter::addLayerFromImage<unsigned char, 4>(image,
"layer", mapOut, minValue, maxValue);
85 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
86 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
87 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
88 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
91 TEST(ImageConversion, roundTrip16UC1)
96 mapIn[
"layer"].setRandom();
98 const float minValue = -1.0;
99 const float maxValue = 1.0;
104 GridMapCvConverter::toImage<unsigned short, 1>(mapIn,
"layer", CV_16UC1, minValue, maxValue, image);
108 mapOut[
"layer"].setConstant(NAN);
109 GridMapCvConverter::addLayerFromImage<unsigned short, 1>(image,
"layer", mapOut, minValue, maxValue);
112 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
113 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
114 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
115 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
118 TEST(ImageConversion, roundTrip32FC1)
123 mapIn[
"layer"].setRandom();
125 const float minValue = -1.0;
126 const float maxValue = 1.0;
131 GridMapCvConverter::toImage<float, 1>(mapIn,
"layer", CV_32FC1, minValue, maxValue, image);
135 mapOut[
"layer"].setConstant(NAN);
136 GridMapCvConverter::addLayerFromImage<float, 1>(image,
"layer", mapOut, minValue, maxValue);
139 const float resolution = (maxValue - minValue) / (
float) std::numeric_limits<unsigned char>::max();
140 expectNear(mapIn[
"layer"], mapOut[
"layer"], resolution,
"");
141 EXPECT_TRUE((mapIn.getLength() == mapOut.getLength()).all());
142 EXPECT_TRUE((mapIn.getSize() == mapOut.getSize()).all());
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
void replaceNan(Matrix &m, const double newValue)
TEST(ImageConversion, roundTrip8UC3)
void expectNear(const M1 &A, const M2 &B, T tolerance, std::string const &message="")