我正在尝试在 google colab 中进行面部识别项目,但出现此错误:

问题描述 投票:0回答:0

OpenCV(4.7.0) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

我使用的代码如下:-

文件夹='已知面孔/' 数据库 = {}

listdir(文件夹)中的文件名:

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 = Img.fromarray(gbr)                  # konversi dari OpenCV ke PIL
gbr_array = asarray(gbr)

face = gbr_array[y1:y2, x1:x2]                        

face = Img.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.embeddings(face)

database[os.path.splitext(filename)[0]]=signature
python opencv face-recognition codecvt facenet
© www.soinside.com 2019 - 2024. All rights reserved.