python - 错误:我无法将我的图像从 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))
解决方案
您使用的文件名 (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)
推荐阅读
- appium - 运行 Appium-doctor 时出现错误
- caching - 轮询不工作时更新 Apollo 客户端 3 的缓存
- c++ - 如何在 C++11 中安全且可移植地创建和使用临时文件?
- java - 想要对应用程序进行编程以连接到蓝牙设备
- numeric - r 考试类型编号:答案 Inf
- html - Flexbox,盒子里面的盒子
- vue.js - 有条件地将事件侦听器和处理程序附加到 Vue 组件
- typescript - Jasmine/Typescript - 使用“this”变量
- lisp - 在常见的 lisp 中,您如何在未捕获错误的地方重新启动?
- python - 如何递归地遍历 2 个字典,并根据另一个修改原始字典?