简体   繁体   English

实时跟踪眼睛运动

[英]Tracking eyes motion real time

Helloo guys, I`ve wrote a code in python that detect eyes motion but It works just for video file.大家好,我在 python 中编写了一个检测眼睛运动的代码,但它仅适用于视频文件。

What should I change to make It to detect the motion eyes in the real time through the web cam?我应该改变什么让它通过 web cam 实时检测运动眼?

There is the code:有代码:

import cv2

import numpy as np

cap = cv2.VideoCapture("eye_recording.flv")

while True:
ret, frame = cap.read()
if ret is False:
    break

roi = frame[269: 795, 537: 1416]
rows, cols, _ = roi.shape
gray_roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
gray_roi = cv2.GaussianBlur(gray_roi, (7, 7), 0)

_, threshold = cv2.threshold(gray_roi, 3, 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() cv2.destroyAllWindows()

Change改变

cap = cv2.VideoCapture(0)

That's it而已

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM