【发布时间】:2021-07-12 22:04:50
【问题描述】:
我目前正在使用 opencv 来识别屏幕上的个人,并且我已经创建了一个模型,但是我收到了这个错误:
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)
【问题讨论】:
-
能否检查
ret是否为真,并打印frame.shape? -
@Burak 感谢您的回答!我已经更新了问题的答案
标签: python python-3.x opencv machine-learning