A grayscale image stores one intensity value for each pixel instead of three color components. In this workflow, intensity runs from 0 for black through gray values to 255 for white. A 640 by 480 color image therefore has shape (480, 640, 3), while its grayscale version has shape (480, 640). section 9.3.1
Convert a camera image to grayscale before face detection so the classifier can compare pixel intensities across image regions. With OpenCV, call cv2.cvtColor on the loaded frame using cv2.COLOR_BGR2GRAY. section 9.3.1
>>> gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
This conversion produces a single-channel image named gray from a BGR camera frame. section 9.3.1
Grayscale conversion is preparation rather than the final detection step. Histogram equalization can then improve contrast, producing a cleaned image for detectMultiScale. Packaging both operations in a prep_face function makes the same preparation reusable whenever a frame is checked for a face. section 9.3.1 section 9.3.2
Prepare a face image
Load photo.jpg, convert it to grayscale, and equalize its histogram. Pass the prepared image to the face classifier, while retaining the original color frame for drawing the detected rectangle and center marker. section 9.3.1 section 9.3.2


