OpenSfM icon indicating copy to clipboard operation
OpenSfM copied to clipboard

Set code inputs without using the command line

Open Alirezasoltani19951374 opened this issue 2 years ago • 5 comments

I want to debug the code line by line to understand more. I did the data address by changing the functionparser.add_argument("--dataset",default="data/lund/",help="dataset to process"). But I do not know where to set inputs like Extract _Metadata or Extract Features. Please help me

Alirezasoltani19951374 avatar Jan 10 '22 15:01 Alirezasoltani19951374

Hi @Alirezasoltani19951374 ,

You could just start a debugger with the same parameters you would use in a terminal. No need to change anything in the code. Just in case you want to follow a different route: extract_metadata,create_tracks,... are opensfm commands. The structure is a bit tricky to figure out. Every command is a class with a name attribute that is then matched to the positional command argument here: https://github.com/mapillary/OpenSfM/blob/c250de55ee3053fc7d8b433860664206ba8b2841/opensfm/commands/command_runner.py#L33-L37 The commands themselves are imported from __init__.py.

Good luck

fabianschenk avatar Jan 10 '22 15:01 fabianschenk

Hi @fabianschenk, thanks for responding, I did not understand what you said. a a2 I get this error when I go line by line of code. While I have specified the location of the data by functionparser.add_argument("--dataset",default="data/lund/",help="dataset to process")

Alirezasoltani19951374 avatar Jan 10 '22 16:01 Alirezasoltani19951374

Hi @Alirezasoltani19951374 ,

Even though I absolutely do not understand why you would set the parameters instead of passing them to the debugger, you could just set them above the with dataset_factory(....) something like this (untested code!):

args.dataset = "data/berlin"    # Here you might need the full path /home/OpenSfM/.../data/berlin
args.dataset_type = None # You might need a different value here.
args.command = "extract_metadata"
with dataset_factory(args.dataset, args.dataset_type) as data:
.....

If you have other problems with debugging in VS Code, please consult the VS Code documentation!

Best, Fabian

fabianschenk avatar Jan 11 '22 08:01 fabianschenk

Hi@fabianschenk , I apologize for taking your time. When running a program through a command line, for example python3 bin / opensfm_main.py extract_metadata data / lund / Runs well. But when I passing the parameters through Visual Studio code, I get the following error Traceback (most recent call last): File "/home/alireza/Test01/OpenSfM/bin/opensfm_main.py", line 28, in commands.opensfm_commands, create_default_dataset_context, dataset_choices=["opensfm"] File "/home/alireza/Test01/OpenSfM/opensfm/commands/command_runner.py", line 34, in command_runner command.run(data, args) File "/home/alireza/Test01/OpenSfM/opensfm/commands/command.py", line 13, in run self.run_impl(data, args) File "/home/alireza/Test01/OpenSfM/opensfm/commands/extract_metadata.py", line 12, in run_impl extract_metadata.run_dataset(dataset) File "/home/alireza/Test01/OpenSfM/opensfm/actions/extract_metadata.py", line 48, in run_dataset data.save_camera_models(camera_models) File "/home/alireza/Test01/OpenSfM/opensfm/dataset.py", line 459, in save_camera_models with self.io_handler.open_wt(self._camera_models_file()) as fout: File "/home/alireza/Test01/OpenSfM/opensfm/io.py", line 1368, in open_wt return cls.open(path, "w", encoding="utf-8") File "/home/alireza/Test01/OpenSfM/opensfm/io.py", line 1364, in open return open(*args, **kwargs) FileNotFoundError: [Errno 2] No such file or directory: 'data/berlin/camera_models.json' Learning this program is one of my desires. I hope you are not upset if my questions are basic. thanks alot

Alirezasoltani19951374 avatar Jan 12 '22 11:01 Alirezasoltani19951374

Hi @Alirezasoltani19951374 ,

This is likely because the debugger starts in a folder (probably your home directory), where data/berlin/ does not exist.

Use the full path /home/OpenSfM/data/berlin like I already wrote as comment above!

args.dataset = "data/berlin"    # Here you might need the full path /home/OpenSfM/data/berlin

I've debugged OpenSfM quite often myself and it works. Please, make sure to double check file paths, read the VS Code doc and use Google search.

fabianschenk avatar Jan 12 '22 14:01 fabianschenk