New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cv2.error: OpenCV(4.1.0) /io/opencv/modules/core/src/persistence.cpp:2046: error: (-215:Assertion failed) isMap() in function 'operator[]' #14908
Comments
I experience the same error with: opencv-python==4.1.0.25 when running
|
Same error with self compiled opencv 4.1.1 and opencv-contrib 4.1.1 The error: (cv) pi@rpi401b:~/Documents/Python Projects/opencv/facelock $ python3 detector_webcam.py
detector_webcam.py:23: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setup(relayPin, GPIO.OUT)
Traceback (most recent call last):
File "detector_webcam.py", line 44, in <module>
recognizer.read(fname) # load() for createLBPHFaceRecognizer()
cv2.error: OpenCV(4.1.1) /home/pi/opencv/modules/core/src/persistence.cpp:2046: error: (-215:Assertion failed) isMap() in function 'operator[]' The code I ran: import cv2
import os
import sqlite3
import RPi.GPIO as GPIO
import time
# Connect SQLite3 database
conn = sqlite3.connect('database.db')
db = conn.cursor()
# Assign the training data file
fname = "recognizer/trainingData.yml"
if not os.path.isfile(fname):
print("Please train the data first")
exit(0)
# Setup GPIO for unlock LED
relayPin = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(relayPin, GPIO.OUT)
GPIO.output(relayPin, 0)
lastDetectedAt = 0
detectInterval = 5
lastUnlockedAt = 0
unlockDuration = 5
# Font used for display
font = cv2.FONT_HERSHEY_SIMPLEX
# Connect to video source
vSource = 0 # first USB webcam
vStream = cv2.VideoCapture(vSource)
# Setup Classifier for detect face
faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
# Setup LBPH recognizer for face recognition
recognizer = cv2.face.LBPHFaceRecognizer_create()
# Load training data
recognizer.read(fname)
while vStream.isOpened():
# Turn off unlock LED when timeout
if time.time() - lastUnlockedAt > unlockDuration:
GPIO.output(relayPin, 0)
ok, frame = vStream.read() # Read frame
if not ok: break
timeElapsed = time.time() - lastDetectedAt
if timeElapsed > 1./detectInterval:
lastDetectedAt = time.time()
# Detect face
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, scaleFactor = 1.1, minNeighbors = 2)
for (x, y, w, h) in faces:
# Try to recognize the face a
roiGray = gray[y:y+h, x:x+w]
id_, conf = recognizer.predict(roiGray)
print(id_, conf)
# If recognized face has enough confident (<= 70),
# retrieve the user name from database,
# draw a rectangle around the face,
# print the name of the user and
# light up the unlock LED for 5 secord
if conf <= 70:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# retrieve user name from database
db.execute("SELECT `name` FROM `users` WHERE `id` = (?);", (id_,))
result = db.fetchall()
name = result[0][0]
GPIO.output(relayPin, 1) # Unlock
lastUnlockedAt = time.time()
print("[Unlock] " + str(id_) + ":" + name + " (" + str(conf) + ")")
cv2.putText(frame, name, (x+2,y+h-5), font, 1, (150,255,0), 2)
else:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2)
GPIO.output(relayPin, 0) # Lock the door if not enough confident
cv2.imshow("Face Recognizer", frame)
# Press ESC to quit the program
key = cv2.waitKey(1) & 0xff
if key == 27 or key == ord('q'):
break
# Clean up
vStream.release()
conn.close()
cv2.destroyAllWindows()
GPIO.cleanup()
print("END") |
Same error for me: Ubuntu 18.04.3 LTS When using: recognizer = cv2.face.LBPHFaceRecognizer_create() |
Finally I resolve the problem after retrain. |
same for me! |
how you can solve this problem? @mickey9801 |
Just retrain and it will work. @royalluckyboy |
Retrain with the dataset and generate a new xml file. @royalluckyboy |
How to retrain it to generate the xml file? @mickey9801 |
Perdón, como hago para Re entrenar, soy nuevo en esto. Pueden ayudarme? |
i got this error
The text was updated successfully, but these errors were encountered: