这是一个模块,旨在为初学者抽象出使用opencv检测和识别人脸的复杂性。
visionmadeeas的Python项目详细描述
视觉变得简单
本项目旨在消除初级程序员对开放式CV处理的复杂性,进行人脸检测和识别实验。这个项目最初是为了在我自己教的课程中使用而开发的,但我希望它也能为其他人找到用处。
项目主页
安装
pip install visionmadeeasy
要成功运行演示,您还必须…
- 从https://github.com/opencv/opencv/tree/master/data/haarcascades下载一个级联文件,如
haarcascade_frontalface_default.xml
,并将其保存到项目文件夹中 - 在项目文件夹中创建名为“数据集”的子文件夹。这是存放训练照片的地方。
- 确保已连接网络摄像机:-)
演示代码
importvisionmadeeasydefi_see_a_face(location,img):print(f"I see a face!!! It is at {location['x']},{location['y']}")returnTrue# must return True to keep the loop alivedefi_recognise_a_face(location,person_name,confidence,img):print(f"Hello {person_name}! I am {confidence}% sure it is you :-)")returnTrue# must return True to keep the loop aliveif__name__=="__main__":vme=visionmadeeasy.VisionMadeEasy(0,"dataset")quit=Falsewhilenotquit:print("Demonstration time! Menu of options...")print("1. Detect faces")print("2. Record faces")print("3. Train for faces recorded")print("4. Recognise faces (must do training first)")print("5. Exit")choice=int(input("Enter your option (1 to 5):"))ifchoice==1:print("[face_vision] Task: Searching for faces.\nLook at the camera! (press ESC to quit)")# Demo of detecting facesvme.detect_face(i_see_a_face)elifchoice==2:print("About to save 50 images of different angles etc of a person, saving to folder ./dataset")id=int(input("Enter unique person number: "))n=input("Enter person name: ")print("Smile! :-)")# Demo of recording facesvme.record_face_dataset(images_to_record=50,interval=1,person_identifier=id,person_name=n)elifchoice==3:print("[face_vision] Task: Training... please wait...")# Demo of training facesvme.train_from_faces()elifchoice==4:print("[face_vision] Task: Searching for faces I recognise.\nLook at the camera! (press ESC to quit)")# Demo of recognising facesvme.recognise_face(i_recognise_a_face)elifchoice==5:quit=Trueprint("Goodbye!")
作者
许可证
麻省理工学院许可证(C)2019 Paul Baumgarten