首页 > 解决方案 > 错误:我无法将我的图像从 bgr 转换为 rgb:TypeError: Expected Ptr对于参数“src”

问题描述

#error: 我无法将我的图像从 bgr 转换为 rgb

images = []
path = 'E:\subjects\AI\Face-Mask-Detection-master\without-mask-detections'
listimages=os.listdir(path)
encode_list = []

for img in listimages:
        images.append(img)
        img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
        encode = face_recognition.face_encodings(img)
        encode_list.append(encode)

print(images)
#encodeListKnown= find_encoding(images)
#print(len(encodeListKnown))

标签: pythonopencvartificial-intelligence

解决方案


您使用的文件名 (img) 不包含完整路径,无法打开。此外,您的代码不会打开图像文件。您应该构建完整路径并使用以下命令打开它:

for file in listimages:
    img = cv2.imread(os.path.join(path, file))
    images.append(img)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    encode = face_recognition.face_encodings(img)
    encode_list.append(encode)

推荐阅读