Example Code

Simple Face Detection using IMAQ

Code and Documents

Attachment

Overview

This is my second attempt at making something with IMAQ Vision add-on. The example uses built-in colour and pattern matching capabilities to perform face recognition on a webcam stream. Code itself is not very sophisticated and face detection is far from robust. That being said, given right templates and adequate settings it does perform surprisingly with respect to its simplicity. Hopefully this will inspire you to work on more refined and complex face detection examples.

face rec block diagram.png

face rec1.pngface rec2.png

Description

The whole approach can be split into two main parts:

1. Face Detection. It is accomplished by matching Eye, Nose and Lips templates against the camera stream image. Once these three are found, simple logical calculations are performed (e.g. is eye level higher than nose level) to determine whether it's really something resembling a face. If so, a boolean is used to flag this case.

2. Point Following. Once a face is found we extract the X and Y of the last Lips match found (chosen arbitrarily). This point (X,Y) is then tracked on the screen until another face is found.

This way we can use more robust template match setup data to find a face less often but with higher accuracy. Until another face is found point tracking takes care of following last face found.

Hopefully this makes sense, but if not, I enclosed more comments within the code itself.


Steps to Implement or Execute Code

1) Download the VI

2) Make sure you have selected your camera input in the block diagram

3) [Optional] Update template files to fit yourself better either in the load_templates_subVI.vi file or update the .png files with new ones using same names in the folder of the project.

4 )[Optional] Adjust Setup Data to fit your camera, templates and lighting better.

5) Run the VI.

6) Use the "Show Templates" button on the front panel to show/hide templates on the IMAQ image control.

Requirements

Software

LabVIEW 8.6 or newer

Vision Development Module

NI-IMAQ

NI-IMAQdx


Hardware

LabVIEW and IMAQ compatible web camera or any other source of video input



______________________________________________________

Mark N
Applications Engineer
National Instruments UK & Ireland

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
JLHaworth
Member
Member
on

Could you please post for Labview 2011 SP1?

NI-MarkN
NI Employee (retired)
on

The 8.6 version should work fine, but just in case I have saved it for 2011.

You can find the link next to the original ones in the post above.

______________________________________________________

Mark N
Applications Engineer
National Instruments UK & Ireland
JLHaworth
Member
Member
on

Thank you! I had some trouble with the v8.6, that it wouldn't even load the front or block diagram.

No idea what that was about. The v11 loads up great, but crashes during the run.

The IMAQ grab works and updates on the front panel. It looks like the code runs up to the face_check_subVI, after which it crashes.

If I set a breakpoint, it will step past, and keep iterating through the loop.

I have updated the templates to include eye, lips, and nose of my face, so that it should be good there.

Excaept, it doesn't seem that it ever passes a true out of the template matching check?..

Any ideas on what I should check from here? The concept is great, and the code looks good. It just seems to be doing something weird on my end?..

Running on a Dell Latitude, with embedded webcam @ 30 fps, Windows 7, 64-bit, Labview 2011 SP1 64-bit.

NI-MarkN
NI Employee (retired)
on

That's interesting, if I find time I'll try to replicate the same setup (from software point of view) and see whether I get the same results.

Do you get any specific error messages once it crashes?

If you were to open face_check_subVI you'd see it only does simple comparisons and maths but does not call any subVIs from itself which makes me believe the issue lies somewhere else. Did you try changing the "Setup Match Color Pattern" settings? Do any other IMAQ examles run fine your machine?

______________________________________________________

Mark N
Applications Engineer
National Instruments UK & Ireland
JLHaworth
Member
Member
on

I don't get any error or message of any kind. The LV windows all basically just suddenly close and that is all.

I found this behavior being discussed in a couple of forum topics http://forums.ni.com/t5/LabVIEW/LabVIEW-Access-Violation-Crashes/td-p/2004337/page/2 and http://forums.ni.com/t5/NI-TestStand/LabVIEW-Access-Violation-Crashes-from-TestStand/td-p/2004661/pa..., with a direct mention in the first link to the optical flow block. I have tried the Optical Flow Example from the LV examples package. This vi gives the exact same behavior. I run the vi, and it runs a few frames, then crashes all LV windows.

I have updated to LV 2012, which is the farthest my license allows, and I get the same behavior. I do get a window advising of LV crashing, though, with the following details.

Problem signature:

  Problem Event Name:          APPCRASH

  Application Name:          LabVIEW.exe

  Application Version:          12.0.0.4028

  Application Timestamp:          506dc4a8

  Fault Module Name:          nivision.dll

  Fault Module Version:          12.0.0.49152

  Fault Module Timestamp:          4fcfa45c

  Exception Code:          c0000005

  Exception Offset:          00000000005acf61

If I run the vi in debug mode, I can iterate through any number of iterations without crashing.

I am wondering if there is some issue with the frame rate? Should I alter the settings on my camera? I am using the built-in laptop webcam, with factory settings.

Could you post the code saved for LV 2012? Possibly that would work fine, and then not bother trying to troubleshoot the issue any further?!..

222twj
Member
Member
on

I'm thinking about helping my son tackle a Senior project (High School) based on your code... He would like to be able to detect some of his classmates.  My thinking was he could capture some stills in a control setting ... This will be his first exposure to LV.. he has 9 months...any thoughts?  I was going to let him request a student version .. any recommendations on LV version.

Gg$16sant
Member
Member
on

Can someone help me to upload this program on myRIO? I keep getting an error - IMAQ vision: file not found when i run the program.

Contributors