I have a code for a face detector, and here is how it works:
If the face detector doesn't detect a face (doesn't return a value), it will simply print a word, for instance "Hello World".
But what I need is that if the face detector doesn't detect a face (doesn't return a value) for longer than 3 seconds, then it would print the word. So I don't want it to print the word immediately after not detecting a face (no value has been returned).
I've tried doing a time.sleep(3) but that basically delays the whole code.
# "detector" is a library used for the face detecting.
faces = detector(gray)
# If it doesn't detect a face, it will print a word.
if not faces:
print("Hello World")
# A for-loop that prints the coordinates of the face.
for face in faces:
x, y = face.left(), face.top()
x1, y1 = face.right(), face.bottom()
rectangle = cv2.rectangle(frame, (x, y), (x1, y1), (0, 255, 0), 2)
print(rectangle)