Я пытаюсь запустить функцию в течение определенного c периода времени в течение n секунд. Однако получение indexError. Я пытался несколько раз решить проблему в течение нескольких часов, но я не могу понять, что происходит не так. Ниже приведен пример кода.
def recognize_face_time(i):
global dirname
imageList = list(paths.list_images(dirname))
#print(imageList)
print("[INFO] loading encodings...")
data = pickle.loads(open("encodings.pickle", "rb").read())
# load the input image and convert it from BGR to RGB
image = cv2.imread(imageList[i])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# detect the (x, y)-coordinates of the bounding boxes corresponding
# to each face in the input image, then compute the facial embeddings
# for each face
print("[INFO] recognizing faces...")
boxes = face_recognition.face_locations(rgb,
model="hog")
encodings = face_recognition.face_encodings(rgb, boxes)
# initialize the list of names for each face detected
names = []
# loop over the facial embeddings
for encoding in encodings:
# attempt to match each face in the input image to our known
# encodings
matches = face_recognition.compare_faces(data["encodings"],
encoding, tolerance=0.45)
name = "Unknown"
# check to see if we have found a match
if True in matches:
# find the indexes of all matched faces then initialize a
# dictionary to count the total number of times each face
# was matched
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
# loop over the matched indexes and maintain a count for
# each recognized face face
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
# determine the recognized face with the largest number of votes
name = max(counts, key=counts.get)
# update the list of names
names.append(name)
i += 1
x = threading.Timer(1, recognize_face_time, [i])
x.start()
#test_names.append(names)
if i == 4:
x.cancel()
#print(test_names)
Вот ошибка, которую я имею
image = cv2.imread(imageList[i])
IndexError: list index out of range