TGViewer
[PYTHON:TODAY] [PYTHON:TODAY] @python2day · 63.7K subscribers
Post #7968 9.18K
⚡️ Готовый скрипт для обнаружения лица и глаз в режиме реального времени.

Этот скрипт превращает твою вебку в систему распознавания лиц и глаз.

📸 Использует каскады Хаара от OpenCV — лёгкие, быстрые, работают оффлайн.

Установи OpenCV:

bash
$ pip install opencv-python


⬇️ Скачай XML-файлы классификаторов:

haarcascade_frontalface_default.xml
haarcascade_eye.xml

Код:


python
import cv2 as cv


def detect_faces_and_eyes():
"""
Detects faces and eyes in real-time using the webcam.

Press 'q' to exit the program.
"""
# Load the pre-trained classifiers for face and eye detection
face_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_frontalface_default.xml")
eye_cascade = cv.CascadeClassifier(r"..\libs\haarcascade_eye.xml")

# Open the webcam
cap = cv.VideoCapture(0)

while cap.isOpened():
# Read a frame from the webcam
flag, img = cap.read()

# Convert the frame to grayscale for better performance
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

# Detect faces in the frame
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7)

# Detect eyes in the frame
eyes = eye_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7)

# Draw rectangles around faces and eyes
for x, y, w, h in faces:
cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 1)

for a, b, c, d in eyes:
cv.rectangle(img, (a, b), (a + c, b + d), (255, 0, 0), 1)

# Display the resulting frame
cv.imshow("Face and Eye Detection", img)

# Check for the 'q' key to exit the program
key = cv.waitKey(1)
if key == ord("q"):
break

# Release the webcam and close all windows
cap.release()
cv.destroyAllWindows()


if __name__ == "__main__":
# Call the main function
detect_faces_and_eyes()



✅ Реагирует на движение, показывает всё в терминале;
✅ Работает на любом ноуте;
✅ Идеально для проектов по компьютерному зрению.

Сохрани — пригодится! 👍

😳 Лайф | 📲 Зеркало Max

#python #soft #code
  • 👍 38
  • 🔥 15
  • ❤ 7
More from @python2day
  1. Sep 27, 2026⚡️ Open-source AI-диктофон: записывает разговор, распознаёт участников и превращает часы а…
  2. Sep 27, 2026🤨 Победил босса? А теперь посмотри рекламу. Microsoft 🪟 запатентовала систему, которая п…
  3. Sep 24, 2026😎 Когда узнал, что зарабатываешь больше айтишников
  4. Sep 23, 2026🎬 ИИ научили снимать рекламные ролики одной командой /brag — open-source инструмент, скил…
  5. Sep 23, 2026😯 Наступил звездный час для инфоцыган Чувак наглядно показал разницу нейросетей против ре…
  6. Sep 21, 2026🤖 Будущее наступило старик В Сан-Франциско стартап REK устроил первый публичный поединок…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →