diff options
author | Théo de la Hogue | 2022-04-13 17:45:21 +0200 |
---|---|---|
committer | Théo de la Hogue | 2022-04-13 17:45:21 +0200 |
commit | 529e8ac3ea24f0aec09162bdc3be369b28c382c5 (patch) | |
tree | 799363263b5f71b25168605e1832283d4d55c4a0 | |
parent | 3bf7254b9967ab31bb016944bdc232839dbf3604 (diff) | |
download | argaze-529e8ac3ea24f0aec09162bdc3be369b28c382c5.zip argaze-529e8ac3ea24f0aec09162bdc3be369b28c382c5.tar.gz argaze-529e8ac3ea24f0aec09162bdc3be369b28c382c5.tar.bz2 argaze-529e8ac3ea24f0aec09162bdc3be369b28c382c5.tar.xz |
Adding a progress bar feature
-rw-r--r-- | src/argaze/utils/MiscFeatures.py | 24 | ||||
-rw-r--r-- | src/argaze/utils/__init__.py | 3 | ||||
-rw-r--r-- | src/argaze/utils/export_tobii_segment_aruco_rois.py | 9 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/argaze/utils/MiscFeatures.py b/src/argaze/utils/MiscFeatures.py new file mode 100644 index 0000000..24f1791 --- /dev/null +++ b/src/argaze/utils/MiscFeatures.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +# Print iterations progress +def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█', printEnd = "\r"): + """Print iterations progress. + Call in a loop to create terminal progress bar + @params: + iteration - Required : current iteration (Int) + total - Required : total iterations (Int) + prefix - Optional : prefix string (Str) + suffix - Optional : suffix string (Str) + decimals - Optional : positive number of decimals in percent complete (Int) + length - Optional : character length of bar (Int) + fill - Optional : bar fill character (Str) + printEnd - Optional : end character (e.g. "\r", "\r\n") (Str) + """ + percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total))) + filledLength = int(length * iteration // total) + bar = fill * filledLength + '-' * (length - filledLength) + print(f'\r{prefix} |{bar}| {percent}% {suffix}', end = printEnd) + + # Print New Line on Complete + if iteration == total: + print() diff --git a/src/argaze/utils/__init__.py b/src/argaze/utils/__init__.py index 1448ed6..262a0e2 100644 --- a/src/argaze/utils/__init__.py +++ b/src/argaze/utils/__init__.py @@ -1,4 +1,5 @@ """ .. include:: README.md """ -__docformat__ = "restructuredtext"
\ No newline at end of file +__docformat__ = "restructuredtext" +__all__ = ['MiscFeatures']
\ No newline at end of file diff --git a/src/argaze/utils/export_tobii_segment_aruco_rois.py b/src/argaze/utils/export_tobii_segment_aruco_rois.py index a192cf1..d28f887 100644 --- a/src/argaze/utils/export_tobii_segment_aruco_rois.py +++ b/src/argaze/utils/export_tobii_segment_aruco_rois.py @@ -9,6 +9,7 @@ from argaze import GazeFeatures from argaze.TobiiGlassesPro2 import TobiiEntities, TobiiVideo from argaze.ArUcoMarkers import * from argaze.RegionOfInterest import * +from argaze.utils import MiscFeatures import numpy @@ -86,6 +87,10 @@ def main(): # Video and data replay loop try: + # print 0% progress + frame_count = 0 + MiscFeatures.printProgressBar(frame_count, tobii_segment_video.get_frame_number(), prefix = 'Progress:', suffix = 'Complete', length = 100) + # Iterate on video frames activating video / data synchronisation through vts data buffer for video_ts, video_frame in tobii_segment_video.frames(tobii_segment_data.vts): @@ -147,6 +152,10 @@ def main(): # Write video output_video.write(video_frame.matrix) + # Update Progress Bar + frame_count += 1 + MiscFeatures.printProgressBar(frame_count, tobii_segment_video.get_frame_number(), prefix = 'Progress:', suffix = 'Complete', length = 100) + # Exit on 'ctrl+C' interruption except KeyboardInterrupt: pass |