Opencv Haar Cascade Frontal Face Xml Download Patched May 2026

Open Source Computer Vision Library. Contribute to opencv/opencv development by creating an account on GitHub. OpenCV Face detection with Haar cascades - PyImageSearch

Click the button in the top right corner of the file view. opencv haar cascade frontal face xml download

import cv2 # 1. Load the pre-trained Haar Cascade XML file # Ensure the XML file is in the same directory as your script face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') # 2. Read the input image img = cv2.imread('your_image.jpg') # 3. Convert image to grayscale (Haar cascades require grayscale input) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 4. Detect faces # scaleFactor: how much the image size is reduced at each image scale # minNeighbors: how many neighbors each candidate rectangle should have faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=4) # 5. Draw rectangles around the detected faces for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) # Display result cv2.imshow('Face Detection', img) cv2.waitKey(0) cv2.destroyAllWindows() Use code with caution. Open Source Computer Vision Library

If you have already installed OpenCV via pip , the files are often located within your Python environment's site-packages under cv2/data/ . How to Use the XML File in Python import cv2 # 1