Histogram equalization prepares a grayscale image for face detection by improving its contrast. In a face-following camera workflow, convert the color frame to a single intensity channel first, then equalize that grayscale image before running the classifier. Better contrast helps improve face-detection accuracy. section 9.3.1 section 9.6
Use it as a small image-preparation step:
- Load a camera image or saved photo into a frame. section 9.3.1
- Convert the color frame to grayscale with cv2.cvtColor(..., cv2.COLOR_BGR2GRAY), producing one intensity value per pixel from 0 (black) to 255 (white). section 9.3.1
- Call cv2.equalizeHist(gray) and pass the resulting clean image to detectMultiScale. section 9.3.1
- Keep the original frame when drawing the detected face rectangle and center marker for display. section 9.3.2
def prep_face(frame):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
return cv2.equalizeHist(gray)
Put grayscale conversion and histogram equalization in a reusable prep_face function so every frame is prepared the same way before detection. section 9.3.2
Prepare a photo before locating a face
A photo is converted from color to grayscale, equalized into clean, and checked with a Haar-cascade classifier. After a match is found, the application calculates the rectangle center, draws a blue rectangle and marker on the original image, and displays it. section 9.3.1 section 9.3.2
