Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于Fisher-Faces-OpenCV-Python的人脸识别_Python_Opencv - Fatal编程技术网

基于Fisher-Faces-OpenCV-Python的人脸识别

基于Fisher-Faces-OpenCV-Python的人脸识别,python,opencv,Python,Opencv,我使用OpenCV python使用以下代码进行人脸识别。虽然我已经调整了图像的大小,但仍然会收到一个错误,因为应该调整图像的大小。如何解决 import cv2, os import numpy as np recognizer = cv2.createFisherFaceRecognizer() # Eigenface Recognizer def get_images_and_labels(path): image_paths = [os.path.join(path, f

我使用OpenCV python使用以下代码进行人脸识别。虽然我已经调整了图像的大小,但仍然会收到一个错误,因为应该调整图像的大小。如何解决

import cv2, os
import numpy as np



recognizer = cv2.createFisherFaceRecognizer() # Eigenface Recognizer

def get_images_and_labels(path):

   image_paths = [os.path.join(path, f) for f in os.listdir(path)]

   images = []
   labels = []

   for image_path in image_paths:

      image_pil = cv2.imread(image_path,0)

      image = np.array(image_pil, 'uint8')

      indx = os.path.split(image_path)[1].split(".")[0]

      images.append(image)
      labels.append(int(indx))

      cv2.imshow("Adding faces to traning set...", image_pil)
      cv2.waitKey(50)

 return images, labels


 path ='G:\Resizing\Fisher Faces\data'

 images, labels = get_images_and_labels(path)
 cv2.destroyAllWindows()

recognizer.train(images, np.array(labels))

print "The system has trained successfully."




cascPath = "G:\Resizing\lBPH\haarcascades\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascPath)

cap = cv2.VideoCapture(0)

while(True):

   ret, frame = cap.read()


   gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

   faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=10,
    minSize=(30, 30),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
      )

   for (x, y, w, h) in faces:
     cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

     cv2.imshow('frame',frame)

   for (x, y, w, h) in faces:
      resized = cv2.resize(gray[y: y + h, x: x + w], (200,200), interpolation = cv2.INTER_AREA)
      img=cv2.equalizeHist(resized)

      nbr_predicted, conf = recognizer.predict(img)

      print "Index {} is Correctly Recognized with confidence {}".format(nbr_predicted, conf)



cap.release()
cv2.destroyAllWindows()
错误是

"OpenCV Error: Bad argument (Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 1228800 elements, but got 40000.) 
      in cv::Fisherfaces::predict, file ..\..\..\..\opencv\modules\contrib\src\facerec.cpp, line 623
Traceback (most recent call last):
  File "G:/Resizing/Fisher Faces/FisherFaces.py", line 79, in <module>
    nbr_predicted, conf = recognizer.predict(img)
cv2.error: ..\..\..\..\opencv\modules\contrib\src\facerec.cpp:623: error: (-5) Wrong input image size. Reason: Training and Test images must be of equal size! Expected an image with 1228800 elements, but got 40000. in function cv::Fisherfaces::predict"
OpenCV错误:参数错误(输入图像大小错误。原因:训练图像和测试图像的大小必须相同!预期图像包含1228800个元素,但得到40000个。) 在cv::Fisherfaces::predict中,文件为..\..\opencv\modules\contrib\src\facerec.cpp,第623行 回溯(最近一次呼叫最后一次): 文件“G:/Resizing/Fisher Faces/FisherFaces.py”,第79行,在 nbr_预测,conf=recognizer.predict(img) cv2.error:..\..\..\..\opencv\modules\contrib\src\facerec.cpp:623:错误:(-5)输入图像大小错误。原因:训练图像和测试图像必须大小相同!预期图像包含1228800个元素,但得到40000个。在函数cv::Fisherfaces::predict中”
包含您收到的确切错误消息会有帮助,理想情况下是完整的堆栈回溯。通过添加错误消息来编辑代码似乎是不言自明的。有些图像看起来有不同的尺寸。但我正在用equal hist函数调整它们的大小。这不是给了图像相同的尺寸吗?代码缩进看起来不太正确。可能与使用
cap.read()
捕获的帧冲突?这将有助于包含您得到的确切错误消息,理想情况下是完整的堆栈回溯。通过添加错误消息来编辑代码似乎是不言自明的。有些图像看起来有不同的尺寸。但我正在用equal hist函数调整它们的大小。这不是给了图像相同的尺寸吗?代码缩进看起来不太正确。可能与使用
cap.read()
捕获的帧冲突?