| 35 | } |
| 36 | |
| 37 | TEST(ImageConversion, roundTrip8UC3) |
| 38 | { |
| 39 | // Create grid map. |
| 40 | GridMap mapIn({"layer"}); |
| 41 | mapIn.setGeometry(grid_map::Length(2.0, 1.0), 0.1); |
| 42 | mapIn["layer"].setRandom(); // Sets the layer to random values in [-1.0, 1.0]. |
| 43 | mapIn.move(Position(0.5, -0.2)); |
| 44 | const float minValue = -1.0; |
| 45 | const float maxValue = 1.0; |
| 46 | replaceNan(mapIn.get("layer"), minValue); // When we move `mapIn`, new areas are filled with NaN. As `toImage` does not support NaN, we replace NaN with `minValue` instead. |
| 47 | |
| 48 | // Convert to image. |
| 49 | cv::Mat image; |
| 50 | GridMapCvConverter::toImage<unsigned char, 3>(mapIn, "layer", CV_8UC3, minValue, maxValue, image); |
| 51 | |
| 52 | // Convert back to grid map. |
| 53 | GridMap mapOut(mapIn); |
| 54 | mapOut["layer"].setConstant(NAN); |
| 55 | GridMapCvConverter::addLayerFromImage<unsigned char, 3>(image, "layer", mapOut, minValue, maxValue); |
| 56 | |
| 57 | // Check data. |
| 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()); |
| 62 | } |
| 63 | |
| 64 | TEST(ImageConversion, roundTrip8UC4) |
| 65 | { |
nothing calls this directly
no test coverage detected