Skip to content

Commit

Permalink
added progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
01-DC committed Feb 26, 2022
1 parent e100e7e commit 9821f08
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions videoAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
from PIL import Image
import imagehash

def printProgressBar (iteration, total, prefix = '', suffix = '', decimals = 1, length = 100, fill = '█'):
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 = '\r')
if iteration == total:
print()

def videoAnalysis(FRAMES_SKIP, VIDEO_PATH):
vid= cv2.VideoCapture(VIDEO_PATH)
f= open('frameHashData.txt', 'w', buffering=1) # For storing and analysing frame hash differences
printProgressBar(vid.get(cv2.CAP_PROP_POS_FRAMES), vid.get(cv2.CAP_PROP_FRAME_COUNT), prefix = 'Progress:', suffix = 'Complete', length = 50)

success, prevImg= vid.read()
prevHash= imagehash.dhash(Image.fromarray(np.uint8(prevImg)).convert('RGB'), hash_size=64)
Expand All @@ -22,10 +31,9 @@ def videoAnalysis(FRAMES_SKIP, VIDEO_PATH):
break

currHash= imagehash.dhash(Image.fromarray(np.uint8(currImg)).convert('RGB'), hash_size=64)

f.write(str(currHash-prevHash)+' '+str(vid.get(cv2.CAP_PROP_POS_FRAMES))+'\n')

prevHash= currHash
printProgressBar(vid.get(cv2.CAP_PROP_POS_FRAMES), vid.get(cv2.CAP_PROP_FRAME_COUNT), prefix = 'Progress:', suffix = 'Complete', length = 50)

f.close()
vid.release()
Expand Down

0 comments on commit 9821f08

Please sign in to comment.