zoukankan      html  css  js  c++  java
  • Python 对图片进行人脸识别

    import cv2
    
    def detect(path):
        img = cv2.imread(path)
        cascade = cv2.CascadeClassifier("/vagrant/detect/haarcascade_frontalface_alt.xml")#xml文件路径一定要注意
        rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20))
    
        if len(rects) == 0:
            return [], img
        rects[:, 2:] += rects[:, :2]
        return rects, img
    
    def box(rects, img):
        for x1, y1, x2, y2 in rects:
            cv2.rectangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2)
        cv2.imwrite('/vagrant/img/detected.jpg', img);
    
    rects, img = detect("/vagrant/img/one.jpg")
    box(rects, img)
    

     以上是源码,来自:

    http://fideloper.com/facial-detection
    

     依赖:

    $ sudo apt-get update
    $ sudo apt-get install -y vim build-essential python-software-properties    # The Basics
    $ sudo apt-get install -y python-opencv python-numpy python-scipy        # OpenCV items
    
    $ wget http://eclecti.cc/files/2008/03/haarcascade_frontalface_alt.xml
    
  • 相关阅读:
    阅读笔记十四
    惨淡的蓝桥杯国赛经历
    阅读笔记十三
    阅读笔记十二
    阅读笔记十一
    阅读笔记十
    阅读笔记九
    阅读笔记八
    阅读笔记七
    阅读笔记六
  • 原文地址:https://www.cnblogs.com/lanqie/p/7442924.html
Copyright © 2011-2022 走看看