Forum

Author Topic: Progress Callback function/Progress Bar?  (Read 6201 times)

boulder1998

  • Newbie
  • *
  • Posts: 7
    • View Profile
Progress Callback function/Progress Bar?
« on: July 06, 2023, 03:37:43 PM »
Hello everybody,

I am working on a python Metashape script in Visual Studio Code using Jupyter Notebooks on a MacBook Air M2 with 16GB Memory.
I want to know how long each Metashape task/function (e.g. matchPhotos, buildModel, buildDEM, etc.) in my code is going to take.
I've started to use the following suggestion by Alexey from a few years back:

Hello kingd0559,

The simple example of callback function usage is below:
Code: [Select]
def progress_print(p):
        print('Current task progress: {:.2f}%'.format(p))

chunk = PhotoScan.app.document.chunk
chunk.matchPhotos(progress=progress_print)

It will print the current progress to the console for the image matching operation.

However, applying this function for example to buildUV or buildModel will make VSC go to a kinda "freeze" mode and it's hard to do anything until the task is done, this with only a view pictures as a trial basis. Plus, the cell outputs and hence, also the progress, is not properly displayed anymore.
Has someone experienced a similar situation and knows what one can do about it, especially for bigger projects?

-------------

In the discussion where I found the above, there was also the following idea by Alexey that I like:
And another simple example that may be helpful for those who want also to estimate the time left for the current operation based on the spent time and current progress value:

Code: [Select]
import time, PhotoScan
def progress_print(p):
        elapsed = float(time.time() - start_time)
        if p:
            sec = elapsed / p * 100
print('Current task progress: {:.2f}%, estimated time left: {:.0f} seconds'.format(p, sec))
else:
print('Current task progress: {:.2f}%, estimated time left: unknown'.format(p)) #if 0% progress

chunk = PhotoScan.app.document.chunk
global start_time
start_time = time.time()
chunk.matchPhotos( progress=progress_print)

Changing PhotoScan to Metashape did not the job. Is there an updated way to do this for Metashape version 2.0.1? maybe even with adding a progress bar?  ;)

Thank you for replies.

Cheers, boulder1998

ankit108

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Progress Callback function/Progress Bar?
« Reply #1 on: July 08, 2023, 05:40:29 PM »
Why is it getting freezed? is it because progress print prints too many lines??
if that is the reason, you can test a workaround..
Code: [Select]
import time, PhotoScan
def progress_print(p):
        elapsed = float(time.time() - start_time)
        if p:
            sec = elapsed / p * 100
print('Current task progress: {:.2f}%, estimated time left: {:.0f} seconds'.format(p, sec), end="\r", flush=True)
else:
print('Current task progress: {:.2f}%, estimated time left: unknown'.format(p), end="\r", flush=True) #if 0% progress

chunk = PhotoScan.app.document.chunk
global start_time
start_time = time.time()
chunk.matchPhotos( progress=progress_print)

ankit108

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Progress Callback function/Progress Bar?
« Reply #2 on: July 08, 2023, 05:57:43 PM »
Why is it getting freezed? is it because progress_print prints too many lines??
if that is the reason, you can test a workaround..
Code: [Select]
import time, PhotoScan
def progress_print(p):
        elapsed = float(time.time() - start_time)
        if p:
            sec = elapsed / p * 100
print('Current task progress: {:.2f}%, estimated time left: {:.0f} seconds'.format(p, sec), end="\r", flush=True)
else:
print('Current task progress: {:.2f}%, estimated time left: unknown'.format(p), end="\r", flush=True) #if 0% progress

chunk = PhotoScan.app.document.chunk
global start_time
start_time = time.time()
chunk.matchPhotos( progress=progress_print)