【问题标题】: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:错误:(-215:断言失败)!_src.empty()在函数'cvtColor '
【发布时间】:2021-11-28 06:36:51
【问题描述】:

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

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

查看已安装包的版本,附文件,请关注。

【问题讨论】:

标签: python deep-learning computer-vision face-detection opencv-contrib


【解决方案1】:

问题解决了!

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    • 2015-09-26
    • 2022-07-18
    • 2022-01-10
    • 2020-08-11
    • 2014-01-16
    相关资源
    最近更新 更多