O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
“KOMPYUTER TIZIMLARI” kafedrasi
Kompyuter ko‘rishni raspberry pi bilan dasturlash fanidan tayyorlagan
Amaliy ish-7
Bajardi:Karimova Gavhar
Tekshirdi: Karimberdiyev Jaxongir
TOSHKENT – 2024
“Kompyuter ko‘rishni raspberry pi bilan dasturlash” fanidan 6-amaliy ish uchun topshiriq
-
Yuzdan tanib oluvchi (face recognition) dastur yarating.
-
Talaba o‘zining yuzini dastur orqali aniqlash jarayonini amalga oshirishi kerak va skrinshot tarzda word hujjat tayyorlashi lozim.
-
Dastur kodini va .doc hujjatlarni tizimga yuklashi zarur.
import cv2
import numpy as np
# Load the image of the known person
known_image = cv2.imread('image1.jpg', cv2.IMREAD_GRAYSCALE)
# Load the classifier for face detection
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# Initialize the camera
cap = cv2.VideoCapture(0)
while True:
# Read a frame from the camera
ret, frame = cap.read()
if not ret:
print("Error reading frame from camera")
break
# Convert the frame to grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Detect faces in the frame
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in faces:
# Extract the face region from the frame
face = gray[y:y+h, x:x+w]
# Resize the known image to match the size of the detected face
resized_known_image = cv2.resize(known_image, (w, h))
# Compare the detected face with the known image
diff = cv2.absdiff(face, resized_known_image)
similarity = np.mean(diff)
# Draw a rectangle around the detected face
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
# Display the person's name if similarity is below a certain threshold
if similarity < 100: # Adjust this threshold as needed
cv2.putText(frame, "Zuhriddin", (x, y+h+30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
else:
cv2.putText(frame, "Unknown person", (x, y+h+30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
# Display the resulting frame
cv2.imshow('Face Recognition', frame)
# Exit loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the camera and close all windows
cap.release()
cv2.destroyAllWindows()
|