3DOM-FBK / deep-image-matching

Multiview matching with deep-learning and hand-crafted local features for COLMAP and other SfM software. Supports high-resolution formats and images with rotations. Both CLI and GUI are supported.
https://3dom-fbk.github.io/deep-image-matching/
BSD 3-Clause "New" or "Revised" License
338 stars 40 forks source link

How to define initial camera params #55

Open rlamarche opened 6 months ago

rlamarche commented 6 months ago

Hi,

First thank you for this awesome project !

I wonder if it is possible to set initial camera params in the cameras.yaml file ? For example, if I define an OPENCV camera model, can I set initial fx, fy, cx,cy, k1, k2, p1 and p2 params ?

If they are guessed, how are they guessed ?

Do I need to manually update them in the database.db colmap file ? Because the column type is a blob and it might not be easy to do it on command line.

Thank you.

lcmrl commented 6 months ago

Hi, I am working to add this option directly in cameras.yaml, for now you can open database.db with COLMAP GUI and modify there the camera params or, not elegant but simple, silmply go to the function create_camera() in src/deep_image_matching/io/h5_to_db.py:

def create_camera(db: Path, image_path: Path, camera_model: str):
    image = Image.open(image_path)
    width, height = image.size

    focal = get_focal(image_path)

    if camera_model == "simple-pinhole":
        model = 0  # simple pinhole
        param_arr = np.array([focal, width / 2, height / 2])
    elif camera_model == "pinhole":
        model = 1  # pinhole
        param_arr = np.array([focal, focal, width / 2, height / 2])
    elif camera_model == "simple-radial":
        model = 2  # simple radial
        param_arr = np.array([focal, width / 2, height / 2, 0.1])
    elif camera_model == "opencv":
        model = 4  # opencv
        param_arr = np.array([focal, focal, width / 2, height / 2, 0.0, 0.0, 0.0, 0.0])
    else:
        raise RuntimeError(f"Invalid camera model {camera_model}")

    return db.add_camera(model, width, height, param_arr)

The 4 last params in OPENCV camera model are k1, k2, p1 and p2. You can substitute zeros with your values. Thanks for the feedback, I will let you know when the new features will be added. Feel free to open an issue if you find any problem or to collaborate!

rlamarche commented 6 months ago

Thank you for your feedback ! I did not find how to change using colmap gui, but I'm glad it's possible.

Also, thank you for pointing out how to change it in the code.

Keep going, your work is awesome. I'm trying the feature detection & matching on very low quality underwater datasets and I'm convinced that it can make a huge difference.

Regards,

Romain.

oUp2Uo commented 6 months ago

Thank you for your feedback ! I did not find how to change using colmap gui, but I'm glad it's possible.

Also, thank you for pointing out how to change it in the code.

Keep going, your work is awesome. I'm trying the feature detection & matching on very low quality underwater datasets and I'm convinced that it can make a huge difference.

Regards,

Romain.

In COLMAP UI, (Processing - Database Management), you could change the camera model or initial parameters.