Facial Recognition (the bane of my existance)

163 views
Skip to first unread message

Benjamin Jones

unread,
Apr 17, 2019, 8:44:34 AM4/17/19
to ResourceSpace

So I've looked all through the forum here and can't seem to find a solution for my exact problem.  When I run a 'php facial_recognition_trainer.php', I get this:

Preparing image for resource ID 2 and node ID 278
Preparing image for resource ID 79 and node ID 278
Preparing image for resource ID 3 and node ID 279
Preparing image for resource ID 82 and node ID 279
Preparing image for resource ID 85 and node ID 279
Preparing image for resource ID 72 and node ID 279
Preparing image for resource ID 71 and node ID 279
Preparing image for resource ID 62 and node ID 279
Preparing image for resource ID 61 and node ID 279
Preparing image for resource ID 56 and node ID 279
Preparing image for resource ID 48 and node ID 279
Preparing image for resource ID 118 and node ID 279
Preparing image for resource ID 115 and node ID 279
Preparing image for resource ID 136 and node ID 279
Preparing image for resource ID 121 and node ID 279
Preparing image for resource ID 153 and node ID 279
Preparing image for resource ID 478 and node ID 279
Traceback (most recent call last):
  File "/var/www/resourcespace/pages/tools/../../lib/facial_recognition/faceRecognizerTrainer.py", line 40, in <module>
    cv2.face
AttributeError: 'module' object has no attribute 'face'

I've tested opencv with python and it seems to be installed okay.  I've tried with both pip and yum  (yup, I'm running CentOS).  Everything else works great with resourcespace, and if this is the only thing that doesn't work, I can accept that.  Just wanted to make sure there's nothing out there I haven't tried before throwing in the towel.

Ian Matzen

unread,
Apr 17, 2019, 10:00:47 PM4/17/19
to ResourceSpace
Hi Benjamin. 

I encountered the same error and found a simple solution! The cv2.face command is dependent on the version of OpenCV you are running. It seems the version I am on (and the one you are probably running) uses a slightly different syntax for the command than the one that is being executed by ResourceSpace's python script. I suggest you launch python and review the OpenCV help page to find the proper one. Within Python, here is what I executed:

Python #launches Python command line
import cv2 #imports OpenCV library
print(help(cv2.face)) #prints OpenCV documentation

Scroll down to the command you are looking for. Once you have it, back up the faceRecognizerTrainer.py and faceRecognizer.py scripts and search/replace the old command with the one that works with your version of OpenCV.

I am now able to run the trainer. However, the tool does not recognize any faces from within ResourceSpace. When I select a face from within the interface, I receive the following error:

Error: Internal Server Error
ResourceSpace was not able to predict a label.

Maybe you will have better luck and report back in this thread!

Best,

Ian

Benjamin Jones

unread,
Apr 18, 2019, 9:08:15 AM4/18/19
to ResourceSpace
I believe you're correct. I know the documentation says to use OpenCV version 2.4.13, but the closest I've been able to find is 2.5.  I'm holding out hope that maybe a future update will allow us to use the newest version of OpenCV or at least one I can find ;)

Benjamin Jones

unread,
Apr 18, 2019, 9:48:22 AM4/18/19
to ResourceSpace
Okay.. somehow I got it working and I'm going to do my best to explain my steps.

First.  I am running CentOS 7, Python version 2.7.5

Second.  I made the mistake of following many of the help articles and installed opencv with yum.  I don't think this is the best way to do it, so I used PIP instead.  (https://linuxize.com/post/how-to-install-pip-on-centos-7/)

Third.  I don't think that ResourceSpace supports the latest version of OpenCV (which is what PIP will try to install).  Luckily you can force an older version.  Here is the series of commands I ran to get a successful message from running facialrecognition.php  (if you have already been using PIP, then uninstall any OpenCV stuff you've installed)

pip install opencv-python-headless==3.4.0.14
pip install opencv-contrib-python-headless==3.4.0.14
pip install opencv-contrib-python==3.2.0.7
pip install opencv-python==3.1.0.0
pip install facereg
pip install FaceExtractor

Is the facereg and FaceExtractor necessary?  I have no clue.. All I know is that after doing this, it works. 

ps  I did not modify any ResourceSpace code.

Capture.JPG






Ian Matzen

unread,
Jun 17, 2019, 9:10:10 AM6/17/19
to ResourceSpace
Hi Benjamin. Thank you for sharing your process. Once you have trained OpenCV, have you successfully recognized faces from within ResourceSpace?

Benjamin Jones

unread,
Jun 17, 2019, 10:02:28 AM6/17/19
to ResourceSpace
Yup!  Only real issue with the software now is how slow it is.  Once you draw a box around their faces though, it got pretty accurate about recognizing who you're marking.
Reply all
Reply to author
Forward
0 new messages