Forum

Author Topic: Alignment result from the python module aligns only a few of my entire image set  (Read 12624 times)

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
I am running the alignCameras() step on my imageset of 933 images using the python version of the software. For some reason, it is aligning only 127 out of the 933 images and the rest are not aligned (NA). The computer that I am using is a remote machine and does not have a user Interface.

I also ran the same set of images on a different computer with the user interface version of the software. Here all 933 images were aligned without any problem. I am wondering if I am making any mistake in the python code. The code is as follows.

import os
import Metashape
import numpy as np
# Use GPU
Metashape.app.gpu_mask=1
Metashape.app.cpu_enable=False
# End use GPU

#Load Images
pa='/home/nys09/'
pat='/home/nys09/Trial1Beamch_arc/'
b=[]
c=os.path.join(pa,"arc_imagelist_t1.txt")
images = open(c,"r+")
a = np.loadtxt(images,dtype=str)
for i in range(np.shape(a)[0]):
    b.append(pat+str(a))

#Alignment
Metashape.app.settings.log_enable=True
Metashape.app.settings.log_path='/home/nys09/Trial1Beamch_arc/trial2logfile.txt'

doc = Metashape.Document()
doc.save(pat+"trial_alignment2.psz")
chunk = doc.addChunk()
chunk.addPhotos(b)
chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=True,reference_preselection=False,keypoint_limit=40000, tiepoint_limit=4000)
chunk.alignCameras()
doc.save()


Also the log file is not being generated. I want all processing to be written to txt file as I am using the software without user interface.

Please help me with this issue.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello nys09,

Can you please share the processing logs from the both runs?

Also which type of the data you are processing? I mean a kind of scene.
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Hi Alexey.

I have shared both the .psz files, one from UI and the other from python interface of the software, via email as a reply to my support request. I have also sent the pdf reports that I generated from both models. I am unable to attach those here because of size limit.

I was unable to generate a log file even after including the following. Is there anything else that I am missing to write the log file to the hard drive?
Metashape.app.settings.log_enable=True
Metashape.app.settings.log_path='/home/nys09/Trial1Beamch_arc/trial2logfile.txt

The type of data I am using this for are the pictures of my concrete beams in our lab. the ticket that I raised on support is https://agisoft.freshdesk.com/helpdesk/tickets/127078

Thanks,
Yeshwanth
nys09@vt.edu

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

Thank you for sending the project file.

I've tried to reset the camera alignment in the project, remove the adjusted values for distortion parameters and re-start alignCameras(), but each time the result is complete and all the cameras are aligned.

Just for case, I can suggest to use Tasks approach to reduce the memory consumption for the main workflow operations, for example, for the camera alignment:

Code: [Select]
task = Metashape.Tasks.AlignCameras()
task.adaptive_fitting = False
task.network_distribute = True
task.apply(chunk)
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Hi Alexey, 

Thank you so much for your response. This was only a trial run for using the high performance computer that our university has. I have much bigger beams to work on. 

Any guidance on how to write the code to do a realignment of unaligned pictures if less than  90% of images are aligned, would be great.

Also, please let me know what all lines to include for getting a log file. I'm using the following lines in my code. The log file is not being generated.

Metashape.app.settings.log_enable=True
Metashape.app.settings.log_path='/home/nys09/Trial1Beamch_arc/trial2logfile.txt'


Thanks,
Yeshwanth

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

The following code is checking the number of aligned cameras and re-aligns the NA (not aligned) cameras then:
Code: [Select]
aligned = list()
not_aligned = list()
for camera in chunk.cameras:
    if camera.transform:
        aligned.append(camera)
    elif camera.enabled:
        not_aligned.append(camera)
if len(not_aligned) > len(aligned) * 0.1:
    chunk.alignCameras(cameras = not_aligned, reset_alignment=False)

As for the log, if you are running the script from the command-line, then you can just re-direct output from terminal to the file, for example:
Code: [Select]
metashape.exe -r script.py > D:/log.txt
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Hi Alexey,

Thank you very much. In the above code, Don't I have to write match photos step, before we realign the unaligned cameras as follows?
chunk.matchPhotos(accuracy=Metashape.HighAccuracy, generic_preselection=True,reference_preselection=False,keypoint_limit=40000, tiepoint_limit=4000)

Thank you

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

You need to run the image matching only once - prior to the initial (first) alignment. Later re-alignment operations would be re-using tie points that are already present in the project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Hi Alexey,

I tried your above code for realigning the unaligned cameras and I am getting the following error.

File "arc_inputfile.py", line 59, in <module>
    chunk.alignCameras(cameras = not_aligned, reset_alignment=False)
TypeError: 'reset_alignment' is an invalid keyword argument for this function


I checked the documentation. There is no argument called reset_alignment=false for alignCameras(). it is only there for the alignment using the tasks approach. But it requires a chunk object as a parameter. So my trial of passing not_aligned to task did not work. Kindly suggest.
 
Code I used:
if len(not_aligned) > len(aligned) * 0.1:
    task2 = Metashape.Tasks.AlignCameras()
    task2.adaptive_fitting = False
    task2.network_distribute = True
    task2.reset_alignment = False
    task2.apply(not_aligned)

Thanks
Yeshwanth

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

Yes, in the version 1.5.5 reset_alignment is only available for Tasks approach. However, the argument would be available in the version 1.6.0 API.

I recommend to use Tasks if you are processing large projects with big number of images, since network_distribute option would allow to reduce the memory consumption.
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Hi Alexey,

Thank you very much for your continued support. I was able to run the alignment for all the images. But, now I am facing difficulty in the dense cloud generation part now. The result from the python version of the software has a lot of background noise / outliers which was not there when I used the GUI version of the software. I am attaching a picture of the model. In the picture, we can see the noise on the right side. Any insight into how to avoid this, would be helpful.

I am using the following code for the dense cloud step.

chunk.buildDepthMaps(quality=Metashape.HighQuality, filter=Metashape.AggressiveFiltering)
task = Metashape.Tasks.BuildDenseCloud()
task.network_distribute = True
task.apply(chunk)

The log file is available at https://drive.google.com/file/d/16ph7mGyIdhybMX3VLFsWSWU5V7Zcs45g/view?usp=sharing

Thank you
Yeshwanth

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

Can you also post a screenshot of the GUI-related reconstruction?
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
Please find attached the screenshot of the dense cloud from the GUI version. You can see that the GUI version dense cloud is much better than the python version. I wonder why the results would be different.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15171
    • View Profile
Hello Yeshwanth,

Can you please confirm that the second screenshot is of the dense cloud and not of the polygonal mesh model in shaded view mode?
Best regards,
Alexey Pasumansky,
Agisoft LLC

nys09@vt.edu

  • Newbie
  • *
  • Posts: 16
    • View Profile
I am sorry, I guess it was shaded mesh. I am now attaching the dense cloud image. I double checked and this one is from the dense cloud.