import cv2 import numpy as np cap = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier( cv2.data.haarcascades + "haarcascade_frontalface_default.xml") my_face_saved = False my_face_position = None my_face_area = None while True: _, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale( gray, scaleFactor=1.05, minNeighbors=3, minSize=(20, 20), flags=cv2.CASCADE_SCALE_IMAGE ) if not my_face_saved and len(faces) > 0: my_face_position = faces[0] mx, my, mw, mh = my_face_position my_face_area = mw * mh my_face_saved = True print("Ваше лицо сохранено! Нажмите 'r' для сброса.") owner_found = False for (x, y, width, height) in faces: if my_face_saved: mx, my, mw, mh = my_face_position current_area = width * height center_match = (abs((x + width/2) - (mx + mw/2)) < 150 and abs((y + height/2) - (my + mh/2)) < 150) area_ratio = current_area / my_face_area area_match = 0.3 < area_ratio < 2.0 if center_match and area_match: color = (0, 0, 255) owner_found = True alpha = 0.7 new_x = int(alpha * x + (1 - alpha) * mx) new_y = int(alpha * y + (1 - alpha) * my) new_w = int(alpha * width + (1 - alpha) * mw) new_h = int(alpha * height + (1 - alpha) * mh) my_face_position = (new_x, new_y, new_w, new_h) my_face_area = new_w * new_h else: color = (255, 0, 0) else: color = (255, 0, 0) cv2.rectangle(frame, (x, y), (x + width, y + height), color, 3) if my_face_saved and not owner_found: cv2.putText(frame, "Owner not found", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) cv2.imshow("Camera", frame) key = cv2.waitKey(1) if key == ord('q'): break elif key == ord('r'): my_face_saved = False my_face_position = None my_face_area = None print("Сохраненное лицо сброшено!") cap.release() cv2.destroyAllWindows() Python import cv2 import numpy as np cap = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier( cv2.data.haarcascades + "haarcascade_frontalface_default.xml") my_face_saved = False my_face_position = None my_face_area = None while True: _, frame = cap.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale( gray, scaleFactor=1.05, minNeighbors=3, minSize=(20, 20), flags=cv2.CASCADE_SCALE_IMAGE ) if not my_face_saved and len(faces) > 0: my_face_position = faces[0] mx, my, mw, mh = my_face_position my_face_area = mw * mh my_face_saved = True print("Ваше лицо сохранено! Нажмите 'r' для сброса.") owner_found = False for (x, y, width, height) in faces: if my_face_saved: mx, my, mw, mh = my_face_position current_area = width * height center_match = (abs((x + width/2) - (mx + mw/2)) < 150 and abs((y + height/2) - (my + mh/2)) < 150) area_ratio = current_area / my_face_area area_match = 0.3 < area_ratio < 2.0 if center_match and area_match: color = (0, 0, 255) owner_found = True alpha = 0.7 new_x = int(alpha * x + (1 - alpha) * mx) new_y = int(alpha * y + (1 - alpha) * my) new_w = int(alpha * width + (1 - alpha) * mw) new_h = int(alpha * height + (1 - alpha) * mh) my_face_position = (new_x, new_y, new_w, new_h) my_face_area = new_w * new_h else: color = (255, 0, 0) else: color = (255, 0, 0) cv2.rectangle(frame, (x, y), (x + width, y + height), color, 3) if my_face_saved and not owner_found: cv2.putText(frame, "Owner not found", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2) cv2.imshow("Camera", frame) key = cv2.waitKey(1) if key == ord('q'): break elif key == ord('r'): my_face_saved = False my_face_position = None my_face_area = None print("Сохраненное лицо сброшено!") cap.release() cv2.destroyAllWindows() Скрипт при запуске берёт ваше лицо и целит распознавание на него Соррян за кривой код