zoukankan      html  css  js  c++  java
  • 使用python3完成人脸识别

    原文地址:https://www.jb51.net/article/160197.htm

    第一种:

     1 # -*- coding:utf-8 -*-
     2 import cv2 as cv
     3 import numpy as np
     4  
     5 src = cv.imread('test1.jpg')
     6 path = r'D:face'
     7  
     8 def face_detect_demo():
     9   gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
    10  
    11   face_detector = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
    12   face_detector.load(path + 'haarcascade_frontalface_default.xml')
    13   faces = face_detector.detectMultiScale(gray,1.3,5)
    14   for x,y,w,h in faces:
    15     cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2)
    16   cv.imshow("result",src)
    17  
    18 print("--------------python face detect-------------")
    19 cv.namedWindow("input image",0)
    20 cv.namedWindow("result",0)
    21 cv.imshow("input image",src)
    22 face_detect_demo()
    23 cv.waitKey(0)
    24 cv.destroyAllWindows()

    效果:

    第二种:

     1 # -*- coding:utf-8 -*-
     2 import cv2 as cv
     3 import numpy as np
     4  
     5 src = cv.imread('test1.jpg')
     6 path = r'D:face'
     7  
     8 def face_detect_demo():
     9   gray = cv.cvtColor(src,cv.COLOR_BGR2GRAY)
    10  
    11   face_detector = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
    12   face_detector.load(path + 'haarcascade_frontalface_default.xml')
    13   faces = face_detector.detectMultiScale(gray,1.3,5)
    14   for x,y,w,h in faces:
    15     cv.rectangle(src,(x,y),(x+w,y+h),(0,0,255),2)
    16   cv.imshow("result",src)
    17  
    18 print("--------------python face detect-------------")
    19 cv.namedWindow("input image",0)
    20 cv.namedWindow("result",0)
    21 cv.imshow("input image",src)
    22 face_detect_demo()
    23 cv.waitKey(0)
    24 cv.destroyAllWindows()

    效果:

  • 相关阅读:
    PAT (Advanced Level) 1086. Tree Traversals Again (25)
    PAT (Advanced Level) 1085. Perfect Sequence (25)
    PAT (Advanced Level) 1084. Broken Keyboard (20)
    PAT (Advanced Level) 1083. List Grades (25)
    PAT (Advanced Level) 1082. Read Number in Chinese (25)
    HDU 4513 吉哥系列故事――完美队形II
    POJ Oulipo KMP 模板题
    POJ 3376 Finding Palindromes
    扩展KMP
    HDU 2289 Cup
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/11994081.html
Copyright © 2011-2022 走看看