jeudi 3 octobre 2019

How to get the time which a code has spent within a particular if loop

I am providing a piece of code of project for iris localization. So here I would like to get amount of time that a person spends looking at a particular direction. So moreover I want to get entire time a code spends in a specific if loop.

I have tried something using timeit module.But I was not able to get the time when the code enters the if loop and the time at which it leaves the while loop.

                thresh = (five_eye[1]-one_eye[1])
                print("thresh:",thresh)
                # if 13<thresh <16:
                #     print('CENTER')
                #     cv2.putText(frameClone, 'CENTER', 
(90,40),cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 2)
                #     single_eye_state.append(index)
                #     single_eye_state.append('CENTER')
                if 10<thresh<=13:
                    start = timeit.timeit()
                    print('Looking Down 1 Feet')
                    cv2.putText(frameClone,'Looking Down 1 Feet', 
(90,40),cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 2)
                    single_eye_state.append(index)
                    single_eye_state.append('DOWN1')
                    end = timeit.timeit()
                    print(end - start)
                elif 7<thresh<=10:
                    print("Looking Down 2 Feet")
                    cv2.putText(frameClone,'Looking Down 2 Feet', 
(90,40),cv2.FONT_HERSHEY_SIMPLEX, 1.5, (0, 0, 255), 2)
                    single_eye_state.append(index)
                    single_eye_state.append('DOWN2')

Need the total time a code spends in a while loop.

Aucun commentaire:

Enregistrer un commentaire