15行python代码实现人脸识别
2024-09-08 09:36:34
方法一: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)
最新文章
- HiHo Coder字典树 TrieTree
- catalan number
- 【转】Struts2国际化
- 4D时间管理
- Unique Binary Search Trees
- 【翻译】Kinect Studio是? 三月 SDK Update的新机能
- sql server 函数
- LinQ—Lambda表达式
- 关于黑名单IP的设置
- 手机下的ev.pageX无效
- redhat6.4下安装Oracle11g
- If I were you
- 新闻热词:从爬虫到react native应用
- CentOS 7 安装docker (图文)
- vue 自定义marquee无缝滚动组件
- 《SSO CAS单点系列》之 APP原生应用如何访问CAS认证中心
- [luogu1110][ZJOI2007]报表统计【平衡树】
- 7.5 GRASP原则五:高内聚 High Cohesion
- Docker基本命令与使用 —— Docker容器的网络连接(四)
- WCF使用Net.tcp绑定时候出现错误:元数据包含无法解析的引用
热门文章
- 困扰所有SAP顾问多年的问题终于解决了
- django自带的序列化组件
- Redis 03 字符串
- 在使用amoeba连接数据库时,报错java.lang.Exception: poolName=slaves, no valid pools
- 论文解读(GATv2)《How Attentive are Graph Attention Networks?》
- Vue3 发生错误:setup function returned a promise
- 【JDBC】学习路径3-密码登录&;SQL注入攻击
- hadoop 不在 sudoers 文件中,此事将被报告。
- angr原理与实践(二)—— 各类图的生成(CFG CG ACFG DDG等)
- mysql杂记漫谈