1

Tengo este problema estoy tratando de mostrar por pantalla reconocimiento de rostro dentro de una interfaz grafica con pyqt.

código:

import sys
import os
import cv2
import numpy as np
from PyQt4 import QtGui, QtCore, Qt
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ui_login_Opencv import Ui_MainWindow


class Video():

    def __init__(self,capture):
    cascPath = "Classifiers/haarcascade_frontalface_default.xml"
    self.face_cascade = cv2.CascadeClassifier(cascPath)
    self.face_dir = 'face_data'
    self.model = cv2.createFisherFaceRecognizer()
    self.face_names = []
    self.capture = capture
    self.currentFrame=np.array([])

    def load_trained_data(self):
        names = {}
        key = 0
        for (subdirs, dirs, files) in os.walk(self.face_dir):
            for subdir in dirs:
                names[key] = subdir
                key += 1
        self.names = names 
        self.model.load('Classifiers/fisher_trained_data.xml')



    def captureNextFrame(self):
        """                           
        capture frame and reverse RBG BGR and return opencv image                                      
        """

        ret, readFrame=self.capture.read()
        if(ret==True):
            self.currentFrame=cv2.cvtColor(readFrame,cv2.COLOR_BGR2RGB)
            inImg = np.array(readFrame)
            self.face_names = self.process_image(inImg)

    def process_image(self, inImg, RESIZE_FACTOR=2):
        frame = cv2.flip(inImg,1)
        resized_width, resized_height = (112, 92)
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)        
        gray_resized = cv2.resize(gray, (gray.shape[1]/RESIZE_FACTOR, gray.shape[0]/RESIZE_FACTOR))        
        faces = self.face_cascade.detectMultiScale(
                gray_resized,
                scaleFactor=1.1,
                minNeighbors=5,
                minSize=(30, 30),
                flags=cv2.cv.CV_HAAR_SCALE_IMAGE
                )
        persons = []
        for i in range(len(faces)):
            face_i = faces[i]
            x = face_i[0] * RESIZE_FACTOR
            y = face_i[1] * RESIZE_FACTOR
            w = face_i[2] * RESIZE_FACTOR
            h = face_i[3] * RESIZE_FACTOR
            face = gray[y:y+h, x:x+w]
            face_resized = cv2.resize(face, (resized_width, resized_height))
            confidence = self.model.predict(face_resized)
            if confidence[1]<300:
                person = self.names[confidence[0]]
                cv2.rectangle(frame, (x,y), (x+w, y+h), (255, 0, 0), 3)
                cv2.putText(frame, '%s - %.0f' % (person, confidence[1]), (x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))
            else:
                person = 'Unknown'
                cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 0, 255), 3)
                cv2.putText(frame, person, (x-10, y-10), cv2.FONT_HERSHEY_PLAIN,1,(0, 255, 0))
            persons.append(person)
        return (frame, persons)


    def convertFrame(self):
        """     converts frame to format suitable for QtGui            """
        try:
            height,width=self.currentFrame.shape[:2]
            img=QtGui.QImage(self.currentFrame,width,height,QtGui.QImage.Format_RGB888)
            img=QtGui.QPixmap.fromImage(img)
            self.previousFrame = self.currentFrame
            return img
        except:

            return None

class Gui(QtGui.QMainWindow):
    def __init__(self,parent=None):
    QtGui.QWidget.__init__(self,parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)
    self.video = Video(cv2.VideoCapture(0))
    self._timer = QtCore.QTimer(self)
    self._timer.timeout.connect(self.play)
    self._timer.start(27)
    self.update()


    def play(self):
        try:
            self.video.captureNextFrame()
            self.ui.videoFrame.setPixmap(self.video.convertFrame())
            self.ui.videoFrame.setScaledContents(True)
        except TypeError:
            print "No frame"
def main():
import sys, time
app = QtGui.QApplication(sys.argv)

# Create and display the splash screen
splash_pixmap = QPixmap('Imagenes/SplashScreem.png')
splash = QSplashScreen(splash_pixmap, Qt.WindowStaysOnTopHint)
splash.setMask(splash_pixmap.mask())
splash.show()
app.processEvents()

# Simulate something that takes time
time.sleep(2)

ex = Gui()
ex.show()
splash.finish(ex)
sys.exit(app.exec_())

if __name__ == '__main__':
main()

Aqui esta el error

introducir la descripción de la imagen aquí

    Traceback (most recent call last):
    File "C:\Python                  Opencv\VTMSRRegistroClienteOpencv\VTMSRRegistroClienteOpencv\Login_Opencv.py",       line 106, in play
  self.video.captureNextFrame()
  File "C:\Python Opencv\VTMSRRegistroClienteOpencv\VTMSRRegistroClienteOpencv\Login_Opencv.py", line 43, in captureNextFrame
 self.face_names = self.process_image(inImg)
 File "C:\Python Opencv\VTMSRRegistroClienteOpencv\VTMSRRegistroClienteOpencv\Login_Opencv.py", line 68, in process_image
confidence = self.model.predict(face_resized)
cv2.error: ..\..\..\..\opencv\modules\contrib\src\facerec.cpp:620: error:  (-5) This Fisherfaces model is not computed yet. Did you call  Fisherfaces::train? in     function cv::Fisherfaces::predict

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.