Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Machine Learning by (120 points)
using python 3.8 and the spyder IDE
the code is given here which I us to detect the faces from the recorded video...
and one more issue it not only detect the faces it alos detect hands and other objects as well..
All the files codes are saved at the same place....

plz help me as soon as possible....

import cv2

face_cascade = cv2.CascadeClassifier( + 'haarcascade_frontalface_default.xml')

cap = cv2.VideoCapture('tom_jerry.mp4')

while True:

    # Read the frame

    _, img =

    # Convert to grayscale

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Detect the faces

    faces = face_cascade.detectMultiScale(gray, 1.1, 4)

    # Draw the rectangle around each face

    for (x, y, w, h) in faces:

        cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)

    # Display

    cv2.imshow('img', img)

    # Stop if escape key is pressed

    k = cv2.waitKey(30) & 0xff

    if k==27:


# Release the VideoCapture object


Please log in or register to answer this question.

Browse Categories