Forum

Author Topic: Select all images for alignment using API  (Read 4527 times)

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Select all images for alignment using API
« on: March 02, 2017, 09:27:05 AM »
For the first step in my processing workflow, I'm using the following API calls -

Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.addPhotos(images)

# image matching and alignment
for frame in chunk.frames:
    frame.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection, keypoint_limit=40000, tiepoint_limit=1000) # HighestAccuracy

chunk.alignCameras()

The same procedure in the GUI yields 3000 points as shown in the attached image (agisoft_1.png). As is evident, only the images with the green ticks are used in the alignment.

However, in the GUI, I can manually select all images (by pressing Ctrl + A) and then proceed with image alignment (agisoft_2.png). This yields 4000+ points for further processing. And the output is really good for the 2nd process, and very distorted for the 1st.

I wanted to know what change I can make in my API call to select all images and thereby get the same performance.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Select all images for alignment using API
« Reply #1 on: March 02, 2017, 11:59:38 AM »
Hello varadg,

You can loop through all the cameras and check if they are aligned, then add them to list the realign:

Code: [Select]
realign_list = list()
for camera in chunk.cameras:
      if not camera.transform:
            realign_list.append(camera)
chunk.alignCameras(cameras = realign_list)

if you need to re-align just all the cameras, then you can just skip "cameras" argument or pass chunk.cameras to align everything using available matching points.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Select all images for alignment using API
« Reply #2 on: March 02, 2017, 12:52:48 PM »
Hey Alexey. Thanks for the reply. Just to clarify, I add the code you've supplied after the first alignCameras call right?

Also, if I want to re-align all cameras regardless, I just do -

Code: [Select]
chunk.alignCameras(chunk.cameras)


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Select all images for alignment using API
« Reply #3 on: March 02, 2017, 01:01:22 PM »
Hello varadg,

Yes, if you need to reset alignment for all cameras and align them again, then just use chunk.alignCameras(), while chunk.alignCameras(chunk.cameras) would work only if you reset the alignment for all cameras at first.
And if you are passing any list as "cameras" argument - it works as Align Selected Cameras option available from GUI.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Select all images for alignment using API
« Reply #4 on: March 02, 2017, 03:22:03 PM »
Hi Alexey. I tried your suggestion. This is the code I used -

Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()
chunk.addPhotos(images)

# image matching and alignment
for frame in chunk.frames:
    frame.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection, keypoint_limit=40000, tiepoint_limit=1000) # HighestAccuracy

chunk.alignCameras()

realign_list = list()
for camera in chunk.cameras:
      if not camera.transform:
            realign_list.append(camera)
chunk.alignCameras(cameras = realign_list)


I have attached the output from the GUI & the API. As you can see the output from the GUI is still quite different from what I get from the API. What am I doing wrong?

For reference, this is the full orthophoto generation pipeline I'm using -

Code: [Select]
doc = PhotoScan.app.document
doc.save(project_psx_path)

# add photos
chunk = doc.addChunk()
chunk.addPhotos(images)

# image matching and alignment
for frame in chunk.frames:
    frame.matchPhotos(accuracy=PhotoScan.HighAccuracy, preselection=PhotoScan.GenericPreselection, keypoint_limit=40000, tiepoint_limit=1000) # HighestAccuracy

chunk.alignCameras()

realign_list = list()
for camera in chunk.cameras:
      if not camera.transform:
            realign_list.append(camera)


chunk.alignCameras(cameras=realign_list)

# dense point cloud

chunk.buildDenseCloud(quality=PhotoScan.HighQuality,filter=PhotoScan.MildFiltering) # quality=PhotoScan.UltraQuality

# build mesh
chunk.buildModel(surface=PhotoScan.HeightField, interpolation=PhotoScan.EnabledInterpolation, face_count=PhotoScan.MediumFaceCount, source=PhotoScan.DenseCloudData)   # classes provide control on which kind of terrain we are mapping

# build UV
chunk.buildUV(mapping=PhotoScan.OrthophotoMapping)

# build texture
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=8192)

doc.save()

# build orthophoto
chunk.buildOrthomosaic()

# export orthophoto
orthophoto_path = "{0}/{1}_ortho.tif".format(project_files_path, project_name)
chunk.exportOrthomosaic(path=orthophoto_path, jpeg_quality=99)

# resize for easier viewing
orthophoto = cv2.imread(orthophoto_path)
orthophoto_resized = cv2.resize(orthophoto, (0, 0), fx=0.5, fy=0.5)
cv2.imwrite(orthophoto_path, orthophoto_resized)

# report_path = "{0}/{1}_report.pdf".format(project_files_path, project_name)
# chunk.exportReport(path=report_path, title="API Processing Report")

t2 = time.time()

print("Time Taken : {} seconds".format(t2-t1))

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Select all images for alignment using API
« Reply #5 on: March 02, 2017, 03:31:01 PM »
Hello varadg,

The provided result doesn't contain any information about the number or aligned cameras and the orientation of the model in the coordinate system space.

I think I've already mentioned in anther thread that you are working with the unstable dataset, so the produced results may have arbitrary orientation in space and different number of aligned cameras.
Best regards,
Alexey Pasumansky,
Agisoft LLC