Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 81e7238

Browse files
Recognition
1 parent f92138b commit 81e7238

File tree

5 files changed

+14
-33334
lines changed

5 files changed

+14
-33334
lines changed

‎Face_Recognition/Recognition.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# We are using the trained yml file.
1414
face_recognizer.read('face_trained.yml')
1515

16-
# img = cv.imread(r'images\henry13円.jpg')
16+
img = cv.imread(r'images\henry13円.jpg')
1717

1818
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
1919
cv.imshow('Person', gray)
@@ -24,8 +24,9 @@
2424
faces = gray[y:y+h, x:x+h]
2525

2626
label, confidence = face_recognizer.predict(faces)
27-
cv.putText(img, str(people[label]), (20, 20), cv.FONT_HERSHEY_COMPLEX, 1.0,
28-
(0, 255, 0), thickness=2)
27+
print(f'Label = {people[label]} with a confidence of {confidence}')
28+
29+
cv.putText(img, str(people[label]), (20, 20), cv.FONT_HERSHEY_COMPLEX, 1.0,(0, 255, 0), thickness=2)
2930
cv.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), thickness=2)
3031

3132
cv.imshow('detected face', img)

‎Face_Recognition/face_train.py‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,25 @@
1818
features = []
1919
labels = []
2020

21-
22-
def train_face():
21+
def train_face(features):
2322
for person in people:
2423
path = os.path.join(DIR, person)
2524
label = people.index(person)
2625

2726
for img in os.listdir(path):
2827
img_path = os.path.join(path,img)
29-
28+
3029
img_arr = cv.imread(img_path, flags=None)
31-
if img_arr is None:
32-
continue
33-
gray = cv.cvtColor(img_arr, cv.COLOR_BGR2GRAY)
30+
img_arr = np.array(img_arr)
31+
gray = cv.cvtColor(np.float32(img_arr), cv.COLOR_BGR2GRAY)
3432

3533
face_rect = haar_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=4)
3634

3735
for (x, y, w, h) in face_rect:
3836
face = gray[y:y+h, x:x+w]
39-
# remove below 2 lines comment
40-
#features.append(face)
41-
#labels.append(label)
42-
43-
44-
train_face()
45-
37+
features.append(face)
38+
labels.append(label)
39+
train_face(features)
4640
# Feature and labels numpy array
4741
features = np.array(features, dtype='object')
4842
labels = np.array(labels)
@@ -51,14 +45,13 @@ def train_face():
5145
face_recognizer = cv.face.LBPHFaceRecognizer_create()
5246

5347
# Trained on features and the labels list
54-
face_recognizer.train(features,labels)
48+
face_recognizer.train(features,labels)
5549

5650
# Just like haar cascade yml file, we can save this file in yml format so that
5751
# we can easily access this trained model
5852
face_recognizer.save('face_trained.yml')
5953

6054
# save the features and labels into the numpy file
6155
# simply remove the comments of the below 2 line
62-
#
63-
# np.save('features.npy', features)
64-
# np.save('labels.npy',labels)
56+
np.save('features.npy', features)
57+
np.save('labels.npy',labels)

‎Face_Recognition/features.npy‎

-2.81 MB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /