講者:ㄇㄒ
日期:2020/12/27
臉部位置標示
$ pip install opencv-python上次有安裝過的就可以不用裝了~
不熟悉安裝位置的話下面指令幫助您
$ pip show opencv-python把整個路徑記下來
But 不要太刁難他找側臉的
import cv2
face_cascade = cv2.CascadeClassifier('檔案路徑')img = cv2.imread('圖片路徑')
faces = face_cascade.detectMultiScale(img, scaleFactor=1.05, minNeighbors=3, minSize=(10, 10))for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255), 2)cv2.rectangle(圖片, 起始座標, 結束座標,
顏色(B,G,R), 粗細)
cv2.imshow('結果顯示', img)
cv2.waitKey(0)import cv2
face_cascade = cv2.CascadeClassifier('特徵檔路徑')
img = cv2.imread('圖片路徑')
faces = face_cascade.detectMultiScale(img, scaleFactor=1.08, minNeighbors=5, minSize=(15, 15))
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255), 2)
cv2.imshow('img', img)
cv2.waitKey(0)Text
from PIL import Image
count = 1
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 255), 2) # (Blue,Green,Red)
filename = "find" + str(count) + ".jpg"
i1 = Image.open('原始圖片名稱')
i2 = i1.crop((x, y, x + w, y + h))
i3 = i2.resize((200, 200), Image.ANTIALIAS)
i3.save(filename)
count += 1import math, operator
from PIL import Image
from functools import reduce
# 以i1為基準比較
i1 = Image.open('圖片路徑')
i2 = Image.open('圖片路徑')
h1 = i1.histogram()
h2 = i2.histogram()
diff = math.sqrt(reduce(operator.add, list(map(lambda a,b: (a-b)**2, h1, h2)))/len(h1))
print(diff) # 數值越大差異越大非連貫程式