-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheye_motion_tracking.py
More file actions
35 lines (27 loc) · 1.08 KB
/
Copy patheye_motion_tracking.py
File metadata and controls
35 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
cap = cv2.VideoCapture("eye_recording.mp4")
while True:
ret, frame = cap.read()
if ret is False:
break
roi = frame[100: 775, 100: 1379]
rows, cols, _ = roi.shape
gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
#gray_roi = cv2.GaussianBlur(gray_roi, (5, 5), 0)
_, threshold = cv2.threshold(gray_roi, 1, 255, cv2.THRESH_BINARY_INV)
contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=lambda x: cv2.contourArea(x), reverse=True)
for cnt in contours:
(x, y, w, h) = cv2.boundingRect(cnt)
cv2.drawContours(roi, [cnt], -1, (0, 0, 255), 3)
cv2.rectangle(roi, (x, y), (x + w, y + h), (255, 0, 0), 2)
cv2.line(roi, (x + int(w/2), 0), (x + int(w/2), rows), (0, 255, 0), 2)
cv2.line(roi, (0, y + int(h/2)), (cols, y + int(h/2)), (0, 255, 0), 2)
break
#cv2.imshow("Threshold", threshold)
#cv2.imshow("gray roi", gray_roi)
cv2.imshow("Roi", roi)
key = cv2.waitKey(30)
if key == 27:
break
cv2.destroyAllWindows()