簡體   English   中英

Python 加載時的進度條

[英]Python progress bar while loading

我正在使用面部識別程序,執行后需要幾秒鍾才能打印出來。 在 python 加載的那些秒中,是否可以顯示百分比加載欄?

當 python 正在執行和加載時,將顯示 1%,然后是 2%,但在同一行上,2 會替換 1%。

如果你不清楚,簡單的評論我會幫助溝通。

人臉識別代碼:

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")

我不熟悉 face_recognition 模塊,所以我需要時間來寫一個完整的答案,但是你考慮過使用TQDM嗎?

編輯:

如果你想在每一行之后更新進度條,你應該這樣做:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM