简体   繁体   中英

Python progress bar while loading

I am using a facial recognition program and after executing it, it takes a few seconds until it prints. During those seconds of python loading, is it possible to display a percentage loading bar?

While python is executing and loading, there will be a display of 1% followed by 2%, but on the same line and the 2 replaces the 1 percent.

If you're unclear, simple comment I will help communicate.

The facial recognition code:

import face_recognition
picture_of_me = face_recognition.load_image_file("me.jpg")
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
unknown_picture = face_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
if results[0] == True:
    print("FRS successful: Match found")
else:
    print("FRS unsuccessful")

I am not familiar with the face_recognition module so It will take me time to write a complete answer, but did you consider using TQDM ?

Edit:

If you wish to update the progress bar after each line, you should do something like:

with tqdm(total=100) as pbar:
    picture_of_me = face_recognition.load_image_file("me.jpg")
    pbar.update(20)
    my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
    pbar.update(20)
    unknown_picture = face_recognition.load_image_file("unknown.jpg")
    pbar.update(20)
    unknown_face_encoding =face_recognition.face_encodings(unknown_picture)[0]
    pbar.update(20)
    results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
    pbar.update(20)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM