[英]OpenCV error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
[英]Receiving the error in Opencv: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
我目前正在使用 opencv 来识别屏幕上的个人,并且我已经创建了 model,但是我收到了这个错误:
error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
我搜索了许多论坛试图找到解决方案,但没有一个真正有帮助。 下面是卡片的一部分。
#Creates the video capture
camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
camera.set(3, 650) # Sets the camera width
camera.set(4, 480) # Sets the camera height
# Creates the window size of for the face
minW = 0.1 * camera.get(3)
minH = 0.1 * camera.get(4)
face_module = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
eye_module = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_eye.xml")
recogniser = cv2.face.LBPHFaceRecognizer_create() # This will rea the LBPH method
recogniser.read("/content/trainner/trainner.yml") # This is where the YML file will be read
def getStudent(ID):
connection = sqlite3.connect("FaceBase.db")
cmd = "SELECT * FROM Class WHERE ID=" + str(ID)
cursor = connection.execute(cmd)
student=None
for row in cursor:
student=row
connection.close()
return student
df = pd.read_csv("attendance.csv")
columnNames = ["ID", "Full Name", "Major", "Time"]
attendance = pd.DataFrame(columns=columnNames)
# This is where the detection logic will occur
while (True):
ret, frame = camera.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face = face_module.detectMultiScale(gray, 1.5, 5)
上面显示的代码中有两个问题,其中之一是:
recogniser.read("/content/trainner/trainner.yml")
这带来了关于 trainner 文件路径的错误,但要解决这个问题,您需要实现它的绝对路径。
recogniser.read(r"/Users/...../Documents/....../trainner/trainner.yml")
要修复 cv2Colour 问题,您需要在摄像头读取下方的代码中添加
if ret is True:
#print("frame.shape")
else:
continue
希望这可以帮助那里的人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.