国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python調(diào)用OpenCV實現(xiàn)人臉識別功能

2020-02-23 00:15:41
字體:
供稿:網(wǎng)友

Python調(diào)用OpenCV實現(xiàn)人臉識別,供大家參考,具體內(nèi)容如下

硬件環(huán)境:

Win10 64位

軟件環(huán)境:

Python版本:2.7.3

IDE:JetBrains PyCharm 2016.3.2

Python庫:

1.1) opencv-python(3.2.0.6)

搭建過程:

OpenCV Python庫:

1. PyCharm的插件源中選擇opencv-python(3.2.0.6)庫安裝

題外話:Python入門Tips

PS1:如何安裝whl文件

1.先安裝PIP

2.CMD命令進入D:/Python27/Scripts里面后再執(zhí)行PIP命令安裝pip install wheel
如果提示'pip'不是內(nèi)部或外部命令,也不是可運行的程序或批處理文件:
①將python安裝目錄下的scripts目錄(例如D:/Python27/Scripts)添加到系統(tǒng)環(huán)境變量path里,注意前加分號。再執(zhí)行該命令
pip install wheel
②在cmd下進入到D:/Python27/Scripts目錄下執(zhí)行該命令
pip install wheel

3.把文件最好放在/Script文件夾里面再pip install xxxx.whl

4.注意whl文件名不能改 必須一模一樣和原名

PS2:到哪找.whl文件?

相關(guān)代碼:

import cv2import numpy as npcv2.namedWindow("test") # Create a windowcap = cv2.VideoCapture(0) #Open camera onesuccess, frame = cap.read() #Read one frameprint("Camera open operation is: ", success);color = (255,0,0) #Config the colorclassfier = cv2.CascadeClassifier("Resources/haarcascade_frontalface_alt.xml")#Make sure this xml file is in the same directory with py file#Otherwise change it to absolute directory. This xml file can be found in D:/My Documents/Downloads/opencv/sources/data/haarcascadeswhile success:  success, frame = cap.read()  size = frame.shape[:2] #  image = np.zeros(size, dtype = np.float16) #  image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #  cv2.equalizeHist(image, image) #  #Below three lines config the minimal image size  divisor = 8  h, w = size  minSize = ((int)(w/divisor), (int)(h/divisor))  faceRects = classfier.detectMultiScale(image, 1.2, 2, cv2.CASCADE_SCALE_IMAGE, minSize) #Face detect  if len(faceRects) > 0:#If face array length > 0    for faceRect in faceRects: #Draw a rectangle for every face        xf, yf, wf, hf = faceRect        x = int((float)(xf))        y = int((float)(yf))        w = int((float)(wf))        h = int((float)(hf))        cv2.rectangle(frame, (x, y), (x + w, y + h), color)        cv2.circle(frame, ((int)(x + 1.2 * w / 4), (int)(y + h / 3)), min((int)(w / 8), (int)(h / 8)), (255, 0, 0))        cv2.circle(frame, ((int)(x + 2.8 * w / 4), (int)(y + h / 3)), min((int)(w / 8), (int)(h / 8)), (255, 0, 0))        #cv2.rectangle(frame, ((int)(x + 3 * w / 8, (int)(y + 3 * h / 4))), ((int)(x + 5 * w / 8), (int)(y + 7 * h / 8)), (255, 0, 0))  cv2.imshow("test", frame) #Display image  key = cv2.waitKey(10)  c = chr(key & 255)  if c in ['q', 'Q', chr(27)]:    breakcv2.destroyWindow("test")

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持武林站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 海兴县| 清水河县| 曲水县| 定西市| 修武县| 班戈县| 辽宁省| 龙岩市| 磴口县| 惠水县| 河南省| 祥云县| 松潘县| 柳州市| 宁陕县| 烟台市| 嘉荫县| 始兴县| 财经| 博湖县| 延寿县| 扶风县| 同德县| 房产| 昭觉县| 湟源县| 汪清县| 六盘水市| 夏河县| 象山县| 漾濞| 常山县| 遵化市| 浑源县| 沁水县| 武城县| 体育| 宁武县| 寿阳县| 石屏县| 莱西市|