gm_faceapi - Facetracking with only a webcam.

Well I sent my module to about 10 people and they have done absolutely nothing with it, so I’m just going to go ahead and release it.

This module automatically chooses the first webcam it can find. (The current API is messed up and won’t let me list all the cameras available).

To make sure faceAPI works with your processor and camera, download the examples on the faceAPI website. There might be some drivers that you would need to run this module that is included with the example on the faceAPI website.


[lua]faceAPI.GetVersion() – Returns the string of the current version of faceAPI the module uses.
faceAPI.GetHeadPos() – Returns the current position of your head.
faceAPI.GetHeadAng() – Returns the current angle of your head.
FACEAPI_ENABLED – Global that is set if the module is properly ran.[/lua]

I think this might be useful.
If someone could give me some code to move the players head angle, that would be nice!

Are you kidding me? It’s in the example file.
if !CLIENT then return end


function faceAPI_demoCalcView(pl, pos, angles, fov)

local WorldPos,WorldAng = LocalToWorld(faceAPI.GetHeadPos()*300+Vector(130,0,0),faceAPI.GetHeadAng(),pos,angles)
// I add 130 forward since faceAPI's head center is a bit too close.

local view = {}
view.origin = WorldPos
view.angles = WorldAng
view.fov = fov

return view


hook.Add(“CalcView”, “faceAPI_demoCalcView”, faceAPI_demoCalcView)

I’ve installed the whole thing correctly but I get this error when requiring faceapi:

error loading module 'faceapi' from file 'c:\program files (x86)\steam\steamapps\<snip>\garrysmod\garrysmod\lua\includes\modules\gm_faceapi.dll':
	Impossível localizar o módulo especificado. (Impossible to locate the specified module)

Install VS2010 redistributables.

Ah thanks I thought I had that already.

Yeah I do. Tried repairing the install but to no avail.

Stupid question, and I apologize for asking this, but did you check the folder to see if that file was in there?

The error is ERROR! module ‘xxx’ not found! in red if it’s not there.

Did you install the FaceApi drivers?

I did, it’s awkward because it works on my desktop PC but not on my laptop, and they’re practically the same. Thanks anyway.

Thanks for the heads up man, but that is kind of a fib. faceAPI doesn’t list all the cameras, but you can select any camera you want even if it’s not the first one, faceAPI just won’t give you the info on the camera type.

[editline]17th July 2011[/editline]

faceAPI doesn’t work with certain processors, maybe that’s the problem. I wouldn’t know.

You could probably get around it using DirectShow or MediaFoundation to enumerate all the input devices ( line 138) and get all their info. But it will be a hell of a work and probably won’t compensate it. You’ll have to test around it. You could also give the API minimal information so you have less work.

What am I supposed to do here? I installed it all into the right foldiers, but the head tracking does not work ingame. Did I miss something?

You are probably missing the most important thing about this module,the faceapi.
This module is just a middle man between the faceapi and gmod.
Go and download the faceapi before complaining that it doesn’t work.

Shit. Massive derp. I’ll install it and check again.

[editline]20th July 2011[/editline]

Alright, it works!

Although shaky as hell.

Here’s my modified version of the example, it only moves the angle of your view, but it’s smoother.
if !CLIENT then return end


function faceAPI_demoCalcView(pl, pos, angles, fov)

lastHeadAng = lastHeadAng or angles

local headAng = faceAPI.GetHeadAng()
local newHeadAng = Angle(faceAPI.GetHeadAng().p*3,faceAPI.GetHeadAng().y*3,faceAPI.GetHeadAng().r)
local finalHeadAng = LerpAngle(0.05,lastHeadAng,newHeadAng)

local WorldPos,WorldAng = LocalToWorld(faceAPI.GetHeadPos()*300+Vector(130,0,0),finalHeadAng,pos,angles)
// I add 130 forward since faceAPI's head center is a bit too close.

local view = {}
view.origin = pos
view.angles = WorldAng
view.fov = fov

lastHeadAng = finalHeadAng

return view


hook.Add(“CalcView”, “faceAPI_demoCalcView”, faceAPI_demoCalcView)[/lua]

hmm ok guys so I downloaded the files and faceapi from the website everything is correctly installed i think. The webcam turns on ingame and the mouse is moving pretty weird. What else do I have to do?

Maybe make it increment and remove the need of a mouse … and maybe make +attack1 and +attack2 work when we blink with our eyes!

I can’t wait to dive more into this, couple mistakes I made while testing it but it was fun.
I’m thinking of doing some stuff with vehicles, not sure yet.