| 1089 | } |
| 1090 | |
| 1091 | bool Reconstruction::ExtractColorsForImage(const image_t image_id, |
| 1092 | const std::filesystem::path& path) { |
| 1093 | const class Image& image = Image(image_id); |
| 1094 | |
| 1095 | Bitmap bitmap; |
| 1096 | if (!bitmap.Read(path / image.Name(), |
| 1097 | /*as_rgb=*/true)) { |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | const Eigen::Vector3ub kBlackColor(0, 0, 0); |
| 1102 | for (const Point2D& point2D : image.Points2D()) { |
| 1103 | if (point2D.HasPoint3D()) { |
| 1104 | struct Point3D& point3D = Point3D(point2D.point3D_id); |
| 1105 | if (point3D.color == kBlackColor) { |
| 1106 | // COLMAP assumes that the upper left pixel center is (0.5, 0.5). |
| 1107 | if (const auto color = bitmap.InterpolateBilinear( |
| 1108 | point2D.xy(0) - 0.5, point2D.xy(1) - 0.5)) { |
| 1109 | const BitmapColor<uint8_t> color_ub = color->Cast<uint8_t>(); |
| 1110 | point3D.color = Eigen::Vector3ub(color_ub.r, color_ub.g, color_ub.b); |
| 1111 | } |
| 1112 | } |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | return true; |
| 1117 | } |
| 1118 | |
| 1119 | void Reconstruction::ExtractColorsForAllImages( |
| 1120 | const std::filesystem::path& path, const int num_threads) { |
no test coverage detected