How to Use OpenCV for Facial Recognition

628 views
Skip to first unread message

Kyosho Dc

unread,
Jul 6, 2018, 9:36:36 AM7/6/18
to ResourceSpace
Hi - I'm working with ResourceSpace 8.4.11017 on an Ubuntu 18.04 LTS server.

I've installed Python (version 2.7.15rc1) and OpenCV (version 3.2.0) per the ResourceSpace documentation. I modified the config.php file per the instructions and restarted Apache2. Installation check is fine, no apparent errors of any kind.

When I now use our ResourceSpace Image Archive (in test), I click on a photo image and a new feature that did not appear before is a small green rectangle with a green edit pencil in it located at the bottom of the image.

But I don't understand how to access it. Nothing happens when I click on it. When I click the customary Edit pencil under Resource tools, the green rectangle and edit pencil do not appear.

So far I'm stumped. It seems to be almost working. Is there a trick to this?

Thanks - 

Kyosho Dc

unread,
Jul 6, 2018, 4:11:41 PM7/6/18
to ResourceSpace
OK - So I now see that when I hold down the Alt key and the Left click key on the mouse on top of the green rectangle and drag it onto the image, the image shifts into a selected state, allows me to draw a box around the face and name it. When I search my field (Suggested Person(s)), it locates the photo. When I view a few photos of the same person, they all say "1 annotation".

All this is good progess.

I have created a folder in my Linux home directory with full permissions for www-data. And I set in config.php the variable: $facial_recognition_face_recognizer_models_location = .

After running the suggested cron job: wget -q -r http://xxxxxxxxxxxxxxxxxxx.com/pages/tools/facial_recognition_trainer.php, I expected to get some data stored at the above location, but the folder is empty. No Apache errors or anything like that.

What am I missing? Once I get a trained face, what happens then? How will my experience as a photo editor shift? Will I get a suggestion when I call up a new image? How does this work currently?

Thanks - 

Dan Huby

unread,
Jul 7, 2018, 5:37:40 PM7/7/18
to ResourceSpace

Kyosho Dc

unread,
Jul 11, 2018, 11:53:23 AM7/11/18
to resour...@googlegroups.com
Hi Dan - Thank you so much for the link! I didn't stumble across that one, and it was exactly what I wanted.

I have further questions about the OpenCV functionality within ResourceSpace:

I do get right away to be able to draw boxes around faces in Preview mode. I then have a choice of Unknown or to enter a name. I have entered the same name on multiple photos, and I do then get a choice to select that person's name and Save.

So far, however, I do not get a prompt for the person's name along with the Unknown tag.

I set config.php as: $facial_recognition_face_recognizer_models_location = '~/OpenCV/faceRecognizerData';
www-data owns both folders with Create and delete files permissions

In /etc/cron.hourly, I set up the trainer task: wget -q -r http://www.zmmarchive.com/pages/tools/facial_recognition_trainer.php

This is quite close to fully functional. So far, I have no data in the faceRecognizerData folder. Is that the reason I am not getting a recognition prompt when I highlight a known person?

Thanks ...

--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.com
---
You received this message because you are subscribed to a topic in the Google Groups "ResourceSpace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/resourcespace/9lBn9pfjj6I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to resourcespace+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Frank Kyosho Fallon

Kyosho Dc

unread,
Jul 12, 2018, 4:57:51 PM7/12/18
to ResourceSpace
Hi - I have some diagnostic info from trying to run facial_recognition_trainer.php:

After removing the -q parameter to display progress, I have:

Connecting to www.zmmarchive.com (www.zmmarchive.com)|192.168.12.8|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Username/Password Authentication Failed.

How would I fix this so it can run from the command line/cron job?

Thanks ...

Kyosho Dc

unread,
Jul 13, 2018, 2:43:51 PM7/13/18
to ResourceSpace
Further diagnostics for running facial recognition on an Ubuntu 18.04 server:

Trying to run the PHP file from the command line with: wget -r --user=xxxxxxxx --password=yyyyyyyy .../pages/tools/facial_recognition_trainer.php

My response is:

HTTP request sent, awaiting response... 401 Unauthorized
Unknown authentication scheme.

Username/Password Authentication Failed.


What is an unknown authentication scheme? Am I supposed to put something besides an admin user on the Ubuntu server and their password?

Kyosho Dc

unread,
Jul 13, 2018, 3:05:17 PM7/13/18
to ResourceSpace
Some additional information:

When I run .../pages/tools/update_checksums.php with wget from the command line I get the same authentication error. I am able to run it by entering the http: address of the php file into a browser.

When I try to do that with facial_recognition_trainer.php, I get a response: Access denied - Command line only!

Dan Huby

unread,
Jul 13, 2018, 3:54:52 PM7/13/18
to ResourceSpace
You need to do "php facial_recognition_trainer.php" otherwise you're not running it from the command line, you're running it via the web server.

Dan

Kyosho Dc

unread,
Jul 14, 2018, 3:24:41 PM7/14/18
to ResourceSpace
Thanks Dan - Bullseye! I now have "Successfully trained FaceRecognizer!"

Following this, I began testing with one of the people I made a lot of annotations for.

I selected a new image, drew a rectangle around the known face, and got this message:

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

Wonder what's going on ....
To unsubscribe from this group and all its topics, send an email to resourcespac...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Frank Kyosho Fallon

Kyosho Dc

unread,
Jul 14, 2018, 3:37:26 PM7/14/18
to ResourceSpace
By the way, I am using Python 2.7.15rc1 and OpenCV 3.4.1

I had to modify faceRecognizerTrainer.py to get it to work:

#model = cv2.createLBPHFaceRecognizer(2, 10, 10, 10)
model = cv2.face.LBPHFaceRecognizer_create(2, 10, 10, 10)

I also modified faceRecognizer.py to match:

#model = cv2.createLBPHFaceRecognizer()
model = cv2.face.LBPHFaceRecognizer_create()

Any possibility I have to downgrade my OpenCV version?

Other ideas?

Thanks -

Jeff Nova

unread,
Jul 14, 2018, 5:23:07 PM7/14/18
to resour...@googlegroups.com
Ideally, we’d support both, but 3.x is canonical at this point and the version that all major package manager default to. Since the edits at least at this time appear to be minor, it might be possible to rather easily support both versions. 

Best,
Jeff
You received this message because you are subscribed to the Google Groups "ResourceSpace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resourcespac...@googlegroups.com.

Kyosho Dc

unread,
Jul 14, 2018, 6:03:48 PM7/14/18
to resour...@googlegroups.com
Hi - I had a success! I must have mixed up pip install and sudo apt install commands along the way.

I completely uninstalled OpenCV and reinstalled following the ResourceSpace instructions. It installed OpenCV 3.2 instead of 3.4.

This version works! No more error messages.

I get a prompt that shows the name of the person I have just drawn a box around!

Fantastic!

Nice work at Montala and hope for more in the future.

Best  to all - Kyosho

To unsubscribe from this group and stop receiving emails from it, send an email to resourcespace+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.com
---
You received this message because you are subscribed to a topic in the Google Groups "ResourceSpace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/resourcespace/9lBn9pfjj6I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to resourcespace+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Frank Kyosho Fallon

Kyosho Dc

unread,
Jul 17, 2018, 6:02:46 PM7/17/18
to ResourceSpace
After some initial success, I am running into what seem to be some configuration and permission issues:

  1. Each time I run the facial recognition trainer, it creates 2 files in the directory I specified in config.php: lbph_model.xml and prepared_data.csv.
    Both are owned by user administrator on the Linux server, which is also a Super Admin in ResourceSpace. Other users who are Archivists, but not Super Admins, can see others' annotations, but cannot save their own.

  2. One person's face was both successfully trained, and it shows as a prompt when that person is identified in a new photo. But that person's name also shows up as a cue/prompt from the recognition software, even if it is a completely different person.

  3. The facial recognition trainer appears to be running correctly, and it creates new node ID's for new people. I have someone with 14 photographs facially identified. When I draw a rectangle around a new photo of that person, only the 1 person with a different node ID shows up, which is the wrong person.
