具體內容,直接看注釋吧,該注釋的我都注釋掉了。
# coding:utf-8
import cv2
# 待檢測的路徑
imagepath = r'd://greenhat'
face_cascade = cv2.cascadeclassifier(r'd://greenhat//haarcascade_frontalface_default.xml')
# 讀取
image = cv2.imread(imagepath)
gray = cv2.cvtcolor(image,cv2.color_bgr2gray)
# 填上綠帽子的位址
gh = cv2.imread(r'd://greenhat')
# 探測中的人臉
faces = face_cascade.detectmultiscale(
gray,
scalefactor = 1.022,#需》1,越小的話,檢測越寬泛,調整引數用
minneighbors = 5,
minsize = (20,20),#最小腦袋
)print("發現個人臉!".format(len(faces)))
for(x,y,w,h) in faces:
gh2 = cv2.resize(gh, (0,0), fx=0.3, fy=0.3)
sp = gh2.shape
for x1 in range(0,sp[0]):
for y1 in range(0,sp[1]):
# 去掉白顏色,只留下綠顏色,直接特判rgb
if gh2[x1,y1,1]-gh2[x1,y1,0] > 60 and gh2[x1,y1,2] - gh2[x1,y1,1] > 7:
image[y-w+x1+12,x+y1]=gh2[x1,y1]
# 利用自帶的畫綠帽子
#cv2.rectangle(image,(x,y-3),(x+w,y),(0,255,0),thickness=3)
#cv2.circle(image,(x+int(w/2),y-4),2,(0,255,0),10)
cv2.imshow("find faces!",image)
cv2.waitkey(0)
opencv python 自動綠帽機
具體內容,直接看注釋吧,該注釋的我都注釋掉了。coding utf 8 import cv2 待檢測的路徑 imagepath r d greenhat face cascade cv2.cascadeclassifier r d greenhat haarcascade frontalface d...
OpenCV Python模糊處理
import cv2 as cv import numpy as np 均值模糊 defblur demo img dst cv.blur img,5 5 cv.imshow blur image dst import cv2 as cv import numpy as np 中值模糊 defmed...
OpenCV Python 人臉檢測
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!例項總結 下午的時候,配好了opencv的python環境,opencv的python環境搭建。於是迫不及待的想體驗一下opencv的人臉識別,如下文。haar like百科釋義。通俗的來講,就是作為人臉特徵即可。haar特徵值反映了影象的灰度變化...