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

Function LoadSiftFeaturesFromTextFile

src/colmap/feature/sift.cc:1575–1621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1573}
1574
1575void LoadSiftFeaturesFromTextFile(const std::filesystem::path& path,
1576 FeatureKeypoints* keypoints,
1577 FeatureDescriptors* descriptors) {
1578 THROW_CHECK_NOTNULL(keypoints);
1579 THROW_CHECK_NOTNULL(descriptors);
1580
1581 std::ifstream file(path);
1582 THROW_CHECK_FILE_OPEN(file, path);
1583 file.imbue(std::locale::classic());
1584
1585 std::string line;
1586
1587 std::getline(file, line);
1588 std::istringstream header_line_stream(line);
1589 header_line_stream.imbue(std::locale::classic());
1590
1591 point2D_t num_features;
1592 size_t dim;
1593 THROW_CHECK(header_line_stream >> num_features >> dim);
1594
1595 THROW_CHECK_EQ(dim, kSiftDescriptorDim)
1596 << "SIFT features must have kSiftDescriptorDim dimensions";
1597
1598 keypoints->resize(num_features);
1599 descriptors->data.resize(num_features, dim);
1600 descriptors->type = FeatureExtractorType::SIFT;
1601
1602 for (size_t i = 0; i < num_features; ++i) {
1603 std::getline(file, line);
1604 std::istringstream feature_line_stream(line);
1605 feature_line_stream.imbue(std::locale::classic());
1606
1607 float x, y, scale, orientation;
1608 THROW_CHECK(feature_line_stream >> x >> y >> scale >> orientation);
1609
1610 (*keypoints)[i] = FeatureKeypoint(x, y, scale, orientation);
1611
1612 // Descriptor
1613 for (size_t j = 0; j < dim; ++j) {
1614 float value;
1615 THROW_CHECK(feature_line_stream >> value);
1616 THROW_CHECK_GE(value, 0);
1617 THROW_CHECK_LE(value, 255);
1618 descriptors->data(i, j) = TruncateCast<float, uint8_t>(value);
1619 }
1620 }
1621}
1622
1623} // namespace colmap

Callers 1

RunMethod · 0.85

Calls 1

FeatureKeypointClass · 0.85

Tested by

no test coverage detected