Suppose to be my image align like (see the attachment), but why when I'm using Agisoft API, images are not align like that? what wrong with my code? or Is it I miss something at before aligned photo task.
mport os, math, glob
import PhotoScan
import random
import csv
### processing parameters
accuracy = PhotoScan.Accuracy.HighAccuracy #align photos accuracy
reference_preselection = False
generic_preselection = True
keypoints = 40000 #align photos key point limit
tiepoints = 4000 #align photos tie point limit
source = PhotoScan.DataSource.DenseCloudData #build mesh/DEM source
surface = PhotoScan.SurfaceType.Arbitrary #build mesh surface type
quality = PhotoScan.Quality.MediumQuality #build dense cloud quality
filtering = PhotoScan.FilterMode.AggressiveFiltering #depth filtering
interpolation = PhotoScan.Interpolation.EnabledInterpolation #build mesh interpolation
blending = PhotoScan.BlendingMode.MosaicBlending #blending mode
face_num = PhotoScan.FaceCount.HighFaceCount #build mesh polygon count
mapping = PhotoScan.MappingMode.GenericMapping #build texture mapping
atlas_size = 4096
###end of processing parameters definition
####define coordinate system
##chunk.crs=PhotoScan.CoordinateSystem("EPSG::4326")
####define DSM resolution in meter
##DSMresolution=[1.00,0]
######define Orthomosaic resolution in meter
##Orthoresolution=[1.00,0]
###Directory input and output
dir_projects = 'E:\MOSAIC ALGO\Drone Image Stitching\datasets\datasets\RAW' #Directory folders with pictures
dir_PS_outputs = 'E:\MOSAIC ALGO\cuba'#Directory saved PS outputs
path = 'E:\MOSAIC ALGO\Drone Image Stitching\datasets\datasets\geotiff\RGB'
### end of Directory
##read image
print("Processing " + dir_projects)
list_files = os.listdir(dir_projects)
len(list_files)
print(len(list_files))
for entry in list_files: #finding image files
file = dir_projects + "\\" + entry
print ('file:', file)
print('Loading images')
image_list = [
os.path.join(file, path)
for path in os.listdir(file)
if path.lower().endswith(("jpg", "jpeg", "tif", "png","JPG","JPEG","TIF",""))
]
print('image list:', image_list)
###create new chunk
print('Photoscan document')
doc = PhotoScan.Document()
doc.save(dir_PS_outputs + "\\" + dir_PS_outputs.rsplit("\\", 1)[1] + ".psx")
chunk=doc.addChunk()
##
#########align photos
print ('new chunk')
chunk.addPhotos(image_list)
for frame in chunk.frames:
chunk.matchPhotos(accuracy = accuracy, generic_preselection = generic_preselection, reference_preselection = reference_preselection,filter_mask = False,
keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()
realign_list = list()
print('realign_list:', realign_list)
for camera in chunk.cameras:
## if camera.label in image_list and camera.transform:
if not camera.transform:
realign_list.append(camera)
## if len(realign_list)>0:
##a=len(realign_list)
##if a>0:
## chunk.alignCameras(realign_list,1000)
chunk.alignCameras(cameras=realign_list)
##Set camera
chunk.optimizeCameras()
chunk.resetRegion()
doc.save()
####
##
#####building dense cloud
print('dense cloud')
chunk.buildDepthMaps(quality = quality, filter = filtering)
chunk.buildDenseCloud(point_colors = True)
chunk.exportPoints(path + "ortho" + ".las", binary=True, precision=6, colors=True, format=PhotoScan.PointsFormatLAS)
doc.save()
####
##
#######building mesh
chunk.buildModel(surface = surface, source = source, interpolation = interpolation, face_count = face_num)
doc.save()
##
###Build DEM
chunk.buildDem(source=PhotoScan.DenseCloudData, interpolation=PhotoScan.EnabledInterpolation)
doc.save()
##
#######build texture
chunk.buildUV(mapping = mapping, count = 1)
chunk.buildTexture(blending = blending, size = atlas_size)
doc.save()
##
###Build Ortho
chunk.buildOrthomosaic(surface=PhotoScan.ModelData, blending=PhotoScan.MosaicBlending)
doc.save()##
##
####orthorectify photos
for camera in chunk.cameras:
camera.enabled=False
for camera in chunk.cameras:
if camera.label in image_list:
camera.enabled=True
chunk.exportOrthophotos(path+"ortho.tif", projection=chunk.crs)
doc.save()
print("Photo Aligned: ", realign_list)
#######export model
chunk.exportModel(path = path + "/" + chunk.label + ".obj", binary=False, texture_format=PhotoScan.ImageFormatTIFF, texture=True,
normals=False, colors=False, cameras=False, format = PhotoScan.ModelFormatOBJ)
chunk.exportDem(path + "_DEM.tif", image_format=PhotoScan.ImageFormatTIFF, format = PhotoScan.RasterFormatTiles, nodata=-32767, write_kml=False, write_world=True)
chunk.exportOrthomosaic(path + "ortho" + ".tif", image_format=PhotoScan.ImageFormatTIFF, format = PhotoScan.RasterFormatTiles,
raster_transform=PhotoScan.RasterTransformNone, write_kml=False, write_world=True)