Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/colmap/controllers/automatic_reconstruction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ AutomaticReconstructionController::AutomaticReconstructionController(

ImageReaderOptions& reader_options = *option_manager_.image_reader;
reader_options.image_path = *option_manager_.image_path;
reader_options.as_rgb = option_manager_.feature_extraction->RequiresRGB();
if (!options_.mask_path.empty()) {
reader_options.mask_path = options_.mask_path;
option_manager_.image_reader->mask_path = options_.mask_path;
Expand Down
2 changes: 1 addition & 1 deletion src/colmap/controllers/image_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ImageReader::Status ImageReader::Next(Rig* rig,
// Read image.
//////////////////////////////////////////////////////////////////////////////

if (!bitmap->Read(image_path, false)) {
if (!bitmap->Read(image_path, /*as_rgb=*/options_.as_rgb)) {
return Status::BITMAP_ERROR;
}

Expand Down
3 changes: 3 additions & 0 deletions src/colmap/controllers/image_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ struct ImageReaderOptions {
// value `default_focal_length_factor * max(width, height)`.
double default_focal_length_factor = 1.2;

// Whether to read images as grayscale or RGB.
bool as_rgb = false;

bool Check() const;
};

Expand Down
47 changes: 33 additions & 14 deletions src/colmap/controllers/image_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,36 @@
namespace colmap {
namespace {

Bitmap CreateTestBitmap() {
Bitmap CreateTestBitmap(bool as_rgb) {
Bitmap bitmap;
bitmap.Allocate(1, 3, false);
bitmap.Allocate(1, 3, as_rgb);
bitmap.SetPixel(0, 0, BitmapColor<uint8_t>(1));
bitmap.SetPixel(1, 0, BitmapColor<uint8_t>(2));
bitmap.SetPixel(2, 0, BitmapColor<uint8_t>(3));
return bitmap;
}

class ParameterizedImageReaderTests
: public ::testing::TestWithParam<
std::tuple</*num_images=*/int,
/*with_masks=*/bool,
/*with_existing_images=*/bool>> {};
: public ::testing::TestWithParam<std::tuple</*num_images=*/int,
/*with_masks=*/bool,
/*with_existing_images=*/bool,
/*as_rgb=*/bool>> {};

TEST_P(ParameterizedImageReaderTests, Nominal) {
const auto [kNumImages, kWithMasks, kWithExistingImages] = GetParam();
const auto [kNumImages, kWithMasks, kWithExistingImages, kAsRGB] = GetParam();

auto database = Database::Open(kInMemorySqliteDatabasePath);

const std::string test_dir = CreateTestDir();
ImageReaderOptions options;
options.image_path = test_dir + "/images";
options.as_rgb = kAsRGB;
CreateDirIfNotExists(options.image_path);
if (kWithMasks) {
options.mask_path = test_dir + "/masks";
CreateDirIfNotExists(options.mask_path);
}
const Bitmap test_bitmap = CreateTestBitmap();
const Bitmap test_bitmap = CreateTestBitmap(kAsRGB);
for (int i = 0; i < kNumImages; ++i) {
const std::string image_name = std::to_string(i) + ".png";
test_bitmap.Write(options.image_path + "/" + image_name);
Expand Down Expand Up @@ -117,6 +118,7 @@ TEST_P(ParameterizedImageReaderTests, Nominal) {
EXPECT_EQ(camera.width, test_bitmap.Width());
EXPECT_EQ(camera.height, test_bitmap.Height());
EXPECT_EQ(image.Name(), std::to_string(i) + ".png");
EXPECT_EQ(bitmap.IsRGB(), kAsRGB);
EXPECT_EQ(bitmap.ConvertToRowMajorArray(),
test_bitmap.ConvertToRowMajorArray());
if (kWithExistingImages) {
Expand All @@ -135,12 +137,29 @@ TEST_P(ParameterizedImageReaderTests, Nominal) {
EXPECT_EQ(database->NumCameras(), kNumImages);
}

INSTANTIATE_TEST_SUITE_P(ImageReaderTests,
ParameterizedImageReaderTests,
::testing::Values(std::make_tuple(0, false, true),
std::make_tuple(5, false, false),
std::make_tuple(5, true, false),
std::make_tuple(5, false, true)));
INSTANTIATE_TEST_SUITE_P(
ImageReaderTests,
ParameterizedImageReaderTests,
::testing::Values(std::make_tuple(/*num_images=*/0,
/*with_masks=*/false,
/*with_existing_images=*/true,
/*as_rgb=*/true),
std::make_tuple(/*num_images=*/5,
/*with_masks=*/false,
/*with_existing_images=*/false,
/*as_rgb=*/true),
std::make_tuple(/*num_images=*/5,
/*with_masks=*/true,
/*with_existing_images=*/false,
/*as_rgb=*/true),
std::make_tuple(/*num_images=*/5,
/*with_masks=*/true,
/*with_existing_images=*/false,
/*as_rgb=*/false),
std::make_tuple(/*num_images=*/5,
/*with_masks=*/false,
/*with_existing_images=*/true,
/*as_rgb=*/true)));

} // namespace
} // namespace colmap
1 change: 1 addition & 0 deletions src/colmap/exe/feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int RunFeatureExtractor(int argc, char** argv) {

ImageReaderOptions reader_options = *options.image_reader;
reader_options.image_path = *options.image_path;
reader_options.as_rgb = options.feature_extraction->RequiresRGB();

if (camera_mode >= 0) {
UpdateImageReaderOptionsFromCameraMode(reader_options,
Expand Down
10 changes: 10 additions & 0 deletions src/colmap/feature/extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ void ThrowUnknownFeatureExtractorType(FeatureExtractorType type) {
FeatureExtractionOptions::FeatureExtractionOptions(FeatureExtractorType type)
: type(type), sift(std::make_shared<SiftExtractionOptions>()) {}

bool FeatureExtractionOptions::RequiresRGB() const {
switch (type) {
case FeatureExtractorType::SIFT:
return false;
default:
ThrowUnknownFeatureExtractorType(type);
}
return false;
}

bool FeatureExtractionOptions::Check() const {
CHECK_OPTION_GT(max_image_size, 0);
if (use_gpu) {
Expand Down
3 changes: 3 additions & 0 deletions src/colmap/feature/extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct FeatureExtractionOptions {

std::shared_ptr<SiftExtractionOptions> sift;

// Whether the selected extractor requires RGB (or grayscale) images.
bool RequiresRGB() const;

bool Check() const;
};

Expand Down
1 change: 1 addition & 0 deletions src/colmap/ui/feature_extraction_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void SIFTExtractionWidget::Run() {

ImageReaderOptions reader_options = *options_->image_reader;
reader_options.image_path = *options_->image_path;
reader_options.as_rgb = options_->feature_extraction->RequiresRGB();

auto extractor = CreateFeatureExtractorController(
*options_->database_path, reader_options, *options_->feature_extraction);
Expand Down
Loading