OpenCV人臉檢測

2021-09-05 19:05:43 字數 1677 閱讀 2083

import cv2

import matplotlib.pyplot as plt

#讀取**的人臉檢測:

img = cv2.imread('data/face.jpg',1)#讀取一張

gray = cv2.cvtcolor(img,cv2.color_bgr2gray)#將轉化成灰度

face_cascade = cv2.cascadeclassifier("haarcascade_frontalface_alt2.xml")

#此檔案是opencv的haar人臉特徵分類器

faces = face_cascade.detectmultiscale(gray, 1.3, 5)

for (x,y,w,h) in faces:

img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

cv2.imshow('img',img)

cv2.waitkey()

#呼叫人臉++進行人臉識別

key = "申請的key"

secret = "申請的secret"

img = cv2.imread('data/face.jpg',1)#讀取一張

print("識別到了%d個人臉" % (facenum))

for i in range(facenum):

face_rectangle = faces[i]['face_rectangle']

width = face_rectangle['width']

top = face_rectangle['top']

left = face_rectangle['left']

height = face_rectangle['height']

start = (left, top)

end = (left + width, top + height)

color = (55, 255, 155)

thickness = 3

cv2.rectangle(img, start, end, color, thickness)

# 將bgr影象轉變為rgb影象以列印

cv_rgb = cv2.cvtcolor(img, cv2.color_bgr2rgb)

# 展示含有識別框的影象

plt.imshow(cv_rgb)

plt.show()

#

OpenCV人臉檢測

include include include include include include include include include include static cvmemstorage storage 0 建立乙個記憶體儲存器,來統一管理各種動態物件的記憶體 static cvhaar...

OpenCV人臉檢測

win7 32位 opencv3.0 vs2013 對資料夾中進行人臉檢測 在opencv中,人臉檢測用的是harr或lbp特徵,分類演算法用的是adaboost演算法。這種演算法需要提前訓練大量的,非常耗時,因此opencv已經訓練好了,把訓練結果存放在一些xml檔案裡面。在opencv3.0版本...

opencv人臉檢測

最近有空對學習下opencv的東西,本篇主要記錄對人臉檢測實現,而人臉檢測是為人臉識別做準備。opencv版本 3.3.0 環境 vs2015 void cascadeclassifier detectmultiscale inputarray image,vector objects,double...