OpenCV(4.4.0) error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
OpenCV(4.4.0) error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
我正在研究面部检测器脚本。
我设法通过从网络摄像头捕获图像、将它们保存到本地目录并将数据存储在我的本地数据库中来创建数据集。
但是当我尝试 运行 主应用程序识别面孔并将它们显示给我时,我收到以下错误:
runfile('C:/Users/JeanCamargo/Google Drive/python/college/face recognition/face recognition.py', wdir='C:/Users/JeanCamargo/Google Drive/python/college/face recognition')
Reloaded modules: dbconnect
Traceback (most recent call last):
File "C:\Users\JeanCamargo\Google Drive\python\college\face recognition\face recognition.py", line 27, in <module>
recognizer.read(r"trainner\trainningData.yml")
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\pip-req-build-6lylwdcz\opencv\modules\core\src\persistence.cpp:2089: error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
对造成这种情况的原因有什么想法吗?我 运行ning 的文件如下。
import cv2
import sys
import numpy as np
import pickle
from PIL import Image
from dbconnect import mySQL
import os
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read(r"trainner\trainningData.yml")
cascPath = r"Classifiers\haarcascade_frontalface_alt.XML"
faceCascade = cv2.CascadeClassifier(cascPath)
#Id = 0
path = 'dataSet'
def getProfile(Id):
query = "SELECT * FROM people WHERE ID ="+ Id
cursor = query.fetchall()
mySQL.close()
profile = None
for row in cursor:
profile = row
return profile
video_capture = cv2.VideoCapture(1)
font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1,.5,0,2,1)
profiles={}
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
if ret==False:
continue
frame = cv2.flip(frame, 1) # Flip image
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in faces:
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
profile = getProfile(id)
if (profile !=None):
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[1],(x,y+h+30),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[2],(x,y+h+60),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[3],(x,y+h+90),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[4],(x,y+h+120),255)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我终于找到了答案。
这是由于:
cv2.face.LBPHFaceRecognizer_create()
这是对 OpenCV 的正确调用。但很可能你没有 face 子模块,因为你的 cv2.pyd 是在没有 opencv_contrib
的情况下构建的
有几个选项:
使用 opencv_contrib 从 src 重建,为此你需要一个 c++ 编译器和 CMake。
退回到 opencv2.4 并使用
cv2.createLBPHFaceRecognizer()
一旦完成并再次训练数据,它将正常工作
我正在研究面部检测器脚本。 我设法通过从网络摄像头捕获图像、将它们保存到本地目录并将数据存储在我的本地数据库中来创建数据集。 但是当我尝试 运行 主应用程序识别面孔并将它们显示给我时,我收到以下错误:
runfile('C:/Users/JeanCamargo/Google Drive/python/college/face recognition/face recognition.py', wdir='C:/Users/JeanCamargo/Google Drive/python/college/face recognition')
Reloaded modules: dbconnect
Traceback (most recent call last):
File "C:\Users\JeanCamargo\Google Drive\python\college\face recognition\face recognition.py", line 27, in <module>
recognizer.read(r"trainner\trainningData.yml")
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\pip-req-build-6lylwdcz\opencv\modules\core\src\persistence.cpp:2089: error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'
对造成这种情况的原因有什么想法吗?我 运行ning 的文件如下。
import cv2
import sys
import numpy as np
import pickle
from PIL import Image
from dbconnect import mySQL
import os
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read(r"trainner\trainningData.yml")
cascPath = r"Classifiers\haarcascade_frontalface_alt.XML"
faceCascade = cv2.CascadeClassifier(cascPath)
#Id = 0
path = 'dataSet'
def getProfile(Id):
query = "SELECT * FROM people WHERE ID ="+ Id
cursor = query.fetchall()
mySQL.close()
profile = None
for row in cursor:
profile = row
return profile
video_capture = cv2.VideoCapture(1)
font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1,.5,0,2,1)
profiles={}
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
if ret==False:
continue
frame = cv2.flip(frame, 1) # Flip image
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in faces:
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
profile = getProfile(id)
if (profile !=None):
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[1],(x,y+h+30),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[2],(x,y+h+60),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[3],(x,y+h+90),255)
cv2.cv.PutText(cv2.cv.fromarray(frame),profile[4],(x,y+h+120),255)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
我终于找到了答案。
这是由于:
cv2.face.LBPHFaceRecognizer_create()
这是对 OpenCV 的正确调用。但很可能你没有 face 子模块,因为你的 cv2.pyd 是在没有 opencv_contrib
的情况下构建的有几个选项:
使用 opencv_contrib 从 src 重建,为此你需要一个 c++ 编译器和 CMake。
退回到 opencv2.4 并使用
cv2.createLBPHFaceRecognizer()
一旦完成并再次训练数据,它将正常工作