Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # by nonkung51 for this https://medium.com/@nonthakon/เขียนโปรแกรมเตือนให้พักสายตาด้วย-python-6f61d9f56cf7
- import cv2
- import time
- import easygui
- face_cascade = cv2.CascadeClassifier('data/haarcascades/haarcascade_frontalface_default.xml')
- cap = cv2.VideoCapture(0)
- last_time = time.time()
- elapse = 0
- while True:
- if elapse <= 18*60:
- ret, img = cap.read()
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
- faces = face_cascade.detectMultiScale(gray, 1.3, 5)
- if faces != ():
- elapsePerFrame = time.time() - last_time
- elapse += elapsePerFrame
- print('You stared at the screen for {} seconds now.'.format(round(elapse, 2)))
- last_time = time.time()
- else:
- print('eyes not detect')
- last_time = time.time()
- time.sleep(1)
- else :
- print('Rest your eye!')
- easygui.msgbox('Rest your eye!', 'Eye love you!')
- time.sleep(30)
- easygui.msgbox('It\'s OK now.', 'Eye love you!')
- elapse = 0
- last_time = time.time()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement