Forum

Author Topic: Relabeling cameras via python leads to different (worse) alignment  (Read 4752 times)

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
In my workflow, I add photos that are in multiple folders. Sometimes a photo with a specific name (e.g. IMG_1001.JPG) can appear in more than one folder, even though it's actually a different photo. Metashape's default label for the cameras is just the photo filename, which means I can end up with multiple cameras with the same label. This is not acceptable, because my GCP workflow requires referencing specific cameras by their labels. Therefore, I relabel my cameras to have unique labels (the label includes the name of the folder it was in):

    for camera in doc.chunk.cameras:
        path = camera.photo.path
        path_parts = path.split("/")[-2:]
        newlabel = "/".join(path_parts)
        camera.label = newlabel


However, I have noticed that if I relabel the cameras, I get a different alignment than if I don't relabel them. The alignment is much worse if I have relabeled the cameras first. For example, Metashape thinks some groups of cameras are pointing toward the sky or at very oblique angles, even though they are actually all pointing directly downward. The only thing I change between the two runs is whether or not the cameras get relabeled. I do the relabeling immediately after adding the photos. I have repeated this multiple times and I always get the same results.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #1 on: December 05, 2019, 12:40:51 PM »
Hello dyoung,

re-labeling of the cameras should not have any considerable effect on the alignment results.

Can you share the projects in PSZ format saved after aligning the set with default labels and after renaming the cameras?
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #2 on: December 05, 2019, 08:30:46 PM »
Hi Alexey -- sure, please find the project files here: https://ucdavis.box.com/s/fsjcon4cf34h61hbcdi21p36x0wboi1g

Each one is about 10 GB.

The only difference between the two is in whether I relabeled the cameras before alignment. I have repeated this at least three times each way and have gotten the same results. Let me know if there's anything else I can provide to help resolve this issue.

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #3 on: December 13, 2019, 04:13:37 AM »
Hi Alexey -- I'm wondering if you had a chance to look at this. Let me know if there's any more information I can send to help diagnose this bug.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #4 on: December 16, 2019, 08:08:43 PM »
Hello dyoung,

I have re-run Align Selected cameras for the re-labeled chunk several times and every time the results looked correctly (without blocks of the cameras with incorrect orientation).
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #5 on: December 18, 2019, 07:18:57 PM »
Hi Alexey,

Thank you very much for looking at this.

Did you re-run align cameras using the Metashape GUI or the python module? I only had this problem when using the standalone python module. When I re-run the alignment in the GUI, I also get proper alignment.

I would try to re-run alignment using the python module myself, but I can't find a method in the reference documentation for removing the current alignment and matching (which I would have to do first).

Thanks again!
Derek

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #6 on: December 18, 2019, 09:53:14 PM »
Hello Derek,

I've tried to reproduce the problem using Python API, after resetting the camera alignment for all the cameras used the following call (used version 1.6.0):

Code: [Select]
task = Metashape.Tasks.AlignCameras()
task.subdivide_task = True
task.apply(Metashape.app.document.chunk)
and the result was similar to the GUI run results, with no issues.
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #7 on: December 20, 2019, 06:05:29 PM »
Thanks again for running this, Alexey. Maybe the issue is resolved in 1.6.0. I am working to port my code to 1.6.0 to test it myself. I had an issue because 1.6.0 does not have "HighAccuracy", "HighQuality" etc defined, but I see these are now implemented via the "downscale" parameter. I will report here once I have it running in 1.6.0.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #8 on: December 20, 2019, 07:05:53 PM »
Hello Derek,

Meanwhile I'll try to check 1.5.5 results.

If you have some doubts regarding updated Python API, you can post them here on forum.
Latest API reference is available by the following link: https://www.agisoft.com/pdf/metashape_python_api_1_6_0.pdf
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #9 on: December 20, 2019, 07:45:02 PM »
Thank you!

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #10 on: December 21, 2019, 04:05:41 AM »
I am happy to report that using the Python API 1.6.0, the alignment worked perfectly for me. So the bug (or whatever the issue was) seems to be resolved in 1.6.0.

Interestingly, 1.6.0 took 23% longer than 1.5.5 to align cameras. However, I am happy to accept 23% longer if it means I get proper alignment.

Note that I have been running this with adaptive_fitting = True in both 1.5.5 and 1.6.0.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #11 on: December 23, 2019, 01:01:25 PM »
Hello Derek,

Glad to hear that it works properly on your side. Can you, however, specify the OS version used, so that we could try to reproduce the difference in the processing time?
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #12 on: December 23, 2019, 08:51:25 PM »
Alexey -- Sure, I am using the standalone Python API on Ubuntu 18.04 on a PC with a RTX 2080 Ti and an Intel i9-9900. Python version 3.5.6.

Here are the methods and arguments I am using:

1.5.5:
doc.chunk.matchPhotos(accuracy=Metashape.HighAccuracy)
doc.chunk.alignCameras(adaptive_fitting=True)

1.6.0:
doc.chunk.matchPhotos(downscale=1)
doc.chunk.alignCameras(adaptive_fitting=True)

Hope this helps. I would be interested to know if you find the cause of the increased processing time.

Derek

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #13 on: December 24, 2019, 01:43:50 PM »
Hello Derek,

That's quite strange, since the alignment time on Linux should be improved in the version 1.6.

The possible reason of this difference might be the default subdivide_task parameter being enabled in the version 1.6, while in the older versions it has not been accessible for methods (only via Tasks class).
Best regards,
Alexey Pasumansky,
Agisoft LLC

dyoung

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Relabeling cameras via python leads to different (worse) alignment
« Reply #14 on: December 26, 2019, 07:36:45 PM »
Interesting. In early January I will repeat my comparison of 1.5.5 and 1.6.0 and I'll try different settings for the subdivide_task parameter.