python調(diào)用OpenCV實(shí)現(xiàn)人臉識(shí)別功能
Python調(diào)用OpenCV實(shí)現(xiàn)人臉識(shí)別,供大家參考,具體內(nèi)容如下
硬件環(huán)境:
Win10 64位
軟件環(huán)境:
Python版本:2.7.3
IDE:JetBrains PyCharm 2016.3.2
Python庫(kù):
1.1) opencv-python(3.2.0.6)
搭建過(guò)程:
OpenCV Python庫(kù):
1. PyCharm的插件源中選擇opencv-python(3.2.0.6)庫(kù)安裝
題外話:Python入門Tips
PS1:如何安裝whl文件
1.先安裝PIP
2.CMD命令進(jìn)入D:\Python27\Scripts里面后再執(zhí)行PIP命令安裝pip install wheel
如果提示'pip'不是內(nèi)部或外部命令,也不是可運(yùn)行的程序或批處理文件:
①將python安裝目錄下的scripts目錄(例如D:\Python27\Scripts)添加到系統(tǒng)環(huán)境變量path里,注意前加分號(hào)。再執(zhí)行該命令
pip install wheel
②在cmd下進(jìn)入到D:\Python27\Scripts目錄下執(zhí)行該命令
pip install wheel
3.把文件最好放在\Script文件夾里面再pip install xxxx.whl
4.注意whl文件名不能改 必須一模一樣和原名
PS2:到哪找.whl文件?
相關(guān)代碼:
import cv2 import numpy as np cv2.namedWindow("test") # Create a window cap = cv2.VideoCapture(0) #Open camera one success, frame = cap.read() #Read one frame print("Camera open operation is: ", success); color = (255,0,0) #Config the color classfier = 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\haarcascades while 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)]: break cv2.destroyWindow("test")
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python基于opencv實(shí)現(xiàn)的人臉識(shí)別(適合初學(xué)者)
- python opencv人臉識(shí)別考勤系統(tǒng)的完整源碼
- python實(shí)現(xiàn)圖片,視頻人臉識(shí)別(opencv版)
- Python基于Opencv來(lái)快速實(shí)現(xiàn)人臉識(shí)別過(guò)程詳解(完整版)
- Python opencv實(shí)現(xiàn)人眼/人臉識(shí)別以及實(shí)時(shí)打碼處理
- Python基于OpenCV庫(kù)Adaboost實(shí)現(xiàn)人臉識(shí)別功能詳解
- python opencv3實(shí)現(xiàn)人臉識(shí)別(windows)
- 基于python3 OpenCV3實(shí)現(xiàn)靜態(tài)圖片人臉識(shí)別
- 使用 Python 和 OpenCV 實(shí)現(xiàn)實(shí)時(shí)人臉識(shí)別功能
相關(guān)文章
Python如何根據(jù)照片修改時(shí)間重命名并排序詳解
重命名操作是我們開(kāi)發(fā)中經(jīng)常遇到的一個(gè)需求,下面這篇文章主要給大家介紹了關(guān)于Python如何根據(jù)照片修改時(shí)間重命名并排序的相關(guān)資料,需要的朋友可以參考下2021-05-05python xmind 包使用詳解(其中解決導(dǎo)出的xmind文件 xmind8可以打開(kāi) xmind2020及之后版本打
xmind8 可以打開(kāi)xmind2020 報(bào)錯(cuò),如何解決這個(gè)問(wèn)題呢?下面小編給大家?guī)?lái)了python xmind 包使用(其中解決導(dǎo)出的xmind文件 xmind8可以打開(kāi) xmind2020及之后版本打開(kāi)報(bào)錯(cuò)問(wèn)題),感興趣的朋友一起看看吧2021-10-10python shell根據(jù)ip獲取主機(jī)名代碼示例
這篇文章主要介紹了python shell根據(jù)ip獲取主機(jī)名代碼示例,涉及用socket模塊和shell中hostname命令獲取等相關(guān)內(nèi)容,具有一定參考價(jià)值,需要的朋友可以了解下。2017-11-11詳解Python虛擬機(jī)是如何實(shí)現(xiàn)閉包的
Python中的閉包是一個(gè)強(qiáng)大的概念,允許函數(shù)捕獲和訪問(wèn)其周圍的作用域,即使這些作用域在函數(shù)執(zhí)行完畢后也能被訪問(wèn),這篇文章將著重討論P(yáng)ython虛擬機(jī)是如何實(shí)現(xiàn)閉包的,文中有相關(guān)的代碼示例供大家參考,具有一定的參考價(jià)值,需要的朋友可以參考下2023-12-12django從請(qǐng)求到響應(yīng)的過(guò)程深入講解
這篇文章主要給大家介紹了關(guān)于django從請(qǐng)求到響應(yīng)的過(guò)程的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08Python調(diào)用edge-tts實(shí)現(xiàn)在線文字轉(zhuǎn)語(yǔ)音效果
edge-tts是一個(gè) Python 模塊,允許通過(guò)Python代碼或命令的方式使用 Microsoft Edge 的在線文本轉(zhuǎn)語(yǔ)音服務(wù),這篇文章主要介紹了Python調(diào)用edge-tts實(shí)現(xiàn)在線文字轉(zhuǎn)語(yǔ)音效果,需要的朋友可以參考下2024-03-03