setInterval in python

Viewed 73

Can someone help me, I want to make this print every 5 seconds, but it always perform in 1 seconds. I find a solution here https://www.codegrepper.com/code-examples/python/how+to+set+interval+in+python but it didnt work for me.

run = True
    for (box, pred) in zip(locs, preds):
        # unpack the bounding box and predictions
        (startX, startY, endX, endY) = box
        (mask, withoutMask) = pred

        def detection():
            global run
            if mask>withoutMask:
                label = "Mask"
                color = (0, 255, 0)
                print("Mask")
            else:
                label = "No Mask"
                color = (0, 0, 255)
                print("No Mask")

            # include the probability in the label
            label = "{}".format(label)

            # display the label and bounding box rectangle on the output frame

            if run:
                Timer(5, detection).start()

            return label, color
            
        label, color = detection()

        cv2.putText(frame, label, (startX, startY - 10),cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)
        cv2.rectangle(frame, (startX, startY), (endX, endY), color, 2)

0 Answers
Related