Python和Opencv中的平滑跟踪

时间:2017-04-17 06:03:35

标签: python opencv numpy tracking

大家好我是Python和opencv的新手,

你能指导我追踪人类虹膜的最佳方法吗?我已经为虹膜创建了ROI,但由于直播,当我通过虹膜的x和y坐标时,它开始随机移动。当下一帧占据前一帧的空间时会发生这种情况。

我写了以下代码:

import numpy as np
import cv2
import time
import ctypes

face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier("haarcascade_righteye_2splits.xml")

cap = cv2.VideoCapture(0)

while True:
        ret, img = cap.read()
        frame=img
        if ret== True:
                egray = cv2.cvtColor(img ,cv2.COLOR_BGR2GRAY)
                faces = face_cascade.detectMultiScale(egray ,1.3 ,5)
                for (x, y, w, h) in faces :
                    eyes=eye_cascade.detectMultiScale(egray)
                    for (ex, ey, ew, eh) in eyes :
                        if (ex>0)&(ey>0)&(ew>0)&(eh>0):
                                gray=egray[ey+25:ey+eh-10,ex+15:ex+ew-15]
                                (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
                                ctypes.windll.user32.SetCursorPos(minLoc[0],minLoc[1])
                                cv2.rectangle(img,(ex,ey),(ex+ew,ey+eh),(255 , 0, 0), 2)

                cv2.imshow('Faces',img)
                cv2.imshow('Gray',egray)
                k = cv2.waitKey(30)& 0xff
                if k==27:
                        break

cap.release()
cv2.destroyAllWindows()

0 个答案:

没有答案