尽管photoscan具备流程化处理功能(在工具栏:workflow–batch process中设置需要的步骤),但当多架次影像需分别处理时,仍需逐个建立工程,逐个进行“batch process”设置,操作依然是繁琐的。好在photoscan支持脚本处理,如果有编写好的脚本,可通过脚本导入窗口(tools–scripts)运行。查阅了各种平台,仅在CSND中找到一个脚本(需要积分下载,实际下载了并没有卵用,也可能自己不会用)。干脆自己查阅官方文档,尝试自己编写,希望可以帮到有需要的朋友。
注意:脚本是针对旧版本的photoscan的开发的,并不适用于metashape。
#!/usr/bin/env python3.7
# encoding: utf-8
"""
@author: Yxz
@contact: QQ:846924329
@file: Automation.py
@time: 2019/12/20 20:30
@desc:
1、改脚本仅适配于photoscan1.2.1;
2、仅支持单线程;
3、新的脚本可以支持metashape1.6.3且可多线程处理,有需要的朋友可以私聊博主获取
"""
import os
import PhotoScan
def auto_process():
global doc
doc = PhotoScan.app.document
app = QtGui.QApplication.instance()
parent = app.activeWindow()
# image_path
path_photos = PhotoScan.app.getExistingDirectory("Specify input photo folder:")
path_export = PhotoScan.app.getExistingDirectory("Specify EXPORT folder:")
#Basic parameters
accuracy = PhotoScan.Accuracy.HighAccuracy
preselection = PhotoScan.Preselection.GenericPreselection
keypoints = 40000
tiepoints = 10000
source = PhotoScan.PointsSource.DensePoints
surface = PhotoScan.SurfaceType.Arbitrary
quality = PhotoScan.Quality.MediumQuality
filtering = PhotoScan.FilterMode.AggressiveFiltering
interpolation = PhotoScan.Interpolation.EnabledInterpolation
face_num = PhotoScan.FaceCount.HighFaceCount
mapping = PhotoScan.MappingMode.GenericMapping
atlas_size = 8192
blending = PhotoScan.BlendingMode.MosaicBlending
color_corr = False
print("script start")
#creat chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = "New Chunk"
#add images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():
photo_list.append(path_photos + "\\" + photo)
chunk.addPhotos(photo_list)
#match images
chunk.matchPhotos(accuracy = accuracy, preselection = preselection, filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()
chunk.optimizeCameras()
#point cloud
PhotoScan.app.gpu_mask = 1 #GPU devices binary mask
PhotoScan.app.cpu_cores_inactive = 2 #CPU cores inactive
chunk.buildDenseCloud(quality = quality, filter = filtering)
#build Mode
chunk.buildModel(surface = surface, source = source, interpolation = interpolation, face_count = face_num)
#build texture
chunk.buildUV(mapping = mapping, count = 1)
chunk.buildTexture(blending = blending , color_correction = color_corr, size = atlas_size)
PhotoScan.app.update()
#export
chunk.exportModel(path_export + "\\" + "_out" + ".tif")
print(""script end"")
PhotoScan.app.addMenuItem("Custom menu/Process 1", auto_process)