[英]face_recognition.py: Using multiple known images for face detection. IndexError: list index out of range
我正在使用face_recognition.py api在充滿圖片的文件夾中找到一些已知的面孔。 我已經用一個已知的面孔/圖像測試了我的代碼,但是我嘗試使用多個面孔/圖像進行測試。
但是我一直收到以下錯誤:face_encodings = face_recognition.face_encodings(image)[counter]中的文件“ program.py”,第15行,IndexError:列表索引超出范圍
這是我的代碼片段:
counter = 0
for file in os.listdir(known_dir):
image = face_recognition.load_image_file(known_dir+"/"+ file)
face_encodings = face_recognition.face_encodings(image)[counter]
counter = counter+1
請幫助我擺脫這個錯誤!
以后請考慮發布一個最小,完整和可驗證的示例 。
face_encodings
是否有face_encodings
初始化為列表? 也許您打算這樣做:
face_encodings = []
for file in os.listdir(known_dir):
image = face_recognition.load_image_file(known_dir+"/"+ file)
face_encodings.append(face_recognition.face_encodings(image))
但是,我無法確切地說出是否可以解決問題,因為我無法對其進行測試...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.