0

I have followed a tutorial to draw rectangle around the face i track. I already write the code same as the tutorial. But when i ran it, it just show the video from the webcam and there is no rectangle drawn around the face. I have no idea why it is happen.

This is my code,

import cv2
import numpy as np

a = cv2.CascadeClassifier('haarcascade_frontalface_default.xml');
cam = cv2.VideoCapture(0);

while(True):
    ret,img=cam.read();
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces = a.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)
    cv2.imshow("Face", img);
    if(cv2.waitKey(1) == ord('q')):
        break;
cam.release()
cv2.destroyAllWindows()

This is my directory with the haarcascade

enter image description here

Josh Parinussa
  • 633
  • 2
  • 11
  • 28
  • For testing purposes, stop capturing frame from camera, instead read a face image from file and try to detect it. – zindarod Sep 17 '17 at 04:46
  • yeah it working in image, but when i am trying to read from webcam it does not draw any rectangle, how i can solve that? – Josh Parinussa Sep 17 '17 at 05:40
  • 1
    It just didn't detect your face. Remove spectacles if you have, get closer to the camera and it should work. – I.Newton Sep 17 '17 at 05:47

0 Answers0