【发布时间】:2019-05-29 22:19:01
【问题描述】:
我正在尝试构建一个模型,在该模型中它将读取给定文件夹中的所有图像并检测面部,裁剪并将裁剪的面部保存到新文件夹!
当我收到错误时,谁能帮我写代码:
cv2.imshow(str(img) , img)
TypeError: mat is not a numpy array, neither a scalar
代码:
import glob
import cv2
import sys
while 1 :
filename = input("Enter the file name in which images are present =")
for img in glob.glob(filename+'/*.*'):
#try :
var_img = cv2.imread(img)
cv2.imshow(str(img) , var_img)
def detect_face(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_cascade = cv2.CascadeClassifier('opencv-files/lbpcascade_frontalface.xml')
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5);
if (len(faces) == 0):
return None, None
(x, y, w, h) = faces[0]
return gray[y:y+w, x:x+h], faces[0]
cv2.imshow(str(img) , img)
cv2.waitKey(0)
cv2.destroyAllWindows()
【问题讨论】:
标签: python opencv image-processing mat