Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: _danny_ on January 24, 2023, 08:54:54 AM
-
I am trying to use the progress callback option from the Metashape Python API within my scripts for various steps in building an orthomosaic. I have defined a function for printing the progress as per Alexey's recommendations here: https://www.agisoft.com/forum/index.php?topic=6146.0 (https://www.agisoft.com/forum/index.php?topic=6146.0)
def progress_bar_print(p):
global n
if not 'n' in globals():
n = datetime.now()
dif = datetime.now() - n
# If the last progress print was less than .5 seconds, don't print
if dif.seconds > .5:
print('Current task progress: {:.2f}% '.format(p),end="\r")
n = datetime.now()
else:
return False
This works fine for some processes such as building depth maps:
# Dense cloud
dense = Metashape.Tasks.BuildDenseCloud()
dense.keep_depth = False
dense.point_colors = True
dense.point_confidence = False
for i in range(0,len(chunk_dict)):
st = datetime.now()
print('Building Depth Maps for {}'.format(doc.chunks[i].label))
depth.apply(doc.chunks[i], progress=progress_bar_print)
print('Task Complete ')
fin = datetime.now() - st
print('Finished {} in {} seconds\n'.format(doc.chunks[i].label, fin.seconds))
doc.save()
Output: (here the second line keeps getting overwritten as the process proceeds)
(https://i.imgur.com/hH7BFG6.png)
But for other processes, such as building the dense cloud, it behaves strangely, and seems to split up into multiple processes:
for i in range(0,len(chunk_dict)):
st = datetime.now()
print('Building Dense Cloud for {}'.format(doc.chunks[i].label))
dense.apply(doc.chunks[i], progress=progress_bar_print)
print('Task Complete ')
fin = datetime.now() - st
print('Finished {} in {} seconds\n'.format(doc.chunks[i].label, fin.seconds))
doc.save()
Output: (here the progress doesn't overwrite itself like I'd expect, it seems to add it to the existing text, making things look strange)
(https://i.imgur.com/epgJgc7.png)
I'm not sure if this is a problem with my code (pretty likely) or whether it's to do with the dense cloud function itself but any help from others who have experience with this would be appreciated!
-
l