mapillary / OpenSfM

Open source Structure-from-Motion pipeline
https://www.opensfm.org/
BSD 2-Clause "Simplified" License
3.28k stars 844 forks source link

Error running `opensfm create_rig` #1012

Open ymei opened 11 months ago

ymei commented 11 months ago

I have 4 cameras in a rig with camera names Left-left, Left-right, Right-left, and Right-right. The image files are named Left-left-001.png ... The camera: field exif_overrides.json is set correctly to each corresponding camera name. Normal reconstruction without considering rig runs correctly.

However, when I run opensfm create_rig data camera '{"RIG_CAMERA_ID1": "Left-left", "RIG_CAMERA_ID2": "Left-right", "RIG_CAMERA_ID3": "Right-left", "RIG_CAMERA_ID4": "Right-right"}', it shows the following info and error:

2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -79.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -33.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -228.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -58.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -204.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 4 shots for instance -96.png using pattern matching.
2023-08-11 10:47:24,678 INFO: Found 0 single shots using pattern matching.
2023-08-11 10:47:25,390 INFO: Found 2 connected components
2023-08-11 10:47:25,394 INFO: Best component has 247 instances
Traceback (most recent call last):
  File "/home/meson/Applications/src/OpenSfM/bin/opensfm_main.py", line 25, in <module>
    commands.command_runner(
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/command_runner.py", line 38, in command_runner
    command.run(data, args)
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/command.py", line 13, in run
    self.run_impl(data, args)
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/create_rig.py", line 15, in run_impl
    create_rig.run_dataset(dataset, args.method, json.loads(args.definition), True)
  File "/home/meson/Applications/src/OpenSfM/opensfm/actions/create_rig.py", line 26, in run_dataset
    rig.create_rigs_with_pattern(data, definition)
  File "/home/meson/Applications/src/OpenSfM/opensfm/rig.py", line 317, in create_rigs_with_pattern
    for subset_data, instances in propose_subset_dataset_from_instances(
  File "/home/meson/Applications/src/OpenSfM/opensfm/rig.py", line 205, in propose_subset_dataset_from_instances
    yield data.subset(name, subset_images), total_instances
  File "/home/meson/Applications/src/OpenSfM/opensfm/dataset.py", line 655, in subset
    subset_dataset = DataSet(subset_dataset_path, self.io_handler)
  File "/home/meson/Applications/src/OpenSfM/opensfm/dataset.py", line 52, in __init__
    self.load_image_list()
  File "/home/meson/Applications/src/OpenSfM/opensfm/dataset.py", line 82, in load_image_list
    raise IOError("No Images found in {}".format(image_list_path))
OSError: No Images found in data/rig_calibration/images

I could copy all images to data/rig_calibration/images first, make rig.py not to delete them then run again. But then it appears to be reconstructing all the images rather than a select subset of them.

And in the end, it fails.

2023-08-11 11:27:38,394 INFO: Some images can not be added
2023-08-11 11:27:38,394 INFO: -------------------------------------------------------
2023-08-11 11:27:38,396 INFO: Shots and/or GCPs are well-conditioned. Using naive 3D-3D alignment.
2023-08-11 11:27:38,801 INFO: Ran GLOBAL bundle in 0.36 secs.with 20/3791/14875 (3.92) shots/points/proj. (avg. length)
2023-08-11 11:27:38,802 DEBUG: Ceres Solver Report: Iterations: 6, Initial cost: 6.977387e+02, Final cost: 6.945257e+02, Termination: CONVERGENCE
2023-08-11 11:27:38,839 INFO: Removed outliers: 0
2023-08-11 11:27:38,885 INFO: Reconstruction 0: 28 images, 11431 points
2023-08-11 11:27:38,885 INFO: Reconstruction 1: 20 images, 3791 points
2023-08-11 11:27:38,885 INFO: Reconstruction 2: 9 images, 3483 points
2023-08-11 11:27:38,885 INFO: Reconstruction 3: 8 images, 4630 points
2023-08-11 11:27:38,885 INFO: Reconstruction 4: 8 images, 1237 points
2023-08-11 11:27:38,885 INFO: Reconstruction 5: 8 images, 960 points
2023-08-11 11:27:38,885 INFO: Reconstruction 6: 6 images, 2492 points
module>
    commands.command_runner(
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/command_runner.py", line 38, in command_runner
    command.run(data, args)
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/command.py", line 13, in run
    self.run_impl(data, args)
  File "/home/meson/Applications/src/OpenSfM/opensfm/commands/create_rig.py", line 15, in run_impl
    create_rig.run_dataset(dataset, args.method, json.loads(args.definition), True)
  File "/home/meson/Applications/src/OpenSfM/opensfm/actions/create_rig.py", line 26, in run_dataset
    rig.create_rigs_with_pattern(data, definition)
  File "/home/meson/Applications/src/OpenSfM/opensfm/rig.py", line 357, in create_rigs_with_pattern
    reconstructed_instances = count_reconstructed_instances(
  File "/home/meson/Applications/src/OpenSfM/opensfm/rig.py", line 398, in count_reconstructed_instances
    instances_count[instances_map[s]] -= 1
KeyError: 'Left-right-106.png'

Is this a bug or perhaps I am not using this feature correctly?

adamjson64 commented 10 months ago

I'm having the same issue. Did you manage to sort this out?

ymei commented 10 months ago

I'm having the same issue. Did you manage to sort this out?

No, the problem persists.

adamjson64 commented 10 months ago

I've been hacking at this for quite a while. I believe this commit introduced a regression:

https://github.com/mapillary/OpenSfM/commit/bf48ad277f29670c3442b533847eb32596b0a422

Commenting that out fixes the problem (but the process still fails for me). I get as far as the ad-hoc sfm logic and it immediately fails saying that the images dont exist (but they do as simlinks, which is expected based on the code ive looked at)

adamjson64 commented 10 months ago

Aha! I got further along. The trick was to pass the absolute path to the input dataset when running opensfm (it was trying to use a relative path to find the images from the bin directory). Latest error is:

2023-08-22 02:42:03,842 INFO: Reading data for image IMG_0060_4.tif (queue-size=0) [ WARN:0@6.256] global grfmt_tiff.cpp:719 readData OpenCV TIFF: TIFFRGBAImageOK: Sorry, can not handle images with 12-bit samples Traceback (most recent call last): File "/home/ubuntu/OpenSfM/bin/opensfm_main.py", line 25, in commands.command_runner( File "/home/ubuntu/OpenSfM/opensfm/commands/command_runner.py", line 38, in command_runner command.run(data, args) File "/home/ubuntu/OpenSfM/opensfm/commands/command.py", line 13, in run self.run_impl(data, args) File "/home/ubuntu/OpenSfM/opensfm/commands/create_rig.py", line 15, in run_impl create_rig.run_dataset(dataset, args.method, json.loads(args.definition), True) File "/home/ubuntu/OpenSfM/opensfm/actions/create_rig.py", line 26, in run_dataset rig.create_rigs_with_pattern(data, definition) File "/home/ubuntu/OpenSfM/opensfm/rig.py", line 335, in create_rigs_with_pattern actions.detect_features.run_dataset(subset_data) File "/home/ubuntu/OpenSfM/opensfm/actions/detect_features.py", line 15, in run_dataset features_processing.run_features_processing(data, data.images(), False) File "/home/ubuntu/OpenSfM/opensfm/features_processing.py", line 55, in run_features_processing read_images(process_queue, data, [image], counter, 1, force) File "/home/ubuntu/OpenSfM/opensfm/features_processing.py", line 163, in read_images image_array = data.load_image(image) File "/home/ubuntu/OpenSfM/opensfm/dataset.py", line 108, in load_image return self.io_handler.imread( File "/home/ubuntu/OpenSfM/opensfm/io.py", line 1411, in imread return imread_from_fileobject(fb, grayscale, unchanged, anydepth) File "/home/ubuntu/OpenSfM/opensfm/io.py", line 1235, in imread_from_fileobject raise IOError("Unable to load image") OSError: Unable to load image

fabianschenk commented 10 months ago

Hi @adamjson64, The error seems pretty clear, your 12-bit TIFF images are not supported.

adamjson64 commented 10 months ago

Yes, it was late and I had been at this for hours so my muscle memory reaction was to share the latest error on Github. Apologies.

The aforementioned regression does seem pertinent based on my debugging efforts so far.

I just need to convert my input images into a bitness that OpenCV will process.

hackgyh commented 2 months ago

Inserting this code in line 655 of dataset. py can solve this problem,maybe

        folders = ["images", "segmentations", "masks"]
        for folder in folders:
            self.io_handler.mkdir_p(os.path.join(subset_dataset_path, folder))

        for img_name in images_subset:
            import shutil
            shutil.copyfile(
                os.path.join(self.data_path, "images", img_name),
                os.path.join(subset_dataset_path, "images", img_name)
                )

        subset_dataset = DataSet(subset_dataset_path, self.io_handler)