Getting this Error in predict function

asked 2017-11-23 08:29:01 -0600

updated 2017-11-23 08:34:55 -0600

berak gravatar image

OpenCV Error: Unspecified error (This Eigenfaces model is not computed yet. Did you call Eigenfaces::train?) in predict, file /home/pi/opencv_contrib-3.3.0/modules/face/src/eigen_faces.cpp, line 113 Traceback (most recent call last): File "box.py", line 42, in <module> label, confidence = model.predict(crop) cv2.error: /home/pi/opencv_contrib-3.3.0/modules/face/src/eigen_faces.cpp:113: error: (-2) This Eigenfaces model is not computed yet. Did you call Eigenfaces::train? in function predict

THE CODE IN WHICH THERE IS ERROR IS GIVEN BELOW

import cv2

import config
import face
import hardware


if __name__ == '__main__':
    # Load training data into model
    print 'Loading training data...'
    model = cv2.face.EigenFaceRecognizer_create()
    model.read(config.TRAINING_FILE)
    print 'Training data loaded!'
    # Initialize camer and box.
    camera = config.get_camera()
    box = hardware.Box()
    # Move box to locked position.
    box.lock()
    print 'Running box...'
    print 'Press button to lock (if unlocked), or unlock if the correct face is detected.'
    print 'Press Ctrl-C to quit.'
    while True:
                print 'Button pressed, looking for face...'
                # Check for the positive face and unlock if found.
                image = camera.read()
                # Convert image to grayscale.
                image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
                # Get coordinates of single face in captured image.
                result = face.detect_single(image)
                if result is None:
                    print 'Could not detect single face!  Check the image in capture.pgm' \
                          ' to see what was captured and try again with only one face visible.'
                    continue
                x, y, w, h = result
                # Crop and resize image to face.
                crop = face.resize(face.crop(image, x, y, w, h))

                put=cv2.equalizeHist(crop)
                # Test face against model.
                label, confidence = model.predict(put)
                print 'Predicted {0} face with confidence {1} (lower is more confident).'.format(
                    'POSITIVE' if label == config.POSITIVE_LABEL else 'NEGATIVE', 
                    confidence)
                if label == config.POSITIVE_LABEL and confidence < config.POSITIVE_THRESHOLD:
                    print 'Recognized face!'
                    box.unlock()
                else:
                    print 'Did not recognize face!'
edit retag flag offensive close merge delete

Comments

  • did you use save() or write() , to save it ?

  • can you show the 1st few lines of your saved model ?

(btw, if you're trying to authenticate a single person only, this is entirely the wrong tool. opencv's face recognition classes are for identification (find the closest from a database))

berak gravatar imageberak ( 2017-11-23 08:47:49 -0600 )edit

then which class should i use .. this code is taken from learn adafruit.com

Sarthak gravatar imageSarthak ( 2017-11-23 09:19:16 -0600 )edit

cv2.imwrite(MEAN_FILE, normalize(mean, 0, 255, dtype=np.uint8)) i used this to create mean.png postive.png and negative.png and training.xml also

Sarthak gravatar imageSarthak ( 2017-11-23 09:21:37 -0600 )edit

mode.save(config.TRAININGFILE) to save the model

Sarthak gravatar imageSarthak ( 2017-11-23 09:23:48 -0600 )edit

if you use save(), you have to use load() to get it back (not implemented in 3.3.0, only later)

please re-train your model, and use write() to store it . then read() to retrieve it.

and please believe me on the authentification !

berak gravatar imageberak ( 2017-11-23 09:44:37 -0600 )edit

OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in resize, file /home/pi/opencv-3.3.0/modules/imgproc/src/imgwarp.cpp, line 3483 Traceback (most recent call last): File "train.py", line 65, in <module> faces.append(prepare_image(filename)) File "train.py", line 38, in prepare_image return face.resize(cv2.imread(filename, cv2.IMREAD_GRAYSCALE)) File "/home/pi/Desktop/pi-facerec-box-master/face.py", line 44, in resize interpolation=cv2.INTER_LANCZOS4) cv2.error: /home/pi/opencv-3.3.0/modules/imgproc/src/imgwarp.cpp:3483: error: (-215) ssize.width > 0 && ssize.height > 0 in function resize

Sarthak gravatar imageSarthak ( 2017-11-23 10:35:09 -0600 )edit

getting this error in train...

Sarthak gravatar imageSarthak ( 2017-11-23 10:35:34 -0600 )edit

the image you read was probably invalid. please add a check after imread()

berak gravatar imageberak ( 2017-11-23 10:41:05 -0600 )edit

so i take the image again?

Sarthak gravatar imageSarthak ( 2017-11-23 10:53:56 -0600 )edit

you have to check, if what you were trying to read in wasactually an image, not a readme.txt or thumbs.db

berak gravatar imageberak ( 2017-11-23 10:57:11 -0600 )edit