你好我想运行一个面部识别教练,着眼于脸部的JPG图片文件夹
import os # importing the OS for path
import cv2 # importing the OpenCV library
import numpy as np # importing Numpy library
from PIL import Image # importing Image library
EigenFace = cv2.face.EigenFaceRecognizer_create(15) # creating EIGEN FACE RECOGNISER
FisherFace = cv2.face.FisherFaceRecognizer_create(2) # Create FISHER FACE RECOGNISER
LBPHFace = cv2.face.LBPHFaceRecognizer_create(1, 1, 7,7) # Create LBPH FACE RECOGNISER
path = 'dataSet' # path to the photos
def getImageWithID (path):
imagePaths = [os.path.join(path, f) for f in os.listdir(path)]
FaceList = []
IDs = []
for imagePath in imagePaths:
faceImage = Image.open(imagePath).convert('L') # Open image and convert to gray
faceImage = faceImage.resize((110,110)) # resize the image so the EIGEN recogniser can be trained
faceNP = np.array(faceImage, 'uint8') # convert the image to Numpy array
ID = int(os.path.split(imagePath)[-1].split('.')[1]) # Retreave the ID of the array
FaceList.append(faceNP) # Append the Numpy Array to the list
IDs.append(ID) # Append the ID to the IDs list
cv2.imshow('Training Set', faceNP) # Show the images in the list
cv2.waitKey(1)
return np.array(IDs), FaceList # The IDs are converted in to a Numpy array
IDs, FaceList = getImageWithID(path)
这反过来又返回错误
Traceback (most recent call last):
File "/Users/jef/PycharmProjects/testProject/Python/Trainer_All.py", line 28, in <module>
IDs, FaceList = getImageWithID(path)
File "/Users/jef/PycharmProjects/testProject/Python/Trainer_All.py", line 19, in getImageWithID
faceImage = Image.open(imagePath).convert('L') # Open image and convert to gray
File "/Users/jef/venv1/lib/python3.6/site-packages/PIL/Image.py", line 2452, in open
% (filename if filename else fp))
OSError: cannot identify image file 'dataSet/.DS_Store'
该文件夹中的数据集存在,我在我的Mac上运行的代码,以及最近的枕头,numpy的和CV2的版本,我GOOGLE了OSERROR但没有太多上前帮助这个特殊的问题。 有任何想法吗?