Anlık Görüntü ile Yüz Tanıma Phyton Kodları Real Time Face Recognition Kodları - MyBlog - Bilgi Paylaşım Platformu


Anlık Görüntü ile Yüz Tanıma Phyton Kodları Real Time Face Recognition Kodları


Phyotn da yüz tanıma sistemi kodları
Anlık Görüntü ile Yüz Tanıma Phyton Kodları Real Time Face Recognition Kodları

 

 Pyhton dili ile Real Time Recognition  eklentisinin çalıştırılması

  1. # face_recognition ve opencv kütüphanelerini import ederek başlıyoruz
  1. # face_recognition ve opencv kütüphanelerini import ederek başlıyoruz
  2. import face_recognition
  3. import cv2
  4. from playsound import sayHelloToMiray
  5. from playsound import stopMusic
  6. def stopPlayingMusic():
  7.     stopMusic()
  8.     globals()['__nowPlaying']=False
  9.     return
  10. # opencv metodu olan VideoCapture ile webcam'den görüntü almayı başlatıyoruz // 0 default webcam video_capture = cv2.VideoCapture(0)
  11. # Yukarıdaki "mennan sevim" resmini yüklüyoruz ve encoding bilgisini alıyoruz
  12. mennan_image = face_recognition.load_image_file("faces/mennan.jpg")
  13. mennan_face_encoding = face_recognition.face_encodings(mennan_image)[0]
  14. # Yukarıdaki "miray sevim" resmini yüklüyoruz ve encoding bilgisini alıyoruz
  15. miray_image = face_recognition.load_image_file("faces/miray.jpg")
  16. miray_face_encoding = face_recognition.face_encodings(miray_image)[0]
  17.  
  18. # Encoding ve açıklama kısmını burada tanımlıyoruz, birden fazla tanımlayabiliriz
  19. known_face_encodings = [
  20.     mennan_face_encoding,
  21.     miray_face_encoding,
  22. ]
  23. known_face_names = [
  24.     "Mennan Sevim",
  25.     "Miray Sevim"
  26. ]
  27. face_locations = []
  28. face_encodings = []
  29. face_names = []
  30. process_this_frame = True
  31. __nowPlaying = False
  32. while True:
  33.     # Videodan anlık bir kare yakalıyoruz
  34.     ret, frame = video_capture.read()
  35.     
  36.     # Aldığımız kareyi 1/4 oranında küçültüyoruz ve bu daha hızlı sonuç vermeyi sağlıyor
  37.     small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
  38.     
  39.     # BGR(opencv) türündeki resmi RGB(face_recognition) formatına çeviriyoruz
  40.     rgb_small_frame = small_frame[:, :, ::-1]
  41.     if process_this_frame:
  42.        # Uyumlu tüm yüzlerin lokasyonlarını bulan kodlar
  43.         face_locations = face_recognition.face_locations(rgb_small_frame)
  44.         face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
  45.         face_names = []
  46.         for face_encoding in face_encodings:
  47.             # Eşleşen yüzleri topla
  48.             matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
  49.             name = "Bilinmeyen"
  50.             # If a match was found in known_face_encodings, just use the first one.
  51.             if True in matches:
  52.                 first_match_index = matches.index(True)
  53.                 name = known_face_names[first_match_index]
  54.                 if name == "Miray Sevim" and __nowPlaying == False:
  55.                     sayHelloToMiray()
  56.                     globals()['__nowPlaying']=True
  57.                 elif name == "Bilinmeyen":
  58.                     stopPlayingMusic()
  59.             face_names.append(name)
  60.     process_this_frame = not process_this_frame
  61.     print(len(face_names))
  62.     if len(face_names) == 0:
  63.         stopPlayingMusic()
  64.     # Sonuçları göster
  65.     for (top, right, bottom, left), name in zip(face_locations, face_names):
  66.         top *= 4
  67.         right *= 4
  68.         bottom *= 4
  69.         left *= 4
  70.         # Yüzü çerçeve içerisine al
  71.         cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
  72.         # "Mennan Sevim" etiketini oluştur
  73.         cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
  74.         font = cv2.FONT_HERSHEY_DUPLEX
  75.         cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
  76.     # Oluşan çerçeveyi ekrana yansıt
  77.     cv2.imshow('Video', frame)
  78.     # Çıkış için 'q'
  79.     if cv2.waitKey(1) & 0xFF == ord('q'):
  80.         break
  81. # Kamerayı kapat
  82. video_capture.release()
  83. cv2.destroyAllWindows()
import face_recognition

Tepkileriniz Nedir?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0

Bir Yorum Yaz