Forum

Author Topic: Example for progress (Callable[[float], None]) – Progress callback  (Read 5304 times)

yweidmann

  • Newbie
  • *
  • Posts: 9
    • View Profile
Dear Community

I am looking for a code example to use the functionality of "progress (Callable[[float], None]) – Progress callback".

As I assume, the callback will be called at the given percentages of progress.

Question:
- Can someone post an example of using the progress callback?

Looking forward to any hint.

Best regards,
Yvo

csbubbles

  • Newbie
  • *
  • Posts: 6
    • View Profile
Can't get "progress" callback working
« Reply #1 on: May 02, 2018, 11:20:32 PM »
I am running the following code snippet below:

Code: [Select]
class Progress(object):
    def __call__(self, state):
        print("Called!")
        print("State: {}".format(state))

progress_callback = Progress()

doc.chunk.alignCameras(progress=progress_callback)

But it doesn't seem like my callback is getting called:

Code: [Select]
2018-05-02 13:11:06 AlignCameras: adaptive fitting = 1
2018-05-02 13:11:06 processing matches... done in 8.7e-05 sec
2018-05-02 13:11:06 selecting camera groups... done in 0.000384 sec
2018-05-02 13:11:06 processing block: 1 photos
...
2018-05-02 13:11:06 point variance: 0 threshold: 9.088
2018-05-02 13:11:06 adding 0 points, 0 far (9.088 threshold), 0 inaccurate, 0 invisible, 0 weak
2018-05-02 13:11:06 optimized in 0.001967 seconds
2018-05-02 13:11:06 coordinates applied in 0 sec
2018-05-02 13:11:06 Finished processing in 0.085296 sec (exit code 1)

I have also tried to define a function instead of a Callable class and pass its name to alignCameras(), it didn't work either.

Could someone please help me out and explain if I am doing something wrong, and how it needs to be?

I couldn't find any examples in PhotoScan's documentation...
Thanks in advance.

PhotoScan Professional 1.4.2
Build 6205 (64 bit)
macOS High Sierra 10.13.3[/code]

kingd0559

  • Newbie
  • *
  • Posts: 4
    • View Profile
Advice on Progress Callbacks
« Reply #2 on: July 11, 2018, 08:06:23 PM »
I've noticed that a handful of the functions in the PhotoScan library make use of progress callbacks. Being somewhat of a novice to Python, I'm not entirely sure how to make use of the callbacks, but I'd like to use them to output the progress to the console.

If anyone has an example of this, an explanation, or some pointers on how to make this happen, that would be greatly appreciated.  :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Advice on Progress Callbacks
« Reply #3 on: July 11, 2018, 08:40:25 PM »
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.
Best regards,
Alexey Pasumansky,
Agisoft LLC

kingd0559

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Example for progress (Callable[[float], None]) – Progress callback
« Reply #4 on: July 11, 2018, 09:16:53 PM »
Awesome. Thanks again Alexey! And thanks for digging up this old thread to answer my question too!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Example for progress (Callable[[float], None]) – Progress callback
« Reply #5 on: July 19, 2018, 06:53:37 PM »
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)
Best regards,
Alexey Pasumansky,
Agisoft LLC