-
Notifications
You must be signed in to change notification settings - Fork 1
/
celebrity_recognition_male_image.py
61 lines (41 loc) · 1.46 KB
/
celebrity_recognition_male_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt
import pickle
# In[2]:
face_cascade = cv2.CascadeClassifier('F:/dd/Library/etc/haarcascades/haarcascade_frontalface_alt2.xml')
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("actor.yml")
labels = {"person_name": 1}
with open("labels.pickle", 'rb') as f:
og_labels = pickle.load(f)
labels = {v:k for k,v in og_labels.items()}
# In[3]:
frame = cv2.imread('C:/Users/Faiz Khan/Desktop/ddd/images3/unknown/brad.jpg')
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
for (x,y,w,h) in faces:
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]
id_, conf = recognizer.predict(roi_gray)
if conf>=45 and conf <=85:
print(id_)
print(labels[id_])
font = cv2.FONT_HERSHEY_SIMPLEX
name = labels[id_]
color = (255, 255, 255)
cv2.putText(frame, name, (x,y), font, 1, color, 2, cv2.LINE_AA)
img_item = "my-image.png"
cv2.imwrite(img_item, roi_color)
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,255,255),5)
print(id_)
print(labels[id_])
font = cv2.FONT_HERSHEY_SIMPLEX
name = labels[id_]
color = (255, 255, 255)
cv2.putText(frame, name, (x,y), font, 1, color, 2, cv2.LINE_AA)
plt.imshow(frame)
# In[ ]: