| 58 | } |
| 59 | |
| 60 | void MaskFeatures(const Bitmap& mask, |
| 61 | FeatureKeypoints* keypoints, |
| 62 | FeatureDescriptors* descriptors) { |
| 63 | size_t out_index = 0; |
| 64 | for (size_t i = 0; i < keypoints->size(); ++i) { |
| 65 | const auto color = mask.GetPixel(static_cast<int>(keypoints->at(i).x), |
| 66 | static_cast<int>(keypoints->at(i).y)); |
| 67 | if (!color || color->r == 0) { |
| 68 | // Delete this keypoint by not copying it to the output. |
| 69 | } else { |
| 70 | // Retain this keypoint by copying it to the output index (in case this |
| 71 | // index differs from its current position). |
| 72 | if (out_index != i) { |
| 73 | keypoints->at(out_index) = keypoints->at(i); |
| 74 | for (int col = 0; col < descriptors->data.cols(); ++col) { |
| 75 | descriptors->data(out_index, col) = descriptors->data(i, col); |
| 76 | } |
| 77 | } |
| 78 | out_index += 1; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | keypoints->resize(out_index); |
| 83 | descriptors->data.conservativeResize(out_index, descriptors->data.cols()); |
| 84 | } |
| 85 | |
| 86 | struct ImageData { |
| 87 | ImageReader::Status status = ImageReader::Status::FAILURE; |