안녕하세요 모든 수석 프로그래머에게! eigenfaces 이미지 훈련 부분에 오류가 있습니다.Eigenfaces 교육 이미지 픽셀 크기 오류
오류 : OpenCV 오류 : 지원되지 않는 형식 또는 형식 조합 (모든 입력 샘플 (교육 이미지)은 동일한 크기 여야합니다! 예상되는 27889 픽셀이지만 27556 픽셀입니다.) cv :: face :: Eigenfaces :: train, 파일 C : \ projects \ opencv-python \ opencv_contrib \ modules \ face \ src \ eigen_faces.cpp, 줄 68
내 사진이 동일한 크기가 아니란 것을 의미합니다. 카메라에서 사진을 캡처 할 때 cv2.rezise()를 시도하지만 여전히 작동하지 않습니다.
여기 내 캡처 코드 :
import cv2
cam = cv2.VideoCapture(0)
detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
Id = input('enter your id: ')
sampleNum = 0
while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
sampleNum = sampleNum+1
cv2.imwrite("dataSet/user."+Id+'.'+str(sampleNum)+".jpg",cv2.resize
(gray[y:y+h,x:x+w],(70,70)))
cv2.imshow('frame',img)
if cv2.waitKey(100) & 0xFF == ord('q'):#waitKey is for delay in video capture
break
elif sampleNum >= 50:#how many picture capture?
break
cam.release()
cv2.destroyAllWindows()
여기에 교육의 일부입니다
import cv2,os
import numpy as np
recognizer = cv2.face.EigenFaceRecognizer_create()
detector= cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
def getImagesAndLabels(path):
imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
faceSamples=[]
Ids=[]
for imagePath in imagePaths:
pilImage = Image.open(imagePath).convert('L')
imageNp = np.array(pilImage,'uint8')
Id = int(os.path.split(imagePath)[-1].split(".")[1])
faces = detector.detectMultiScale(imageNp)
for (x,y,w,h) in faces:
faceSamples.append(imageNp[y:y+h,x:x+w])
Ids.append(Id)
return faceSamples,Ids
faces,Ids = getImagesAndLabels('dataSet')
recognizer.train(faces, np.array(Ids))
recognizer.write('trainner/trainnerEi.yml')
PS. 나는 감사 LBPHFaceRecognizer 에서이 코드를 적용 * 3
왜 크기가 변경된 얼굴 이미지가 감지되면 다시 'getImagesAndLabels'을 사용합니까? – Silencer
진실은 내가 모른다. 나는 LBPHFaceRecognizer를 위해 youtube에서이 코드를 얻는다. 노인 도와주세요. – LotOfQuestion