1
Python and Java API / Building and Exporting Orthomosaic using Network Processing
« on: May 20, 2021, 11:45:52 AM »
Hello and please forgive me as I am new to Python and Photogrammetry. I am a Systems/DevOps Engineer and a PHP/Javascript developer. My background is building production environments for everything from websites to enterprise applications as well as mobile applications. For the last few months, I have been building a tile processing pipeline that we feed imagery into that is stitched using Pix4d. The tile processing pipeline takes the images fed into it and creates the map tiles so that we can load the imagery into our web application. Moving forward, we want to replace Pix4d with an in-house built and managed stitching pipeline. We have looked at other software and now we're testing Metashape.
Currently, I have three AWS EC2 instances running (a master controller and 2 processing nodes) that all share and AWS EFS mount for shared storage. I have some imagery from a Sony camera on the shared filesystem and I have a Python script that successfully creates a Metashape project (though I do know if it is complete and accurate). You can see that code here: https://pb.recoilnetworks.com/?118554ebbf7cd5c9#5hfzwilEuY1Tt0hi35moHKWhA6kkOApNPlDvi1XmLRQ=
Now, I am trying to write another script that simply exports a single bigtiff Orthomosaic. Here's the current code:
And here's the output:
I am not sure why the DenseCloud says there's a "Zero resolution" and not sure about the other issues the follow. Any help is greatly appreciated!
Also, if you have experience with Metashape and the Python SDK, please reply. We will be looking for a Python developer soon to help us build this pipeline, if we can get this to work.
Currently, I have three AWS EC2 instances running (a master controller and 2 processing nodes) that all share and AWS EFS mount for shared storage. I have some imagery from a Sony camera on the shared filesystem and I have a Python script that successfully creates a Metashape project (though I do know if it is complete and accurate). You can see that code here: https://pb.recoilnetworks.com/?118554ebbf7cd5c9#5hfzwilEuY1Tt0hi35moHKWhA6kkOApNPlDvi1XmLRQ=
Now, I am trying to write another script that simply exports a single bigtiff Orthomosaic. Here's the current code:
Code: [Select]
import Metashape
import sys
def do_create_export(project, dir_root, dir_save, ipaddr):
tasks = list()
doc = Metashape.Document()
doc.open(project, read_only=False, ignore_lock=True)
chunk = doc.chunk
# Match Photos
task = Metashape.Tasks.MatchPhotos()
task.keypoint_limit = 40000
task.tiepoint_limit = 4000
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# Align Cameras
task = Metashape.Tasks.AlignCameras()
task.adaptive_fitting = False
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# Depth Maps
task = Metashape.Tasks.BuildDepthMaps()
task.filter_mode = Metashape.FilterMode.MildFiltering
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# Dense Cloud
task = Metashape.Tasks.BuildDenseCloud()
task.point_colors = True
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# DEM
task = Metashape.Tasks.BuildDem()
task.source_data = Metashape.DataSource.DenseCloudData
task.interpolation = Metashape.Interpolation.Extrapolated
task.projection = chunk.crs
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# Build Orthomosaic
task = Metashape.Tasks.BuildOrthomosaic()
task.resolution = 0.05
task.projection = chunk.crs
task.blending_mode = Metashape.BlendingMode.MosaicBlending
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
# Export Orthomosaic
compression = Metashape.ImageCompression()
compression.tiff_compression = Metashape.ImageCompression.TiffCompressionJPEG
compression.jpeg_quality = 100
compression.tiff_big = True
task = Metashape.Tasks.ExportRaster()
task.path = dir_save + 'orthomosaic.tif'
task.image_compression = compression
task.image_format = Metashape.ImageFormatTIFF
task.projection = chunk.crs
task.save_world = False
task.save_alpha = False
task.white_background = True
task.save_kml = False
task.source_data = Metashape.ElevationData
net_task = Metashape.NetworkTask()
net_task.name = task.name
net_task.params = task.encode()
net_task.frames.append((chunk.key, 0))
tasks.append(net_task)
client = Metashape.NetworkClient()
client.connect(ipaddr)
batch_id = client.createBatch(project[len(dir_root):], tasks)
client.resumeBatch(batch_id)
if len(sys.argv) > 2:
psx = sys.argv[1]
rdir = sys.argv[2]
sdir = sys.argv[3]
sip = sys.argv[4]
do_create_export(psx, rdir, sdir, sip)
else:
print("-- missing arguments - provide project file path, root path, save path, and server ip --")
And here's the output:
Code: [Select]
2021-05-20 08:28:08 [172.16.2.101:50920] finished #1 MatchPhotos
2021-05-20 08:28:10 [172.16.2.101:50920] finished #1 MatchPhotos.initialize (1/1)
2021-05-20 08:28:11 [172.16.2.101:50920] finished #1 MatchPhotos.cleanup (1/1)
2021-05-20 08:28:12 [172.16.2.101:50920] finished #1 AlignCameras
2021-05-20 08:28:13 [172.16.2.101:50920] finished #1 AlignCameras.initialize (1/1)
2021-05-20 08:28:14 [172.16.2.101:50920] finished #1 AlignCameras.update (1/1)
2021-05-20 08:28:15 [172.16.2.101:50920] finished #1 AlignCameras.finalize (1/1)
2021-05-20 08:28:16 [172.16.2.101:50920] finished #1 AlignCameras.cleanup (1/1)
2021-05-20 08:28:17 [172.16.2.101:50920] finished #1 BuildDepthMaps
2021-05-20 08:28:18 [172.16.2.101:50920] finished #1 BuildDepthMaps.initialize (1/1)
2021-05-20 08:28:20 [172.16.2.101:50920] finished #1 BuildDepthMaps.finalize (1/1)
2021-05-20 08:28:21 [172.16.2.101:50920] finished #1 BuildDepthMaps.cleanup (1/1)
2021-05-20 08:28:22 [172.16.2.101:50920] finished #1 BuildDenseCloud
2021-05-20 08:28:23 [172.16.2.101:50920] finished #1 BuildDenseCloud.initialize (1/1): Zero resolution
2021-05-20 08:28:24 [172.16.2.101:50920] finished #1 BuildDenseCloud.cleanup (1/1)
2021-05-20 08:28:25 [172.16.2.101:50920] finished #1 BuildDem
2021-05-20 08:28:26 [172.16.2.101:50920] finished #1 BuildDem.initialize (1/1): Null dense cloud
2021-05-20 08:28:27 [172.16.2.101:50920] finished #1 BuildDem.cleanup (1/1)
2021-05-20 08:28:28 [172.16.2.101:50920] finished #1 BuildOrthomosaic
2021-05-20 08:28:30 [172.16.2.101:50920] finished #1 BuildOrthomosaic.initialize (1/1): Null model
2021-05-20 08:28:31 [172.16.2.101:50920] finished #1 BuildOrthomosaic.cleanup (1/1)
2021-05-20 08:28:32 [172.16.2.101:50920] finished #1 ExportRaster: Null elevation
I am not sure why the DenseCloud says there's a "Zero resolution" and not sure about the other issues the follow. Any help is greatly appreciated!
Also, if you have experience with Metashape and the Python SDK, please reply. We will be looking for a Python developer soon to help us build this pipeline, if we can get this to work.