[Python笔记]简单的人脸识别

用了自带的dlib库,如果首次安装dlib库会出错,请参考上一篇的文章。
[python笔记]Python dlib的正确安装

import sys

import dlib
import skimage.draw
import skimage.io

load_name = sys.argv[1]
save_name = sys.argv[2]

detector = dlib.get_frontal_face_detector()

img = skimage.io.imread(load_name)
dets = detector(img, 1)
print('detected: {}'.format(len(dets)))
for d in dets:
    r0, c0, r1, c1 = d.top(), d.left(), d.bottom(), d.right()
    print('Detection {}'.format([(r0, c0), (r1, c1)]))
    skimage.draw.set_color(img, skimage.draw.line(r0, c0, r0, c1), (255, 0, 0))
    skimage.draw.set_color(img, skimage.draw.line(r0, c1, r1, c1), (255, 0, 0))
    skimage.draw.set_color(img, skimage.draw.line(r1, c1, r1, c0), (255, 0, 0))
    skimage.draw.set_color(img, skimage.draw.line(r1, c0, r0, c0), (255, 0, 0))

运行

 python3 1.py 1.jpg 1.jpeg 
 //这里的1.jpg是原图,1.jgeg则是识别后的图片

结果:
[Python笔记]简单的人脸识别_第1张图片

你可能感兴趣的:(8.Python应用知识笔记,10.openCV图像处理)