sightmachine / SimpleCV

The Open Source Framework for Machine Vision
http://simplecv.org
BSD 3-Clause "New" or "Revised" License
2.68k stars 798 forks source link

When using TrainFacialRecognition.py i get an error #663

Open patrickdaulie opened 9 years ago

patrickdaulie commented 9 years ago

Hi,

The camera window shows the image, but when the procudure is executed there is an error : Output of the script :

ERROR: Traceback (most recent call last): File "TrainFacialRecognition.py", line 46, in f = FaceRecognizer() NameError: name 'FaceRecognizer' is not defined Exception in thread Thread-1 (most likely raised during interpreter shutdown):

dreams6 commented 9 years ago

how do you solve this ?

rodgomesc commented 9 years ago
dreams6 commented 9 years ago

-

Hiii

what operating system are you using? -- Windows - 7 - home

you are using SimpleCV1.3 or SimpleCV2.0? --simplecv1.3 superpack

What OpenCV version are you using? its come with simplecv1.3 superpack it seems 2.3

Can you show the code that is giving the error ?:

from SimpleCV import * import time

- i tried to import but notworkout--- from SimpleCV import FaceRecognizer

This file shows you how to train Fisher Face Recognition

Enter the names of the faces and the output file.

cam = Camera(1) # camera names = ['Alice','Bob'] # names of people to recognize outfile = "test.csv" #output file waitTime = 10 # how long to wait between each training session f = FaceRecognizer() def getFaceSet(cam,myStr=""):

Grab a series of faces and return them.

# quit when we press escape.
iset = ImageSet()
count = 0
disp = Display((640,480))
while disp.isNotDone():
    img = cam.getImage()
    fs = img.findHaarFeatures('face')
    if( fs is not None ):
        fs = fs.sortArea()
        face = fs[-1].crop().resize(100,100)
        fs[-1].draw()
        iset.append(face)
        count = count + 1
    img.drawText(myStr,20,20,color=Color.RED,fontsize=32)
    img.save(disp)
disp.quit()
return iset

First make sure our camera is all set up.

getFaceSet(cam,"Get Camera Ready! - ESC to Exit") time.sleep(5) labels = [] imgs = []

for each person grab a training set of images

and generate a list of labels.

for name in names: myStr = "Training for : " + name iset = getFaceSet(cam,myStr) imgs += iset labels += [name for i in range(0,len(iset))] time.sleep(waitTime)

Create, train, and save the recognizer.

f = FaceRecognizer() print f.train(imgs, labels) f.save(outfile)

Now show us the results

disp = Display((640,480)) while disp.isNotDone(): img = cam.getImage() fs = img.findHaarFeatures('face') if( fs is not None ): fs = fs.sortArea() face = fs[-1].crop().resize(100,100) fs[-1].draw() name, confidence = f.predict(face) img.drawText(name,30,30,fontsize=64) img.save(disp)

2nd Floor, Shrinath Complex, Near Bank of Baroda, Sahakar Nagar, Dargah Road, Aurangabad - 431001 Office :- 0240-6007600 ,7350724257

On Fri, Mar 20, 2015 at 2:25 AM, Rodrigo Gomes notifications@github.com wrote:

-

what operating system are you using?

you are using SimpleCV1.3 or SimpleCV2.0?

What OpenCV version are you using?

Can you show the code that is giving the error ?:

— Reply to this email directly or view it on GitHub https://github.com/sightmachine/SimpleCV/issues/663#issuecomment-83757942 .

dreams6 commented 9 years ago

Hiii

what operating system are you using? -- Windows - 7 - home

you are using SimpleCV1.3 or SimpleCV2.0? --simplecv1.3 superpack

What OpenCV version are you using? its come with simplecv1.3 superpack it seems 2.3

Can you show the code that is giving the error ?: from SimpleCV import * import time

from SimpleCV import FaceRecognizer --# i tried to import but not work out

This file shows you how to train Fisher Face Recognition

Enter the names of the faces and the output file.

cam = Camera(1) # camera names = ['Alice','Bob'] # names of people to recognize outfile = "test.csv" #output file waitTime = 10 # how long to wait between each training session f = FaceRecognizer() def getFaceSet(cam,myStr=""):

Grab a series of faces and return them.

# quit when we press escape. 
iset = ImageSet()
count = 0
disp = Display((640,480))
while disp.isNotDone():
    img = cam.getImage()
    fs = img.findHaarFeatures('face')
    if( fs is not None ):
        fs = fs.sortArea()
        face = fs[-1].crop().resize(100,100)
        fs[-1].draw()
        iset.append(face)
        count = count + 1
    img.drawText(myStr,20,20,color=Color.RED,fontsize=32)
    img.save(disp)
disp.quit()
return iset

First make sure our camera is all set up.

getFaceSet(cam,"Get Camera Ready! - ESC to Exit") time.sleep(5) labels = [] imgs = []

for each person grab a training set of images

and generate a list of labels.

for name in names: myStr = "Training for : " + name iset = getFaceSet(cam,myStr) imgs += iset labels += [name for i in range(0,len(iset))] time.sleep(waitTime)

Create, train, and save the recognizer.

f = FaceRecognizer() print f.train(imgs, labels) f.save(outfile)

Now show us the results

disp = Display((640,480)) while disp.isNotDone(): img = cam.getImage() fs = img.findHaarFeatures('face') if( fs is not None ): fs = fs.sortArea() face = fs[-1].crop().resize(100,100) fs[-1].draw() name, confidence = f.predict(face) img.drawText(name,30,30,fontsize=64) img.save(disp)

rodgomesc commented 9 years ago

this algorithm worked perfectly for me!

just by replacing img.findHaarFeatures ('face') by img.findHaarFeatures ('face.xml')

but I have some recommendations that might help you. Recently I noticed a similar problem, and is probably your SimpleCV SuperPack is outdated, due to a considerable number of people are having trouble installing SimpleCV, I developed a new auto installer, but for it to work you must do some things before:

1 in its algorithm replace all img.findHaarFeatures('face') by img.findHaarFeatures('face.xml') 2 - uninstall python and any library related to it, scipy, numpy, opencv etc, let the free windows python. 3 while the installation software is running do not move the machine, including the mouse!

here is the link:

http://goo.gl/eIjdSz

windowsXP, 7,8,8.1

Just click SimpleCVAutoInstall.exe, and wait for the installation.

I'm waiting for your feedback.

sorry, my english is not very good, thanks.

jrahman10 commented 9 years ago

Hello,

I'm Facing The Same Problem. I'm Using: Ubuntu 14.04LTS 32 BIT Python 2.7.6 SimpleCV 2 OpenCV 2 I'm Using Laptop Camera

Code: from SimpleCV import * import time cam = Camera(0) names = ['Jubayer','Disty'] outfile = "test.csv" waitTime = 10

def getFaceSet(cam,myStr=""): iset = ImageSet() count = 0 disp = Display((640,480)) while disp.isNotDone(): img = cam.getImage() fs = img.findHaarFeatures('face') if( fs is not None ): fs = fs.sortArea() face = fs[-1].crop().resize(100,100) fs[-1].draw() iset.append(face) count = count + 1 img.drawText(myStr,20,20,color=Color.RED,fontsize=32) img.save(disp) disp.quit() return iset

getFaceSet(cam,"Get Camera Ready! - ESC to Exit") time.sleep(5) labels = [] imgs = []

for name in names: myStr = "Training for : " + name iset = getFaceSet(cam,myStr) imgs += iset labels += [name for i in range(0,len(iset))] time.sleep(waitTime)

f = FaceRecognizer() print f.train(imgs, labels) f.save(outfile)

disp = Display((640,480)) while disp.isNotDone(): img = cam.getImage() fs = img.findHaarFeatures('face') if( fs is not None ): fs = fs.sortArea() face = fs[-1].crop().resize(100,100) fs[-1].draw() name, confidence = f.predict(face) img.drawText(name,30,30,fontsize=64)

img.save(disp)

Error Showing:

Python 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] on linux2 Type "copyright", "credits" or "license()" for more information.

================================ RESTART ================================

Traceback (most recent call last): File "/home/jubayer/Desktop/F4/SimpleCV/examples/detection/TrainFacialRecognition.py", line 46, in f = FaceRecognizer() NameError: name 'FaceRecognizer' is not defined

Any Help Please :/

Thanks Jubayer

dreams6 commented 9 years ago

Hello Rodrigo i follow your complete instruction then i found my system still download the CV version 2.3..

and as i found the facerecognizer is available in 2.4 and above

so i manually install the 2.4 version , update the path in system PATH and PYTHONPATH with new 2.4 ..vc10 address.

but now system gives error -

Traceback (most recent call last): File "D:\simplecv\facedet\facetrain.py", line 1, in from SimpleCV import * File "C:\Python27\lib\site-packages\SimpleCVinit.py", line 3, in

from SimpleCV.base import * File "C:\Python27\lib\site-packages\SimpleCV\base.py", line 59, in raise ImportError("Cannot load OpenCV library which is required by SimpleCV") ImportError: Cannot load OpenCV library which is required by SimpleCV my python version Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. > > > # ================================ RESTART my system is - windows 7 - home premium opencv i insatall manually - opencv-2.4.10 --- also all installation including python and its supporting software install from your installation , cython installed manually by 0.22 whl please let me know how to go further . step by step even i have raspberry pi - if its easy on rpi please let me know finally i want to run it on rpi thanks for your help. 2nd Floor, Shrinath Complex, Near Bank of Baroda, Sahakar Nagar, Dargah Road, Aurangabad - 431001 Office :- 0240-6007600 ,7350724257 On Sat, Mar 21, 2015 at 8:03 AM, Rodrigo Gomes notifications@github.com wrote: > this algorithm worked perfectly for me! > > just by replacing img.findHaarFeatures ('face') by img.findHaarFeatures > ('face.xml') > > but I have some recommendations that might help you. > Recently I noticed a similar problem, and is probably your SimpleCV > SuperPack is outdated, due to a considerable number of people are having > trouble installing SimpleCV, I developed a new auto installer, but for it > to work you must do some things before: > > 1 in its algorithm replace all img.findHaarFeatures('face') by > img.findHaarFeatures('face.xml') > 2 - uninstall python and any library related to it, scipy, numpy, opencv > etc, let the free windows python. > 3 while the installation software is running do not move the machine, > including the mouse! > > here is the link: > > http://goo.gl/eIjdSz > > windowsXP, 7,8,8.1 > > Just click SimpleCVAutoInstall.exe, and wait for the installation. > > I'm waiting for your feedback. > > sorry, my english is not very good, thanks. > > — > Reply to this email directly or view it on GitHub > https://github.com/sightmachine/SimpleCV/issues/663#issuecomment-84222058 > .
jrahman10 commented 9 years ago

OK I Updated All Like OpenCV And SampleCV Now Its Working But When I Trained 2 Face And After That When It Search For The Face Its Giving This Error ....Any Help Please ? :)

Traceback (most recent call last): File "/home/jubayer/Desktop/SimpleCV-master/SimpleCV/examples/detection/TrainFacialRecognition.py", line 56, in face = fs[-1].crop().resize(100,100) File "/usr/local/lib/python2.7/dist-packages/SimpleCV/Features/Features.py", line 50, in getitem return list.getitem(self,key) IndexError: list index out of range

rodgomesc commented 9 years ago

@jrahman10 in the line names = ['Jubayer','Disty'] contain two names in list?

rodgomesc commented 9 years ago

@jrahman10 FaceRecognize does not allow you, use only a one face

rodgomesc commented 9 years ago

for more help, please ask in http://help.simplecv.org

jrahman10 commented 9 years ago

@administradorx Yes I Used Two Name Still Not Working With Those Error :/

dreams6 commented 9 years ago

Rodrigo Gomes

finally the auto install work properly on windows 7- the problem was python registry was not removed from windows . its now perfectly working on windows 7.

i want similar type of setup or guideline for installation on RPI please help

2nd Floor, Shrinath Complex, Near Bank of Baroda, Sahakar Nagar, Dargah Road, Aurangabad - 431001 Office :- 0240-6007600 ,7350724257

On Mon, Apr 13, 2015 at 12:10 AM, jrahman10 notifications@github.com wrote:

@administradorx https://github.com/administradorx Yes I Used Two Name Still Not Working With Those Error :/

— Reply to this email directly or view it on GitHub https://github.com/sightmachine/SimpleCV/issues/663#issuecomment-92099344 .