Python va Opencv yordamida veb-kamera yordamida yuzni aniqlash


Kod: Bir nechta yuzlarni tanib olish uchun



Download 52,29 Kb.
bet3/3
Sana29.05.2022
Hajmi52,29 Kb.
#615842
1   2   3
Bog'liq
Python va OpenCV yordamida veb

Kod: Bir nechta yuzlarni tanib olish uchun.

"""
Usage:
face_recognize.py -d -i
Options:
-h, --help Show this help
-d, --train_dir = Directory with 
images for training
-i, --test_image = Test image
"""
# importing libraries
import face_recognition
import docopt
from sklearn import svm
import os
def face_recognize(dir, test):
# Training the SVC classifier
# The training data would be all the 
# face encodings from all the known 
# images and the labels are their names
encodings = []
names = []
# Training directory
if dir[-1]!='/':
dir += '/'
train_dir = os.listdir(dir)
# Loop through each person in the training directory
for person in train_dir:
pix = os.listdir(dir + person)
# Loop through each training image for the current person
for person_img in pix:
# Get the face encodings for the face in each image file
face = face_recognition.load_image_file(
dir + person + "/" + person_img)
face_bounding_boxes = face_recognition.face_locations(face)
# If training image contains exactly one face
if len(face_bounding_boxes) == 1:
face_enc = face_recognition.face_encodings(face)[0]
# Add face encoding for current image 
# with corresponding label (name) to the training data
encodings.append(face_enc)
names.append(person)
else:
print(person + "/" + person_img + " can't be used for training")
# Create and train the SVC classifier
clf = svm.SVC(gamma ='scale')
clf.fit(encodings, names)
# Load the test image with unknown faces into a numpy array
test_image = face_recognition.load_image_file(test)
# Find all the faces in the test image using the default HOG-based model
face_locations = face_recognition.face_locations(test_image)
no = len(face_locations)
print("Number of faces detected: ", no)
# Predict all the faces in the test image using the trained classifier
print("Found:")
for i in range(no):
test_image_enc = face_recognition.face_encodings(test_image)[i]
name = clf.predict([test_image_enc])
print(*name)
def main():
args = docopt.docopt(__doc__)
train_dir = args["--train_dir"]
test_image = args["--test_image"]
face_recognize(train_dir, test_image)
if __name__=="__main__":
main()

Uni terminalda qanday ishga tushirish kerak:
python face_recognize.py -d train_dir -i test_image.jpg
Download 52,29 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish