方法一:face_recognition

import cv2
import face_recognition
img_path = "C:/Users/CJK/Desktop/1.jpg"#图片目录
im_fr = face_recognition.load_image_file(img_path)
face_ = face_recognition.face_locations(im_fr,number_of_times_to_upsample=1,model="cnn")
print(face_)
im = cv2.imread(img_path)
print("img size ",im.shape)
cv2.namedWindow("result",cv2.WINDOW_NORMAL)
for _ in face_:
top, right, bottom, left = _
cv2.rectangle(im,(left, top), (right, bottom),(0,200,0),2)
cv2.imshow("result",im)
cv2.imwrite("C:/Users/CJK/Desktop/1_cnn.jpg", im)#图片目录加上_cnn后缀
cv2.waitKey(0)

方法二:opencv

import cv2
img_path = "C:/Users/CJK/Desktop/1.jpg"
pathf='D:/Anaconda3/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml'
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
face_cascade.load(pathf)
im = cv2.imread(img_path)
face_ = face_cascade.detectMultiScale(im,scaleFactor=1.1,minNeighbors=10,flags=0|cv2.CASCADE_SCALE_IMAGE,minSize=(1,1))
cv2.namedWindow("result",cv2.WINDOW_NORMAL)
for _ in face_:
lt = (_[0],_[1])
rb = (_[0]+_[2],_[1]+_[3])
cv2.rectangle(im,lt,rb,(0,200,0),2)
cv2.imshow("result",im)
cv2.imwrite("C:/Users/CJK/Desktop/1_harr.jpg",im)
cv2.waitKey(0)

最新文章

  1. HiHo Coder字典树 TrieTree
  2. catalan number
  3. 【转】Struts2国际化
  4. 4D时间管理
  5. Unique Binary Search Trees
  6. 【翻译】Kinect Studio是? 三月 SDK Update的新机能
  7. sql server 函数
  8. LinQ—Lambda表达式
  9. 关于黑名单IP的设置
  10. 手机下的ev.pageX无效
  11. redhat6.4下安装Oracle11g
  12. If I were you
  13. 新闻热词:从爬虫到react native应用
  14. CentOS 7 安装docker (图文)
  15. vue 自定义marquee无缝滚动组件
  16. 《SSO CAS单点系列》之 APP原生应用如何访问CAS认证中心
  17. [luogu1110][ZJOI2007]报表统计【平衡树】
  18. 7.5 GRASP原则五:高内聚 High Cohesion
  19. Docker基本命令与使用 —— Docker容器的网络连接(四)
  20. WCF使用Net.tcp绑定时候出现错误:元数据包含无法解析的引用

热门文章

  1. 困扰所有SAP顾问多年的问题终于解决了
  2. django自带的序列化组件
  3. Redis 03 字符串
  4. 在使用amoeba连接数据库时,报错java.lang.Exception: poolName=slaves, no valid pools
  5. 论文解读(GATv2)《How Attentive are Graph Attention Networks?》
  6. Vue3 发生错误:setup function returned a promise
  7. 【JDBC】学习路径3-密码登录&SQL注入攻击
  8. hadoop 不在 sudoers 文件中,此事将被报告。
  9. angr原理与实践(二)—— 各类图的生成(CFG CG ACFG DDG等)
  10. mysql杂记漫谈