Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colmap Instructions and Scripts #807

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

bcoltin
Copy link
Member

@bcoltin bcoltin commented Jul 31, 2024

Readme with instructions and shortcomings, scripts for trying to do fancier things that I wasn't able to get fully working in time.

@bcoltin bcoltin requested a review from rsoussan July 31, 2024 20:54
Copy link
Contributor

@trey0 trey0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Brian- I'm not familiar enough with colmap to truly understand what's going on here so won't presume to approve, but I had a bunch of minor comments about Python style. This looks like it was a lot of work!

rows = self.execute("SELECT * FROM cameras")
for r in rows:
cameras.append(r)
return cameras
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I missed something, the one-liner return list(self.execute("SELECT * FROM camera")) would do the same thing.

Some of these other methods look like they could be simplified in a similar way.

paths = []
for img in images:
if type(img) is dict:
for (d, i) in images.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i in images.values():

for p in parts[:-2]:
if p not in d:
d[p] = dict()
d = d[p]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for loop body could be written as a one-liner: d = d.setdefault(p, {})

# builds nested dictionary of image folder structure
def list_images(self):
image_list = self.db.images()
images = dict()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent but more idiomatic to write {} instead of dict() and [] instead of list(). Comes up in several places.

def images_to_paths(self, images):
paths = []
for img in images:
if type(img) is dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isinstance(img, dict):

It's considered bad form to check the type of x by comparing type(x) to something. You generally should use isinstance(x, ...), which is aware of inheritance, etc.

matches += self.db.num_matches(img1.id, img2.id)
image_choices.append((img2.name, matches))
best_matches = heapq.nlargest(10, image_choices, lambda x: x[1])
images = list(map(lambda x: x.name, model1.images.values()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

images = [x.name for x in model1.images.values()]

image_choices.append((img2.name, matches))
best_matches = heapq.nlargest(10, image_choices, lambda x: x[1])
images = list(map(lambda x: x.name, model1.images.values()))
images.extend(list(map(lambda x: x[0], best_matches)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

images += [x[0] for x in best_matches]

def get_best_overlap_images(self, cur_images, subdirs):
best = None
best_matches = 0
for i in range(len(subdirs)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i, subdir in enumerate(subdirs):

Then you can use subdir in place of subdirs[i] below.

print(
"Building initial map %s from %s with %d images..."
% (str(map_num), data_source, len(images))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print(f"Building initial map {map_num} from {data_source} with {len(images)} images...")

Since we can now rely on being in Python 3... I find f-strings more readable than the old-style string interpolation. This could apply in lots of places.

If sticking with string interpolation:

  • I find it's rare that I need to use any formatter other than %s, which works by implicitly calling str() on its argument. (This makes sense for just about any object type. No need to remember to use %d for int or whatever.)
  • When using %s, it's redundant to explicitly call str() on your argument.

)

def create_leaf_models(self, images, subdir="leaf"):
if type(images) is dict:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if isinstance(images, dict):

@trey0
Copy link
Contributor

trey0 commented Aug 1, 2024

Ah, one more general comment is that pylint is really helpful. I find some of its warnings silly and don't bother to fix everything it reports, but it's usually worth running anyway. I'm pretty sure it would have caught several of the things I commented on.

Copy link

@kiruthikpurpose kiruthikpurpose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not gonna create a big difference. But the order of the packages becomes less confused for humans to check out what they could be missing when cross-compared.

Copy link

@kiruthikpurpose kiruthikpurpose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the file name from readme.md to README.md

Look for neat organized structure for the documentation in README.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants