Forum

Author Topic: Aligning turntable photos with fix camera and turn table  (Read 1834 times)

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Aligning turntable photos with fix camera and turn table
« on: September 28, 2020, 09:40:49 PM »
Hi,
I am having a problem on mosaic and generating models when the cameras position is fix and object is paced on turn table. With the metashape gui i am able to see result.  But I follow exact same process  with python script. I am getting wired result. All cameras are not aligned.  Not sure what am I missing in script. Any help Below is my script

Code: [Select]

import Metashape
import os
import glob

Metashape.app.console.clear()

# construct the document class
doc = Metashape.app.document
# doc = Metashape.Document()
output_file_path = './mosaic_result'
project_name = 'object.psx'
output_name = 'object.laz'

file_path = './image/'

psxfile = os.path.join(output_file_path, project_name)
doc.save(psxfile)
chunk = doc.addChunk()
doc.save()

image_path = glob.glob(file_path + '*.jpg')
dir_name = file_path + '/mask'

point_cloud_quality = Metashape.HighQuality

chunk.addPhotos(image_path)
chunk.importMasks(path=dir_name + '/' + '{filename}_mask.png', source=Metashape.MaskSourceFile,
                  operation=Metashape.MaskOperationReplacement)

calib_file = 'lens_calibration.xml'
calibration = Metashape.Calibration()
calibration.load(calib_file, format='xml')
for sensor in chunk.sensors:
    sensor.user_calib = calibration
    sensor.fixed = True


chunk.matchPhotos(accuracy=Metashape.HighAccuracy, preselection=Metashape.GenericPreselection,
                  generic_preselection=True, reference_preselection=False, mask_tiepoints=True,
                  keypoint_limit=40000, tiepoint_limit=4000)

chunk.alignCameras(adaptive_fitting=True)

aligned = list()
not_aligned = list()
for camera in chunk.cameras:
    if camera.transform:
        aligned.append(camera)
    elif camera.enabled:
        not_aligned.append(camera)
        camera.transform = None
if len(not_aligned)>0:
    chunk.alignCameras(cameras = not_aligned, adaptive_fitting=True)

chunk.buildDepthMaps(quality=point_cloud_quality, filter=Metashape.AggressiveFiltering, reuse_depth=True)
chunk.buildDenseCloud(point_colors=True)

pointcloud_filename = os.path.join(output_file_path, output_name)
chunk.exportPoints(pointcloud_filename, colors=True, colors_rgb_8bit=True)

doc.save()

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Aligning turntable photos with fix camera and turn table
« Reply #1 on: September 28, 2020, 10:33:49 PM »
Hello ppant,

Have you checked, whether all preliminary steps are completed properly before image matching and camera alignment is started? Are the masks and calibration information applied properly?

Also please check, if adding filter_mask = True argument to matchPhotos process improves the result.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Aligning turntable photos with fix camera and turn table
« Reply #2 on: September 28, 2020, 10:36:12 PM »
Not sure where is the problem. I have further addition to problem.  Based on  mask my results are  random.

Thanks

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Aligning turntable photos with fix camera and turn table
« Reply #3 on: September 28, 2020, 11:19:40 PM »
Alexey
I  check the camera calibration and my lens calibration information (pre calibrated information) are loaded before matchphotos.  On thing in my mask is rectangular shape (generated for all image). I notice that altering the square mask  my result are different. On more when I make my mask just covering the object,  tie point are to few and it failed. because of that I create the rectangular mask. Do  have relation such that object should cover x% in an image to get good result.

Thanks

ppant

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: Aligning turntable photos with fix camera and turn table
« Reply #4 on: September 29, 2020, 04:50:48 PM »
Alexey,
In the script, you can see all steps are applied.

load image read mask . load camera information. (After these steps I see all the camera precalibrated parameters are loaded and mask image ). I also add filter_mask = True . Mosaic is working but

I further notice that in metashape, the masking effect (choice of image mask how we prepared) how images are aligned. In some cases of mask, images are not aligned. In some cases partial alignment and in some cases full alignment.  I am not sure what is going on.  In the mask image, I set all object value to be 254 and background 0. 


Thanks
« Last Edit: September 29, 2020, 05:41:07 PM by ppant »