import numpy as np
import face_recognition
import cv2
import os
path="C:/Users/HP/Desktop/face1/img/known/"
images=list()
classnames=[]
my_list=os.listdir(path)
for i in my_list:
currentim=cv2.imread(f'{path}{i}')
images.append(currentim)
classnames.append(os.path.splitext(i)[0])
def findenc(images):
encs=[]
for img in images :
img=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
encs.append(face_recognition.face_encodings(img)[0])
return encs
encs=findenc(images)
print("encoding has ended")
cap=cv2.VideoCapture(0)
while True:
success,img=cap.read()
imgsize=cv2.resize(img,(0,0),None,0.25,0.25)
imgsize=cv2.cvtColor(imgsize,cv2.COLOR_BGR2RGB)
faces=face_recognition.face_locations(imgsize)[0]
encodescurf=face_recognition.face_encodings(imgsize)[0]
for encode,faceloc in zip(encodescurf,faces):
matches=face_recognition.compare_faces(encs,encode)
facedis=face_recognition.face_distance(encs,encode)
当ı运行代码时ıget cv2.error:OpenCV(4.5.3)C:\Users\runneramin\AppData\Local\Temp\pip-req-build-sn\u xpupm\OpenCV\modules\imgproc\src\color.cpp:182:错误:(-215:断言失败)_函数“cv::cvtColor”中的src.empty()如何修复该错误
注:cv2版本为“4.5.3” 我使用visualstudio代码 它给出了第16行的错误
发生此错误的原因可能是图像加载不正确。检查cv2.imread或尝试:
正确检查图像的路径
Python中的
os.path.join()
方法在每个非空部分(最后一个路径组件除外)后面使用一个目录分隔符('/')连接各种路径组件。如果要联接的最后一个路径组件为空,则在末尾放置一个目录分隔符(“/”)相关问题 更多 >
编程相关推荐