繁体   English   中英

OpenCV(4.5.2) /tmp/pip-req-build-sl2aelck/opencv/modules/imgproc/src/color.cpp:182: error:(-215:Assertion failed)._src.empty() in function 'cvtColor '

[英]OpenCV(4.5.2) /tmp/pip-req-build-sl2aelck/opencv/modules/imgproc/src/color.cpp:182: error:(-215:Assertion failed) !_src.empty() in function 'cvtColor'

我尝试使用计算机视觉技术通过人脸识别制作考勤系统。

Python Version: 3.8.10

代码如下,

import cv2
import numpy as np
import face_recognition
import os

path = 'attendanceImages'
images = []
classNames = []
myList = os.listdir(path)
print(myList)
for  cl in myList:
    curImg = cv2.imread(f"{path} / {cl}")
    images.append(curImg)
    classNames.append(os.path.splitext(cl)[0])
print(classNames)

def findEncodings(images):
    encodeList = []
    for img in images:
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        encode = face_recognition.face_encodings(img)[0]
        encodeList.append(encode)
    return  encodeList

encodeListKnown = findEncodings(images)
print(len(encodeListKnown))  ##--> It would be printed the length of dataset 

注意: - 在print(len(encodeListKnown))打印后,它会显示长度,但由于错误,它失败了

下面给出了面临的错误

Traceback (most recent call last):
  File "/home/imdadul/PycharmProjects/faceVerification/AttendanceViaFace.py", line 25, in <module>
    encodeListKnown = findEncodings(images)
  File "/home/imdadul/PycharmProjects/faceVerification/AttendanceViaFace.py", line 20, in findEncodings
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.5.2) /tmp/pip-req-build-sl2aelck/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

['sohelRana.jpg', 'apurbo.jpg', 'RamCharan.jpg', 'ananyaPanday.jpg', 'imdadulHaque.jpg']
['sohelRana', 'apurbo', 'RamCharan', 'ananyaPanday', 'imdadulHaque']

Process finished with exit code 1

已安装包的版本检查附在附件中,请关注。 在此处输入图像描述

问题已经解决了!

我在curImg = cv2.imread(f"{path}/{cl}")这一行出错了。 我应该删除/前后的空格。 就是这样。 实际上,它没有找到正确的位置,现在已经解决了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM