Ask Your Question
0

FisherFaceRecognizer in Python, segment fault.

asked 2012-08-01 04:20:55 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

Hi, I am writing a small python script to learn cv2.fisherFaceRecognizer in python, based on latest OpenCV source code. And I write the code based on the code of http://answers.opencv.org/question/253/broken-python-bindings-with/?answer=255#post-id-255, which is for eigenFaceRecognizer.

I just modified below code from eigenFaceRecognizer to fisherFaceRecognizer, then when I run the script it is crashed by segment fault.

model = cv2.createEigenFaceRecognizer()----> changed to cv2.createFisherFaceRecognizer()
model.train(np.asarray(X), np.asarray(y))

Is there anyone that met the same problem? Any solution?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2012-08-01 13:21:02 -0600

updated 2012-08-11 16:14:12 -0600

OpenCV: Fisherfaces with the OpenCV Python bindings

So! I've tried it and it works for me. I have adapted the Eigenfaces sample from my post to the Fisherfaces algorithm and it works as expected. See... In the post at:

I wrote, that it's fixed in trunk. So this fix only applies if you have built a recent OpenCV (after I've commited the patch of course). You say your code is based on the sample, so what does your code look like? Please also let us know, which version of OpenCV you are using. Operating System? 32/64 bit? Which data are you feeding into?

In the following I show the code and the results, so you see it works for me. The images are the Yale Facedatabase A, which I preprocessed to be aligned at the eyes. A copy of the dataset can be obtained from:

facerec_fisherfaces.py

#!/usr/bin/env python
# Software License Agreement (BSD License)
#
# Copyright (c) 2012, Philipp Wagner <bytefish[at]gmx[dot]de>.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of the author nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.


import os
import sys
import cv2
import numpy as np

def normalize(X, low, high, dtype=None):
    """Normalizes a given array in X to a value between low and high."""
    X = np.asarray(X)
    minX, maxX = np.min(X), np.max(X)
    # normalize to [0...1].    
    X = X - float(minX)
    X = X / float((maxX - minX))
    # scale to [low...high].
    X = X * (high-low)
    X = X + low
    if dtype is None:
        return np.asarray(X)
    return np.asarray(X, dtype=dtype)


def read_images(path, sz=None):
    """Reads the images in a given folder, resizes images on the fly if size ...
(more)
edit flag offensive delete link more

Comments

[To Philipp] Thank you so much for your detail answer. I've tried again but failed again. So here let me repeat my steps.

  1. I am using Ubuntu linux 11.04, 64bit version
  2. my python version is: python 2.7.1+
  3. I git cloned the latest opencv code, see below:

Hawk@mymachine:~/work/OpenCV/OpenCV-Current/opencv$ git remote -v

origin git://code.opencv.org/opencv.git (fetch)

origin git://code.opencv.org/opencv.git (push)

===

Hawk@mymachine:~/work/OpenCV/OpenCV-Current/opencv$ git branch

  • master

===

Hawk@mymachine:~/work/OpenCV/OpenCV-Current/opencv$ git pull

Already up-to-date.

===

Then I cmake and make and sudo make install.

Then run your script on AT&T face database, and I got "Segment Fault".

I don't know why, can you help?

HawkWang gravatar imageHawkWang ( 2012-08-02 00:20:44 -0600 )edit

I have added a bug report here and will fix it this weekend:

Please add your Operating System, OpenCV version (I guess trunk), NumPy version (please try with latest also) and any details, that can help me to reproduce.

Philipp Wagner gravatar imagePhilipp Wagner ( 2012-08-02 11:25:17 -0600 )edit

[To Philipp] I am sorry that I left my computer for several days that I haven't check the fix. I will soon test your fix and thank you so much for help! And thank you for your spirit of open source. I will soon post my test result.

HawkWang gravatar imageHawkWang ( 2012-08-14 03:03:03 -0600 )edit

[To Philipp] I have tested the fix by just repeating the steps I failed last time. And now it runs OK! No "Segment Fault" anymore. Again, thanks a lot!

HawkWang gravatar imageHawkWang ( 2012-08-14 04:51:47 -0600 )edit
1

answered 2012-08-05 18:31:05 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

It's fixed in trunk:

There were 2 problems causing the segmentation fault actually.

(1) Mat::copyTo threw a segmentation fault for the Python Bindings on 64 bit machines, I have opened a new issue regarding it:

The current solution simply does a naive, but safe element-by-element copy.

(2) The Python Wrapper generated for the LDA should work correctly now if a list of images is passed, I doubt this was causing the problem (but the copyTo(...) again). I've fixed it nevertheless.

Please update your local repository with the latest changes and let me know, if it works.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-08-01 04:20:55 -0600

Seen: 5,999 times

Last updated: Aug 11 '12