Python Forum
face tracking using optical flow method using python+opencv - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: face tracking using optical flow method using python+opencv (/thread-2502.html)



face tracking using optical flow method using python+opencv - Aftab - Mar-22-2017

Hello Folks..

I want to track the face in motion. Suppose if i move the face in different directions, then the camera should track that face in that direction and vice versa.
Now this code track faces , if the face is exactly in front of camera. But i want to track faces in motion . How could i do this using optical flow method .. Please help me.

My code is below: detector.py
This code is simple using Cascades method
import cv2
import numpy as np

faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam=cv2.VideoCapture(0);
rec=cv2.createLBPHFaceRecognizer();
rec.load("recognizer/trainningData.yml")
id=0
font=cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_COMPLEX_SMALL,2,1,0,2)
while(True):
        ret,img=cam.read();
        gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        faces=faceDetect.detectMultiScale(gray, 1.3,5);
        for(x,y,w,h) in faces:
              cv2.rectangle(img,(x,y),(x+w,y+h), (0,0,255),2)
              id,conf=rec.predict(gray[y:y+h,x:x+w])
              if(id==1):
                  id="Aftab Ahmed"
              elif (id==2):
                      id="Ahmed"
              cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,255);
        cv2.imshow("Face", img);
        if(cv2.waitKey(1)==ord('q')):
            break;
cam.release()
cv2.destroyAllWindows()



RE: face tracking using optical flow method using python+opencv - wavic - Mar-22-2017

https://www.learnopencv.com/object-tracking-using-opencv-cpp-python/
http://www.pyimagesearch.com/2015/09/21/opencv-track-object-movement/

A little googling