| 15 | } |
| 16 | |
| 17 | TEST(common, valid_cases_1) |
| 18 | { |
| 19 | // create an example perspective camera |
| 20 | constexpr unsigned int cols = 2000; |
| 21 | constexpr unsigned int rows = 1000; |
| 22 | auto cam = create_perspective_camera(cols, rows, -0.1, 0.1); |
| 23 | // create keypoints and those grid IDs |
| 24 | std::vector<std::pair<cv::KeyPoint, std::pair<int, int>>> test_cases; |
| 25 | constexpr float eps = 0.01; |
| 26 | // - corners |
| 27 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.min_x_, cam.img_bounds_.min_y_, 0.0}, |
| 28 | std::make_pair(0, 0))); // top left |
| 29 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.max_x_ - eps, cam.img_bounds_.min_y_, 0.0}, |
| 30 | std::make_pair(cam.num_grid_cols_ - 1, 0))); // top right |
| 31 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.min_x_, cam.img_bounds_.max_y_ - eps, 0.0}, |
| 32 | std::make_pair(0, cam.num_grid_rows_ - 1))); // bottop left |
| 33 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.max_x_ - eps, cam.img_bounds_.max_y_ - eps, 0.0}, |
| 34 | std::make_pair(cam.num_grid_cols_ - 1, cam.num_grid_rows_ - 1))); // bottom right |
| 35 | // - edges |
| 36 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cols / 2.0, cam.img_bounds_.min_y_, 0.0}, |
| 37 | std::make_pair(cam.num_grid_cols_ / 2 - 1, 0))); // top center |
| 38 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cols / 2.0, cam.img_bounds_.max_y_ - eps, 0.0}, |
| 39 | std::make_pair(cam.num_grid_cols_ / 2 - 1, cam.num_grid_rows_ - 1))); // bottom center |
| 40 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.min_x_, rows / 2.0, 0.0}, |
| 41 | std::make_pair(0, cam.num_grid_rows_ / 2 - 1))); // left center |
| 42 | test_cases.emplace_back(std::make_pair(cv::KeyPoint{cam.img_bounds_.max_x_ - eps, rows / 2.0, 0.0}, |
| 43 | std::make_pair(cam.num_grid_cols_ - 1, cam.num_grid_rows_ / 2 - 1))); // right center |
| 44 | |
| 45 | // check |
| 46 | for (const auto &test_case : test_cases) |
| 47 | { |
| 48 | // extract information |
| 49 | const auto &keypt = test_case.first; |
| 50 | const auto idx_x = test_case.second.first; |
| 51 | const auto idx_y = test_case.second.second; |
| 52 | // run the function |
| 53 | int est_idx_x = -1; |
| 54 | int est_idx_y = -1; |
| 55 | const auto found = data::get_cell_indices(&cam, keypt, est_idx_x, est_idx_y); |
| 56 | EXPECT_TRUE(found); |
| 57 | EXPECT_EQ(est_idx_x, idx_x); |
| 58 | EXPECT_EQ(est_idx_y, idx_y); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | TEST(common, valid_cases_2) |
| 63 | { |
nothing calls this directly
no test coverage detected