title: Python opencv: How to use Kalman filter
body: <p>I'm working with face recognition using Python.</p>
  
  <p>I have a following code:</p>
  
  <pre><code>from sklearn.externals import joblib
  clf = joblib.load('model/svm.pkl')
  pca = joblib.load('model/pca.pkl')
  face_cascade = cv2.CascadeClassifier("classifier/haarcascade_frontalface_alt.xml")
  webcam = cv2.VideoCapture(0)
  ret, frame = webcam.read()
  while ret:
      start = time()
      origin = frame
      gray = cv2.cvtColor(origin, cv2.COLOR_BGR2GRAY)
      cv2.equalizeHist(gray,gray)
  
      faces = face_cascade.detectMultiScale(
          origin,
          scaleFactor=1.1,
          minNeighbors=5,
          minSize=(30, 30),
          flags=cv2.cv.CV_HAAR_SCALE_IMAGE
      )
      for (x, y, w, h) in faces:
          cv2.rectangle(origin, (x, y), (x+w, y+h), (0, 255, 0), 2)
          face = gray[y:y+h , x:x+w]
          cv2.equalizeHist(face,face)
  
          face_to_predict = cv2.resize(face,(100, 100),interpolation = cv2.INTER_AREA)
  
          img = face_to_predict.ravel()
          principle_components = pca.transform(img)
          proba = clf.predict_proba(principle_components) # probability
          pred = clf.predict(principle_components)
          if proba[0][pred]&gt;0.4:
              name = face_profile_names[pred[0]]
  </code></pre>
  
  <p>So, this code works fine and from time to time it recognizes faces as I expected. But there are also a lot of weakness here: if I'm twisting my head the accuracy is too low for me.
  I've found Kalman's filter to improve my face recognition, but I didn't realize how to use it with my existing code.</p>
  
  <p>I've found a few post with using Kalman's filter, but it's not clear enough how it may be used in current case. Some of posts are here:
  <a href="https://stackoverflow.com/questions/29012038/is-there-any-example-of-cv2-kalmanfilter-implementation">Is there any example of cv2.KalmanFilter implementation?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/42904509/opencv-kalman-filter-python">OpenCV Kalman Filter python</a></p>
  
  <p>So, my <code>principle_components</code> is  a Matrix of values and hopefully it may be used for initialization of my Kalman filter, but I'm not sure about that and how this filter may be used after..</p>
  
  <p>Any thoughts?</p>