转载——不用安装VS2015,win系统下安装dlib,face_recognition-亲测100%成功


安装环境:

    win7 /win8/win10

    python3.6 (必须3.6)

    opencv3

测试代码:


   
   
  1. #coding=utf-8
  2. #人脸识别类 - 使用face_recognition模块
  3. import cv2
  4. import face_recognition
  5. import os
  6. path = "img/face_recognition" # 模型数据图片目录,里面直接放带有名字的图片即可
  7. cap = cv2.VideoCapture( 0)
  8. total_image_name = []
  9. total_face_encoding = []
  10. for fn in os.listdir(path):
  11. print(path + "/" + fn)
  12. total_face_encoding.append(
  13. face_recognition.face_encodings(
  14. face_recognition.load_image_file(path + "/" + fn))[ 0])
  15. fn = fn[:(len(fn) - 4)] #截取图片名(这里应该把images文件中的图片名命名为为人物名)
  16. total_image_name.append(fn) #图片名字列表
  17. while ( 1):
  18. ret, frame = cap.read()
  19. # 发现在视频帧所有的脸和face_enqcodings
  20. face_locations = face_recognition.face_locations(frame)
  21. face_encodings = face_recognition.face_encodings(frame, face_locations)
  22. # 在这个视频帧中循环遍历每个人脸
  23. for (top, right, bottom, left), face_encoding in zip(
  24. face_locations, face_encodings):
  25. # 看看面部是否与已知人脸相匹配。
  26. for i, v in enumerate(total_face_encoding):
  27. match = face_recognition.compare_faces(
  28. [v], face_encoding, tolerance= 0.5)
  29. name = "Unknown"
  30. if match[ 0]:
  31. name = total_image_name[i]
  32. break
  33. # 画出一个框,框住脸
  34. cv2.rectangle(frame, (left, top), (right, bottom), ( 0, 0, 255), 2)
  35. # 画出一个带名字的标签,放在框下
  36. cv2.rectangle(frame, (left, bottom - 35), (right, bottom), ( 0, 0, 255),
  37. cv2.FILLED)
  38. font = cv2.FONT_HERSHEY_DUPLEX
  39. cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0,
  40. ( 255, 255, 255), 1)
  41. # 显示结果图像
  42. cv2.imshow( 'Video', frame)
  43. if cv2.waitKey( 1) & 0xFF == ord( 'q'):
  44. break
  45. cap.release()
  46. cv2.destroyAllWindows()


***最重要的一步***:就是通过https://pypi.org/simple/dlib/  该网站下载whl(编译后的文件,使用pip安装超级简单),不使用whl文件安装,会报各种错误。

第一步:dlib安装:

通过链接:https://pypi.org/simple/dlib/下载“dlib-19.7.0-cp36-cp36m-win_amd64.whl“安装包

     使用命令:pip install dlib-19.7.0-cp36-cp36m-win_amd64.whl.whl

第二步:face_recognition安装

     使用命令:pip install face_recognition

第三步:opencv安装

     使用命令:pin install opencv

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值