import cv2
import os
os.sys.path
from os import listdir
from PIL import Image
from numpy import asarray
from numpy import expand_dims
import pickle
folder="data_test_deteksi"
database = {}
for filename in listdir(folder):
path = folder + filename
gbr1 = cv2.imread(folder + filename)
wajah = HaarCascade.detectMultiScale(gbr1,1.1,4)
if len(wajah)>0:
x1, y1, width, height = wajah[0]
else:
x1, y1, width, height = 1, 1, 10, 10
x1, y1 = abs(x1), abs(y1)
x2, y2 = x1 + width, y1 + height
gbr = cv2.cvtColor(gbr1, cv2.COLOR_BGR2RGB)
gbr = Image.fromarray(gbr) # konversi dari OpenCV ke PIL
gbr_array = asarray(gbr)
face = gbr_array[y1:y2, x1:x2]
face = Image.fromarray(face)
face = face.resize((160,160))
face = asarray(face)
face = face.astype('float32')
mean, std = face.mean(), face.std()
face = (face - mean) / std
face = expand_dims(face, axis=0)
signature = MyFaceNet.predict(face)
database[os.path.splitext(filename)[0]]=signature
Why name 'HaarCascade' is not defined?
207 Views Asked by Luky Vianika Sari At
1
There is nothing named as
HaarCascade
in opencv, you need to usecv2.CascadeClassifier
. First downloadhaarcascade
xml file and then pass the path of that file like thisface_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')