【发布时间】:2020-07-29 06:07:06
【问题描述】:
我目前正在学习使用 CNN 等进行图像检测。我发现了一篇很好的文章 here,它解释了使用 OpenCV 进行人脸检测的步骤。我遵循了每一个步骤。但是在尝试测试单个示例图像时,我真的被困了几个小时。下面是我在google Colab中使用的代码:
import cv2
import matplotlib.pyplot as plt
import dlib
import os
from imutils import face_utils
font = cv2.FONT_HERSHEY_SIMPLEX
cascPath=r'C:\Users\randomUser\Desktop\haarcascade_frontalface_default.xml'
eyePath = r'C:\Users\randomUser\Desktop\haarcascade_eye.xml'
smilePath = r'C:\Users\randomUser\Desktop\haarcascade_smile.xml'
faceCascade = cv2.CascadeClassifier(cascPath)
eyeCascade = cv2.CascadeClassifier(eyePath)
smileCascade = cv2.CascadeClassifier(smilePath)
# even if I use the below path, I am still getting the error.
path = r'C:\Users\randomUser\Desktop\imagedata.jpeg'
gray = cv2.imread('imagedata.jpeg')
plt.figure(figsize=(12,8))
plt.imshow(gray, cmap='gray')
plt.show()
我已经在我的目录位置下载了上面提到的所有默认文件以及测试图像imagedata
但是,当我运行前几个步骤时,我收到以下错误:(
我尝试过提供物理路径,但我不明白我错过了什么。
我浏览了不同的文章来解释错误的性质,但没有一篇有帮助,所以我想直接在这里问。
【问题讨论】:
-
嗨,我现在唯一想到的就是尝试从
plt.imshow()中删除cmap='gray'。我知道png和jpg图像处理整数数组作为TIFF格式的数据图像处理浮点数。 -
已经尝试过了...但不起作用:(
标签: python opencv artificial-intelligence conv-neural-network dlib