Not quite sure where to look at this point. Any ideas?

Kyosho Dc

unread,
Jul 19, 2018, 3:40:48 PM7/19/18
to ResourceSpace
With some trepidation, I decided that my ongoing problems with installation and upgrading and downgrading might have kludged the install.

I did an experiment, since I have the luxury of creating Virtual Machines on a Hyper-V server, by creating a new VM with Ubuntu Linux 18.04 LTS out of the box, instead of patched up from 16.04. Then I followed the detailed instructions provided by ResourceSpace for installing and configuring from scratch:


I still had some buggy parts and other tweaks, but without a ton of effort I had RS up and running on a local, experimental filestore. I added OpenCV per the instructions and Voila! It worked with a minor tweak (tiny mod to upgrade syntax to OpenCV Version 3) to the Python files provided with the project for facial recognition.

This was a very straightforward and smooth outcome.

I think I will abandon the other server after I have experimented with transplanting the filestore and so forth. 

Thanks for all the assistance thus far. Looking forward to opening the API for some automation work ...

Kyosho

Kyosho Dc

unread,
Jul 23, 2018, 3:37:02 PM7/23/18
to ResourceSpace
Hi - There is kind of a grand finale to this thread:

I am quite glad I chose to recreate my Linux Ubuntu server and reinstall ResourceSpace with Subversion. As I mentioned, the facial recognition plug-in from OpenCV then worked out of the box.

A final twist: when I uploaded my production database, I returned to the original problem where only 1 person was ever offered as the candidate for recognition. I then realized the field in RS I had added for facial recognition must contain corrupted data due to the installation problems I experienced from before. I deleted the field and created a new one. Yes, I did then have to go in and modify previously annoted photos, delete the name, and re-add it. But then it worked!

afatac

unread,
Jul 27, 2019, 5:16:25 AM7/27/19
to ResourceSpace
Hi, I am curious how does this facial recognition feature work in RS?

From the write up, it seems that we need to train OpenCV to recognise the faces and tag them with names initially.

So after the training, does it mean that when new images are uploaded, the faces will be automatically recognized and tagged, or do we still have to manually draw boxes around faces each time?

Dan Huby

unread,
Jul 27, 2019, 4:47:14 PM7/27/19
to resour...@googlegroups.com
At the moment you have to draw boxes around the faces and it will suggest the nearest match for you.

It'd be possible to connect this to the coordinates for detected faces supplied by Google Vision - that's the next phase but it's not planned for a future release just yet - this requires funding or third party development.

Dan


-- 
Dan Huby
Managing Director
 
Montala Limited
http://www.montala.com
UK: 01367 710245
Intl: +44 136 771 0245



--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.com
---
You received this message because you are subscribed to a topic in the Google Groups "ResourceSpace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/resourcespace/9lBn9pfjj6I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to resourcespac...@googlegroups.com.

afatac

unread,
Jul 29, 2019, 3:25:27 AM7/29/19
to ResourceSpace
Got it. Thanks.


On Sunday, 28 July 2019 04:47:14 UTC+8, Dan Huby wrote:
At the moment you have to draw boxes around the faces and it will suggest the nearest match for you.

It'd be possible to connect this to the coordinates for detected faces supplied by Google Vision - that's the next phase but it's not planned for a future release just yet - this requires funding or third party development.

Dan


-- 
Dan Huby
Managing Director
 
Montala Limited
http://www.montala.com
UK: 01367 710245
Intl: +44 136 771 0245



On Sat, 27 Jul 2019 at 10:16, afatac <ooe...@gmail.com> wrote:
Hi, I am curious how does this facial recognition feature work in RS?

From the write up, it seems that we need to train OpenCV to recognise the faces and tag them with names initially.

So after the training, does it mean that when new images are uploaded, the faces will be automatically recognized and tagged, or do we still have to manually draw boxes around faces each time?

--
ResourceSpace: Open Source Digital Asset Management
http://www.resourcespace.com
---
You received this message because you are subscribed to a topic in the Google Groups "ResourceSpace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/resourcespace/9lBn9pfjj6I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to resour...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages