From 7a1aa278026265abd3d78cc09eed1d654bc3f2fb Mon Sep 17 00:00:00 2001 From: ArtsyInd <109792373+ArtsyInd@users.noreply.github.com> Date: Sun, 29 Oct 2023 13:15:32 +0530 Subject: [PATCH] Update face_and_eye_detection.py In this code, I've added histogram equalization to the grayscale frame and optimized the parameters for both face and eye detection. Additionally, I've changed the way eyes are visualized by drawing ellipses instead of rectangles, which provides a more natural representation of eyes. --- Face and Eye Detection/face_and_eye_detection.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Face and Eye Detection/face_and_eye_detection.py b/Face and Eye Detection/face_and_eye_detection.py index c0fd690..b50d631 100644 --- a/Face and Eye Detection/face_and_eye_detection.py +++ b/Face and Eye Detection/face_and_eye_detection.py @@ -9,17 +9,25 @@ ret, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + gray = cv2.equalizeHist(gray) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 5) roi_gray = gray[y:y+h, x:x+w] roi_color = frame[y:y+h, x:x+w] - eyes = eye_cascade.detectMultiScale(roi_gray, 1.3, 5) + eyes = eye_cascade.detectMultiScale(roi_gray, scaleFactor=1.1, minNeighbors=5, minSize=(20, 20)) for (ex, ey, ew, eh) in eyes: - cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 0, 255), 5) + eye_center = (x + ex + ew // 2, y + ey + eh // 2) + radius = int(0.3 * (ew + eh) / 2) + cv2.ellipse(roi_color, eye_center, (radius, radius), 0, 0, 360, (0, 0, 255), 5) cv2.imshow("frame", frame) + if cv2.waitKey(1) == ord("q"): + break +cap.release() + + if cv2.waitKey(1) == ord("q"): break