Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to recognize people in Image

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use Python to identify people in the image, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Environmental deployment

Just follow the installation and deployment in the previous article.

Code

No nonsense, just go to the code.

#! / user/bin/env python# coding=utf-8 "" @ project: face_recognition@author: swordsman A Liang _ ALiang@file: test.py@ide: PyCharm@time: 2022-01-11 19:50:58 "import face_recognitionknown_faces = [[], []] def add_person (image_path: str Name: str): image = face_recognition.load_image_file (image_path) try: encoding = face_recognition.face_encodings (image) [0] known_faces [0] .append (name) known_faces [1] .append (encoding) except IndexError: print ("I wasn't able to locate any faces in at least one of the images. Check the image files. Aborting... ") def compare (new_image: str): new1 = face_recognition.load_image_file (new_image) unknown_face_encoding = face_recognition.face_encodings (new1) [0] results = face_recognition.compare_faces (known_faces [1], unknown_face_encoding,0.5) print (known_faces [0]) print (results) name =''for i in range (0) Len (known_faces [0]): if results [I]: print (I) name = known_faces [0] [I] break if name =': return'I do not who' else: return nameif _ name__ = ='_ main__': add_person ('data/1.jpg',' Yang Mi') add_person ('data/2.jpg'') Add_person ('data/3.jpg',' Song Yi') add_person ('data/4.jpg',' Deng Ziqi') print (compare ('data/121.jpg')) print (compare (' data/123.jpg'))

Code description:

1. First record some faces and specify the names of the characters. The method is add_person.

2. The compare method is used to determine who the photo is.

Take a look at the picture I prepared first.

Take a look at the photos that need to be verified.

Execution result

It can be seen that Yang Mi and Deng Ziqi have been identified.

The above is all the contents of the article "how to use Python to identify people in an image". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report