Skip to content

Commit

Permalink
outputting now the time left for processing the remainder of the imag…
Browse files Browse the repository at this point in the history
…es as well
  • Loading branch information
fracpete committed May 25, 2020
1 parent 1e37874 commit b035722
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

0.0.3 (2020-05-25)
------------------

- outputting now the time left for processing the remainder of the images as well


0.0.2 (2020-05-25)
------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _read(f):
packages=[
"sid",
],
version="0.0.2",
version="0.0.3",
author='Peter Reutemann',
author_email='fracpete@waikato.ac.nz',
install_requires=[
Expand Down
23 changes: 22 additions & 1 deletion src/sid/debayer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
import datetime
import os
import cv2
import traceback
Expand All @@ -22,6 +23,25 @@ def check_params(input_dir, output_dir, color_profile):
raise Exception("Output directory '%s' does not exist or not a directory!" % input_dir)


def calculate_remaining_time(start, processed, total):
"""
Generates the number of seconds the processing will still take.
:param start: the start time
:type start: datetime.dateime
:param processed: the number of images processed so far
:type processed: int
:param total: the total number of images to process
:type total: int
:return: the time still left for finishing the remainder of the files
:rtype: datetime.timedelta
"""

now = datetime.datetime.now()
per_image = (now - start) / processed
return (total - processed) * per_image


def debayer_image(input, output, color_profile):
"""
Debayers a single image using the specified color profile and writes it to the supplied output file.
Expand Down Expand Up @@ -86,6 +106,7 @@ def debayer(input_dir, input_ext="bmp", output_dir=None, output_ext="jpg", recur
print("Total images to debayer: %d" % total)

# convert images
start = datetime.datetime.now()
current = 0
for dir in directories:
files = [x for x in os.listdir(dir) if x.endswith("." + input_ext)]
Expand All @@ -101,7 +122,7 @@ def debayer(input_dir, input_ext="bmp", output_dir=None, output_ext="jpg", recur
if not dry_run:
debayer_image(infile, outfile, profile)
if current % progress_interval == 0:
print("Progress: %d / %d" % (current, total))
print("Progress: %d / %d - ETA %s" % (current, total, str(calculate_remaining_time(start, current, total))))


def main(args=None):
Expand Down

0 comments on commit b035722

Please sign in to comment.