OpenCV(4.4.0) 错误: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'

Posted

技术标签:

【中文标题】OpenCV(4.4.0) 错误: (-215:Assertion failed) isMap() in function \'cv::FileNode::operator []\'【英文标题】:OpenCV(4.4.0) error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'OpenCV(4.4.0) 错误: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []' 【发布时间】:2020-11-26 13:47:48 【问题描述】:

我正在编写面部检测器脚本。 我设法通过从网络摄像头捕获图像,将它们保存到本地目录并将数据存储在我的本地数据库中来创建数据集。 但是当我尝试运行主应用程序来识别面孔并将它们显示给我时,我收到以下错误:

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\1\pip-req-build-6lylwdcz\opencv\modules\core\src\persistence.cpp:2089: error: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'

关于造成这种情况的任何想法?我正在运行的文件如下。

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

【问题讨论】:

【参考方案1】:

我最终找到了答案。

这是由于:

cv2.face.LBPHFaceRecognizer_create()

这是对 OpenCV 的正确调用。但很可能,您没有 face 子模块,因为您的 cv2.pyd 是在没有 opencv_contrib 的情况下构建的

有几个选项:

使用 opencv_contrib 从 src 重建,为此您需要一个 c++ 编译器和 CMake。 回退到opencv2.4并使用 cv2.createLBPHFaceRecognizer()

一旦完成并再次训练数据,它将正常工作

【讨论】:

以上是关于OpenCV(4.4.0) 错误: (-215:Assertion failed) isMap() in function 'cv::FileNode::operator []'的主要内容,如果未能解决你的问题,请参考以下文章

imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘

imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘

imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘(代码片段

Linux 安装 OpenCV (C++)

TY科技的工程配置(VS2017 & Opencv4.0.0)

linux ubuntu16.04 编译opencv教程(没编过,有时间再弄,推流不用opencv也行的)