MCPcopy Create free account
hub / github.com/colmap/colmap / Extract

Method Extract

src/colmap/feature/aliked.cc:161–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159 }
160
161 bool Extract(const Bitmap& bitmap,
162 FeatureKeypoints* keypoints,
163 FeatureDescriptors* descriptors) override {
164 THROW_CHECK_NOTNULL(keypoints);
165 THROW_CHECK_NOTNULL(descriptors);
166 THROW_CHECK(bitmap.IsRGB());
167
168 const int width = bitmap.Width();
169 const int height = bitmap.Height();
170
171 std::vector<float> input = BitmapToInputTensor(bitmap);
172
173 // Pad image to dimensions divisible by 32.
174 InputPadder padder(height, width, /*divisor=*/32);
175 std::vector<float>* padded_input = padder.MaybePad(input, 3);
176
177 // Prepare image input tensor.
178 std::vector<int64_t> image_shape = model_.input_shapes()[0];
179 image_shape[0] = 1;
180 image_shape[1] = 3;
181 image_shape[2] = padder.padded_height;
182 image_shape[3] = padder.padded_width;
183
184 std::vector<Ort::Value> input_tensors;
185 input_tensors.emplace_back(Ort::Value::CreateTensor<float>(
186 Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtDeviceAllocator,
187 OrtMemType::OrtMemTypeCPU),
188 padded_input->data(),
189 padded_input->size(),
190 image_shape.data(),
191 image_shape.size()));
192
193 // Prepare max_keypoints input tensor (scalar).
194 int64_t max_keypoints = options_.aliked->max_num_features;
195 input_tensors.emplace_back(Ort::Value::CreateTensor<int64_t>(
196 Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtDeviceAllocator,
197 OrtMemType::OrtMemTypeCPU),
198 &max_keypoints,
199 1,
200 model_.input_shapes()[1].data(),
201 model_.input_shapes()[1].size()));
202
203 // Prepare min_score input tensor (scalar).
204 float min_score = static_cast<float>(options_.aliked->min_score);
205 input_tensors.emplace_back(Ort::Value::CreateTensor<float>(
206 Ort::MemoryInfo::CreateCpu(OrtAllocatorType::OrtDeviceAllocator,
207 OrtMemType::OrtMemTypeCPU),
208 &min_score,
209 1,
210 model_.input_shapes()[2].data(),
211 model_.input_shapes()[2].size()));
212
213 // Run model inference.
214 const std::vector<Ort::Value> output_tensors = model_.Run(input_tensors);
215 THROW_CHECK_EQ(output_tensors.size(), 3);
216
217 // Parse keypoints shape: [1, K, 2].
218 const std::vector<int64_t> keypoints_shape =

Callers

nothing calls this directly

Calls 7

BitmapToInputTensorFunction · 0.85
IsRGBMethod · 0.80
MaybePadMethod · 0.80
sizeMethod · 0.80
WidthMethod · 0.45
HeightMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected