Coder Social home page Coder Social logo

justadudewhohacks / face-recognition.js Goto Github PK

View Code? Open in Web Editor NEW
1.9K 1.9K 274.0 5.07 MB

Simple Node.js package for robust face detection and face recognition. JavaScript and TypeScript API.

License: MIT License

Python 1.18% C++ 35.66% JavaScript 35.82% TypeScript 27.35%
face face-detection face-landmark face-recognition javascript node nodejs typescript

face-recognition.js's People

Contributors

0xflotus avatar bobmoff avatar iamblue avatar iqbalhood avatar justadudewhohacks avatar ksachdeva avatar rwieruch avatar xaklx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

face-recognition.js's Issues

face-detector img with no face error handling

Hi if i take a photo without any face is some way to handle this error with face detection? If so how can i handle this error? Because when i tried do that program returned this error:

fr.saveImage(path,faceImage[0]);
   ^

Error: Save_Image - Error: expected argument 1 to be of type ImageRGB

How to improve performance?

Hi, very good work on the project.

I have a question about performance. I am running live face recognition on my laptop webcam and i measured the time that need to work one frame (~0.5s). I am using 3 faces for recognition and there is one face on the webcam(mine).

Here is the code

const recognizeFaces2 = (detections) =>
    Promise.all(detections.map(recognizeFace));

const recognizeFace = (det) => {
    const {rect, face} = det;
    const cvFace = fr.CvImage(face);
    console.time('detection time');
    return recognizer.predictBest(cvFace, UNKNOWN_TRESHHOLD)
        .then((prediction) => {
            console.timeEnd('detection time');
            const text = `${prediction.className} (${prediction.distance})`;
            return {
                rect,
                text
            }
        })
};

const requestFrame = (videoCap) => {
    let frame = videoCap.read();
    return Promise.resolve(frame);
};

const detectCvFaces = (frame) => {
    const options = {
        minSize: new cv.Size(80, 80),
        scaleFactor: 1.1,
        minNeighbors: 3
    };
    let faces = classifier.detectMultiScaleGpu(frame.bgrToGray(), options);
    return faces.map(rect => ({
        rect,
        face: frame.getRegion(rect).resize(150, 150)
    }));
};

const drawRecognizedFaces = (videoCap) =>
    (faces) => requestFrame(videoCap)
        .then((frame) => {
            faces.forEach(({rect, text}) => {
                const blue = new cv.Vec(255, 0, 0);
                drawRectWithText(frame, rect, text, blue);
            });
            if(faces.length) {
                cv.imshow(`face detection`, frame);
                return faces
            } else {
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        cv.imshow(`face detection`, frame);
                        resolve(faces);
                    }, 30)
                })
            }

        });


const recognizeFaceAndDraw = (videoCap) =>
    requestFrame(videoCap)
        .then(detectCvFaces)
        .then(recognizeFaces2)
        .then(log('recognized faces'))
        .then(drawRecognizedFaces(videoCap))
        .then(() => recognizeFaceAndDraw(videoCap));

const runFaceRecognition2 = (src) => {
    const cap = new cv.VideoCapture(src);

    recognizeFaceAndDraw(cap);
};
const recognizeFaces2 = (detections) =>
    Promise.all(detections.map(recognizeFace));

const recognizeFace = (det) => {
    const {rect, face} = det;
    const cvFace = fr.CvImage(face);
    console.time('detection time');
    return recognizer.predictBest(cvFace, UNKNOWN_TRESHHOLD)
        .then((prediction) => {
            console.timeEnd('detection time');
            const text = `${prediction.className} (${prediction.distance})`;
            return {
                rect,
                text
            }
        })
};

const requestFrame = (videoCap) => {
    let frame = videoCap.read();
    return Promise.resolve(frame);
};

const detectCvFaces = (frame) => {
    const options = {
        minSize: new cv.Size(80, 80),
        scaleFactor: 1.1,
        minNeighbors: 3
    };
    let faces = classifier.detectMultiScaleGpu(frame.bgrToGray(), options);
    return faces.map(rect => ({
        rect,
        face: frame.getRegion(rect).resize(150, 150)
    }));
};

const drawRecognizedFaces = (videoCap) =>
    (faces) => requestFrame(videoCap)
        .then((frame) => {
            faces.forEach(({rect, text}) => {
                const blue = new cv.Vec(255, 0, 0);
                drawRectWithText(frame, rect, text, blue);
            });
            if(faces.length) {
                cv.imshow(`face detection`, frame);
                return faces
            } else {
                return new Promise((resolve, reject) => {
                    setTimeout(() => {
                        cv.imshow(`face detection`, frame);
                        resolve(faces);
                    }, 30)
                })
            }

        });


const recognizeFaceAndDraw = (videoCap) =>
    requestFrame(videoCap)
        .then(detectCvFaces)
        .then(recognizeFaces2)
        .then(log('recognized faces'))
        .then(drawRecognizedFaces(videoCap))
        .then(() => recognizeFaceAndDraw(videoCap));

const runFaceRecognition2 = (src) => {
    const cap = new cv.VideoCapture(src);

    recognizeFaceAndDraw(cap);
};

I have tried face-recognition.py and it recognizes faces in real time. I know that both libraries are build on top of dlib

I am on windows machine.

Thanks in advance

Load base64 image

Is it possible to load a base64 string image as a ImageRGB?

I've been trying to do it using the examples of opencv-express with imdecode and fr.CvImage, but the detectFaces and locateFaces returns an empty array. It works fine when I load the same image using cv.imread.

I noticed that the results I get of imread and imdecode are different for the same image, maybe this has something to do with the IMREAD_COLOR flag applied automatically to imread in the opencv source code(?)

"imread": { "step": 276, "elemSize": 3, "sizes": [ 112, 92 ], "empty": false, "depth": 0, "dims": 2, "channels": 3, "type": 16, "cols": 92, "rows": 112 }, "imdecode": { "step": 92, "elemSize": 1, "sizes": [ 112, 92 ], "empty": false, "depth": 0, "dims": 2, "channels": 1, "type": 0, "cols": 92, "rows": 112 }

api details for face-recognition.js

Hi Vincent ,

Facing issue during running some of the sample code in the page https://github.com/justadudewhohacks/face-recognition.js .
api details for accessing imageWindow object is not clear to me .
here addOverlay method is taking rectangle object . however its type is not known .
I believe these are js api are wrapper over dlib library .
Please correct me in case my understanding of this infrastructure is wrong .

const win = new fr.ImageWindow()
// display image
win.setImage(image)
// drawing the rectangle into the displayed image
win.addOverlay(rectangle)
// pause program until key pressed
fr.hitEnterToContinue()

Install issue on Windows 7

Hi,
I am using my own build of dlib.
I have set the DLIB_INCLUDE_DIR & DLIB_LIB_DIR in windows PATH variable as specified in the README.
But I am getting following error on running npm i face-recognition:

F:\Projects\face-recognition-demo\node_modules\face-recognition\lib\includes.js:4
? resolvePath(DLIB_INCLUDE_DIR)
^
ReferenceError: DLIB_INCLUDE_DIR is not defined
at Object. (F:\Projects\face-recognition-demo\node_modules\face-recognition\lib\includes.js:4:17)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:607:3

OS: Windows 7, 64-bit
Node: 8.6.0
npm: 5.3.0

Unable to detect faces in an image having dimensions 80 X 107

Hi,
I was wondering if there's any restriction on the minimum dimensions of an image in order to detect faces in it. Currently I am trying to detect face in a person's image whose dimensions are 80 X 107.
The detector.detectFaces() method returns an empty array.

How can this scale, e.g. with 10000 faces?

Just like you, I used dlib to detect and recognize faces. It's fine with just couple of faces, like 10 or 20, but when we hit more than 1000 the program became extremely slow.

Do you test your lib with more than 1000 faces? Can it scale?

Problem modifying .cc files

When I modify one of the .cc files (utils.cc and utils.h) the changes doesn't affect the build. I know that the build knows about my changes because if I do something wrong, the build throws an error and stop. But after the build, I went to the face-recognition folder inside the node_modules and the .cc file has the original version instead of my edited version. Why does this happen?

Pd: the purpose of my modifications is to use dlib::assign_image to convert a CvImage to an ImageRGB because the face68LandmarkPredictor only works with ImageRGB.

npm install error

This is where the error occurs -

XX(target) Release/obj.target/facerec/cc/index.o
In file included from ../cc/index.cc:1:
In file included from ../../nan/nan.h:51:
In file included from /Users/shashikantsharma/.node-gyp/6.9.2/include/node/node.h:42:
In file included from /Users/shashikantsharma/.node-gyp/6.9.2/include/node/v8.h:21:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/utility:157:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__tuple:16:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:309:44: fatal error: 
      recursive template instantiation exceeded maximum depth of 256
{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};

1 error generated.
make: *** [Release/obj.target/facerec/cc/index.o] Error 1

gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/shashikantsharma/Sites/faceRecognition/node_modules/face-recognition
gyp ERR! node -v v6.9.2
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm WARN [email protected] No repository field.
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "face-recognition"
npm ERR! node v6.9.2
npm ERR! npm  v3.10.9
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the face-recognition package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs face-recognition
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls face-recognition
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/shashikantsharma/Sites/faceRecognition/npm-debug.log

unable to install face-recognition.js

Hi all,

I tried to install by the command npm install face-recognition

Error:

npm ERR! weird error 1
npm ERR! Error: ENOENT, lstat '/home/vijay/node_modules/face-recognition/node_modules/nan/nan.h'
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Linux 4.4.0-97-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "face-recognition"
npm ERR! cwd /home/vijay/vijay/crowdpersona_05-01-18/JavaScript_FaceReconition
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /home/vijay/node_modules/face-recognition/node_modules/nan/nan.h
npm ERR! fstream_path /home/vijay/node_modules/face-recognition/node_modules/nan/nan.h
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Error: ENOENT, lstat '/home/vijay/node_modules/face-recognition/node_modules/face-recognition-models/models/dlib_face_recognition_resnet_model_v1.dat'
npm ERR! If you need help, you may report this log at:
npm ERR! http://github.com/isaacs/npm/issues
npm ERR! or email it to:
npm ERR! [email protected]

npm ERR! System Linux 4.4.0-97-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "face-recognition"
npm ERR! cwd /home/vijay/vijay/crowdpersona_05-01-18/JavaScript_FaceReconition
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /home/vijay/node_modules/face-recognition/node_modules/face-recognition-models/models/dlib_face_recognition_resnet_model_v1.dat
npm ERR! fstream_path /home/vijay/node_modules/face-recognition/node_modules/face-recognition-models/models/dlib_face_recognition_resnet_model_v1.dat
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)

FATAL ERROR: JS Allocation failed - process out of memory
Aborted (core dumped)

FYI:
OS: Ubuntu 14.04
Python version : 2.7
npm version: 2.15.11
nodejs version: v0.12.18

Pls suggest the way forward

Thanks
vijay

npm install face-recognition fails

Node: 9.3.0
OS: darwin x64

CXX(target) Release/obj.target/facerec/cc/FaceRecognizerNet.o
SOLINK_MODULE(target) Release/facerec.node
ld: warning: directory not found for option '-L/usr/X11/lib'
ld: library not found for -lX11
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/facerec.node] Error 1

face-recognition.js installation error

I am getting below error when I try to install using npm install face-recognition command windows 10.

const { dlibLocalLib } = require('./constants')
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3
 npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "face-recognition"
npm ERR! node v4.4.7
npm ERR! npm  v2.15.8
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node ./install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node ./install.js'.
npm ERR! This is most likely a problem with the dlib-build package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs dlib-build
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls dlib-build
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     E:\New folder\faceDetect\npm-debug.log

how to extact face coordinates for each face

Hi,
Currently we are leveraging on python to extract face coordinates of each face to undergo face recognition.

We would like to replace the python module (https://github.com/davisking/dlib) with face-recognition.js

Ex: existing python code
img='test.jpg'
facerec = dlib.face_recognition_model_v1('dlib_face_recognition_resnet_model_v1.dat')
face_descriptor = facerec.compute_face_descriptor(img, shape)
we are storing face_descriptor values in the DB and processing for face recognition.

Please suggest using face-recognition.js how can we extract face descriptor values.

Thanks
vijay

unable to install face-recognition.js

Hi ,

Facing issue in installation of the library on windows 10. As put in the guide , i have installed cmake and visual studio tools on my win 10 machine .

spawning: git [ 'clone',
'--progress',
'https://github.com/davisking/dlib.git' ]
Cloning into 'dlib'...
fatal: unable to access 'https://github.com/davisking/dlib.git/': Failed to connect to 10.68.248.34 port 80: Timed out
child process exited with code 128
npm WARN enoent ENOENT: no such file or directory, open 'd:\face_recognition_node\package.json'
npm WARN face_recognition_node No description
npm WARN face_recognition_node No repository field.
npm WARN face_recognition_node No README data
npm WARN face_recognition_node No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node ./install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\tanmay_patil\AppData\Roaming\npm-cache_logs\2018-01-14T08_43_18_083Z-debug.log

Firing git on windows 10 command line also gives me same error .
fatal: unable to access 'https://github.com/davisking/dlib.git/': Failed to connect to 10.68.248.34 port 80: Timed out.

Through chrome , i am able to navigate to repository with url : https://github.com/davisking/dlib.git/

npm install issue

It seems like I get most of the way through the install. I don't error out until it starts installing dlib. Here is the error:

`> [email protected] install C:\Users\XXX\gitstuff\faces\node_modules\dlib-build

node ./install.js

executing: git --version
executing: cmake --version
find vs2017 via powershell: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe [ '-ExecutionPolicy',
'Unrestricted',
'-Command',
'&{Add-Type -Path 'C:\Users\Sky\gitstuff\faces\node_modules\dlib-build\lib\Find-VS2017.cs'; [VisualStudioConfiguration.Main]::Query()}' ]
executing: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe [ '-ExecutionPolicy',
'Unrestricted',
'-Command',
'&{Add-Type -Path 'C:\Users\XXX\gitstuff\faces\node_modules\dlib-build\lib\Find-VS2017.cs'; [VisualStudioConfiguration.Main]::Query()}' ]
find vs2017: {"log":"Found installation at: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\n - Found Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop\n - Found Microsoft.VisualStudio.Component.VC.Tools.x86.x64\n - Found Microsoft.VisualStudio.VC.MSBuild.Base\n - Using this installation with Windows 10 SDK","path":"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools","sdk":"10.0.16299.0"}

found vs2017
path C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools
sdk 10.0.16299.0
executing: if not exist dlib mkdir dlib
executing: if not exist build mkdir build
executing: if exist dlib rd /s /q dlib
spawning: git [ 'clone',
'--progress',
'https://github.com/davisking/dlib.git' ]
Cloning into 'dlib'...
remote: Counting objects: 43188, done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 43188 (delta 2), reused 26 (delta 0), pack-reused 43160
Receiving objects: 100% (43188/43188), 19.32 MiB | 9.34 MiB/s, done.
Resolving deltas: 100% (30229/30229), done.
Checking connectivity... done.
spawning: git [ 'checkout', 'tags/v19.8', '-b', 'v19.8' ]
Switched to a new branch 'v19.8'
spawning: cmake [ 'C:\Users\XXX\gitstuff\faces\node_modules\dlib-build\dlib\dlib',
'-G',
'Visual Studio 15 2017 Win64' ]
CMake Error: Could not create named generator Visual Studio 15 2017 Win64

Generators
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 9 2008 [arch] = Generates Visual Studio 2008 project files.
Optional [arch] can be "Win64" or "IA64".
Visual Studio 8 2005 [arch] = Generates Visual Studio 2005 project files.
Optional [arch] can be "Win64".
Visual Studio 7 .NET 2003 = Generates Visual Studio .NET 2003 project
files.
Visual Studio 7 = Deprecated. Generates Visual Studio .NET
2002 project files.
Visual Studio 6 = Deprecated. Generates Visual Studio 6
project files.
Borland Makefiles = Generates Borland makefiles.
NMake Makefiles = Generates NMake makefiles.
NMake Makefiles JOM = Generates JOM makefiles.
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
MSYS Makefiles = Generates MSYS makefiles.
MinGW Makefiles = Generates a make file for use with
mingw32-make.
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - MinGW Makefiles = Generates CodeLite project files.
CodeLite - NMake Makefiles = Generates CodeLite project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Eclipse CDT4 - MinGW Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - NMake Makefiles
= Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Kate - MinGW Makefiles = Generates Kate project files.
Kate - NMake Makefiles = Generates Kate project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Sublime Text 2 - MinGW Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - NMake Makefiles
= Generates Sublime Text 2 project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.

child process exited with code 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node ./install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.`

Here is said log:
2018-01-15T00_27_28_512Z-debug.log

Install compile fails on windows

Node: 8.9.1
OS: Windows 10, 64bit, v1709
Microsoft Build Engine version: 14.0.24720.0
CMAKE: 3.10.1

The compile process aborts with...

c:\dev\libs\face-recognition.js\node_modules\dlib-build\dlib\dlib\dlib\dnn\core.h(698): fatal error C1003: error count exceeds 100; stopping compilation (compiling source file ..\cc\FaceRecognizerNet.cc) [C:\dev\libs\face-recognition.js\build\facerec.vcxproj]

With the first error being...

Severity Code Description Project File Line Suppression State Error C2995 'alwaysbool<unknown-type>::type dlib::impl::backward_requires_forward_output(layer_type &,SUBNET &)': function template has already been defined (compiling source file ..\cc\index.cc) facerec c:\dev\libs\face-recognition.js\node_modules\dlib-build\dlib\dlib\dlib\dnn\core.h 238

I'm not familiar with C++ development, so i'm not sure where to start looking.

Unable to install

First of all, great looking lib

Every time I try to install it gets stuck on extract:face-recognition: sill extract face-recognition@

node: 9.2.0
npm: 5.6.0
macOS: High Sierra 10.13.2

How to use the lib with ionic3 enviromnt?

Hi,
I am developing an ionic app, and I want to use this lib,
but i can not include it.
and i searched in the web, but i did not find any example

please could you help me.
thank you so much.

Problems with npm install and windows

Node: 8.9.1
OS: Windows 10, 64bit, v1709
Microsoft Build Engine version: 14.0.24720.0
CMAKE: 3.11.0-rc1

I just tried to install face-recognition and I receive this error:

> gyp ERR! build error gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 10.0.16299
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Rafael Albuquerque\Documents\workspace\visao\node_modules\face-recognition
gyp ERR! node -v v8.9.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:`

I have both node-gyp and rebuild installed globally.
Also, during the install, I receive a lot of warnings.
Ex:
c:\users\rafael albuquerque\documents\workspace\visao\node_modules\face-recognition\cc\FaceRecognizerNet.h(2): fatal error C1083: Not possible open the file include:: 'dlib/dnn.h': No such file or directory (compilando arquivo de origem ..\cc\FaceRecognizerNet.cc) [C:\Users\Rafael Albuquerque\Documents\workspace\visao\node_modules\ face-recognition\build\facerec.vcxproj]

How to extract the faces and save it?

I tried to detect face and save it but it's not working.

This is my code:

const fr = require('face-recognition')

const image = fr.loadImage('images\\IMAG1020.jpg');

const detector = new fr.FrontalFaceDetector();
const gotBig = fr.pyramidUp(image);
const gotFaceRects = detector.detect(gotBig);

const f = 0.5;
const faceRects = gotFaceRects.map(rect => new fr.Rect(rect.left * f, rect.top * f, rect.right * f, rect.bottom * f));

const win = new fr.ImageWindow();
win.setImage(image);
faceRects.forEach((rect, i) => {
	win.addOverlay(rect);
	**fr.saveImage(rect, `face_${i}.png`);**
});
fr.hitEnterToContinue();

I know from your example using "FaceDetector" instead of "FrontalFaceDetector", I think it make an error "Error: Save_Image - Error: expected argument 0 to be of type string".

I can find all faces but I don't know how to save it, please advise.

Thanks,
Thang Dinh

Distance is growing as I add more faces

Hi again :)

I am a little confused by the results that I am getting. The more faces I add to a class, the longer the distance get.

  1. If I add just two faces, and use one the those faces to make a prediction. The distance is non-zero. As I understand it the distance whould be 0, as that exact face exists in one of the classes. Instead I get like 0.7 for each of the photos.

  2. As I continue adding faces to these two classes and keep predicting some other faces that are not added in any class, the distances keep growing the more faces I add.

I am not sure how to interpret these results.

I am trying to build a photo service where users will add faces to people and the system should offer suggestions of other photos in their collection that most likely also is these people, but as the distances grow I am not sure how to handle the confidence score of the predictions.

My assumptions was that as I add more faces, the distances would get reduced as the recognizer gets more data and can make more accurate predictions.

Any tips?

Install issue MacOS (High Sierra)

Hello thanks for your work.
However I have some issue to install via the npm install face-recognition.
I am getting the following error:
CMake Error: Could not create named generator Visual Studio 15 2017 Win64

I believe it is due to the latest OS based code of justadudewhohacks/npm-dlib-build@b8c17de not published on npm.

OS: MacOS High Sierra
npm version: 5.6.0
node version: 8.9.4

Can't wait to test this lib, thanks!

face detection using webcam

Hi,

can u pls let me know how to detect the face from webcam for face recognition. I tried the code but somehow am stuck

Pls suggest

[feature] Support for binary buffers in loadImage

Hi. I don't know if it's possible to add support for buffers in loadImage or some new function. I've looked through the code and it seems that files reading is handled inside dlib and I didn't find any easy way to do a quick PR.

This feature could be utilized in cases when images are stored not on disk (so previously you will get them from somewhere) or images could be preprocessed. So, in this case, they will be loaded into memory as Buffer and storing them to disk and then performing cleanup will add unnecessary overhead.

How can i save recognized faces?

Hi. Thank you for you amazing library. I have some questions.

  1. How can i save images after const faceImages = detector.detectFaces(image); ??
  2. Is there some way to view the whole image with recognized faces in rectangles? Like in your examples and of course save them?

CvImage from cvMat with only one channel

Hi!
I'm working with a one channel buffer that contains only the luminance part of the image and would like to use FaceDetector.locateFaces.

The issue that I encountered is that CvImage expects only a cv.Mat with 3 channels:

const mat = new cv.Mat(buffer, height, width, cv.CV_8UC1);
const image = fr.CvImage(mat);
const detector = new fr.FaceDetector()
detector.locateFaces(image); // -> outputs no faces (there are 2)

const win = new fr.ImageWindow();
win.setImage(image); // -> will display a squashed version of the image, repeated 3 times on the horizontal axis.

As a workaround, one can duplicate the channel 3 times in order to fill the gap:

const fakeRGB = Buffer.alloc(buffer.length * 3);
for (let i = 0, j = 0; i < buffer.length; i++, j += 3) {
      fakeRGB[j + 0] = buffer[i];
      fakeRGB[j + 1] = buffer[i];
      fakeRGB[j + 2] = buffer[i];
}
const cvMat = new cv.Mat(fakeRGB, height, width, cv.CV_8UC3);
const cvImage = new fr.CvImage(cvMat);

detector.locateFaces(cvImage); // -> expected output
const win = new fr.ImageWindow();
win.setImage(image);  // -> normal image

Is there any other way around this that is less taxing because of the conversions?

Performance question

Hi again, sorry for bothering you with these questions :)

I was just wondering if it is normal to get 800-1000ms when calling locateFaces on an image downsized to 500px height. It just seems a lot to me having seen live face detections on video cameras. I am on a MacBook Pro (Retina, Mid 2012).

Any idea if this is normal or it I might be having some issue that slows down the performance ?

Big Size Images makes computer slow

I am not sure if this is a library issue or machine issue (tried it on 2 powerful computers with different OS windows + ubuntu but same result).
Anyways, the first try with a simple images 600x400, size around 100kb-250kb and the detecting faces result was just after 7sec which is a lot for me since I am going to detect thousands of faces.

  • Using sizes like 500-999kb takes 1-2min to detect the faces
  • Over 1MB, huge problems computer get slower and for an image 2-3MB the computer stopped working.

Well, I know I can resize the image before detecting the face, I just wanted to know this issue where is coming from, is it normal or just me ... note this only detecting fr.FaceDetector() I didn't even start to recognize faces

Unable to install on 32-bit Windows OS

Hi,
I need to build my project for 32-bit systems.
Hence I have built dlib for 32-bit Windows and have set the DLIB_INCLUDE_DIR & DLIB_LIB_DIR in windows PATH variable.
But I am getting following error:

C:\face-detector>npm i [email protected]

[email protected] install C:\face-detector\node_modules\dlib-build
node ./install.js

found dlib
DLIB_INCLUDE_DIR: C:\prj\dlib_build_release\include
DLIB_LIB_DIR: C:\prj\dlib_build_release\lib

[email protected] install C:\face-detector\node_modules\face-recognition
node-gyp rebuild

C:\face-detector\node_modules\face-recognition>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_
modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_mo
dules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )

gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: win-x86/node.lib local checksum 4514e8d359637abcf994f36fc110b956c73344e761773de5e9c72a0cccec59b5 not match remote
c4edece2c0aa68e816c4e067f397eb12e9d0c81bb37b3d349dbaf47cf246b0b7
gyp ERR! stack at deref (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\install.js:266:20)
gyp ERR! stack at Request. (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\install.js:384:24)
gyp ERR! stack at emitOne (events.js:121:20)
gyp ERR! stack at Request.emit (events.js:211:7)
gyp ERR! stack at IncomingMessage. (C:\Program Files\nodejs\node_modules\npm\node_modules\request\request.js:1085:12)
gyp ERR! stack at Object.onceWrapper (events.js:313:30)
gyp ERR! stack at emitNone (events.js:111:20)
gyp ERR! stack at IncomingMessage.emit (events.js:208:7)
gyp ERR! stack at endReadableNT (_stream_readable.js:1055:12)
gyp ERR! stack at _combinedTickCallback (internal/process/next_tick.js:138:11)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node
-gyp.js" "rebuild"
gyp ERR! cwd C:\face-detector\node_modules\face-recognition
gyp ERR! node -v v8.9.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1

OS: Windows 7, 32-bit
Node: v8.9.4
npm: 5.6.0

how to compare face descriptor values for face recognition

Hi,

We are able to extract face descriptor values(128 parameters) from the image and store it in JSON file.

While face recognition, we need to extract face coordinates from the json file and compare it with the existing face coordinates.

I could not find the relavant method how to compare two face coordinates for face recognition.

Please suggest the way forward

Thank you.

Error in FaceRecognizer - Error: expected argument 0 to be of type ImageRGB

Hi Vincent ,

I am trying to run sample code for face recognition in the page ( https://github.com/justadudewhohacks/face-recognition.js) .
I have done small changes as per local images i have . I have downloaded images from internet .

My code :

const fr = require('face-recognition');

const detector = fr.FaceDetector();

console.log("Loading  viraat images ");
const img1 = fr.loadImage('./viraatkohli.png');
const img2 = fr.loadImage('./viraatkohli2.png');

const vimg1  = detector.detectFaces(img1);
const vimg2  = detector.detectFaces(img2);

let  viraat_faces = [ ] ;
viraat_faces.push(vimg1);
viraat_faces.push(vimg2);

console.log("Loading  smith images ");
const smimg1 = fr.loadImage('./smith.png');
const smimg2 = fr.loadImage('./stevesmith2.png');

const vimg3  = detector.detectFaces(smimg1);
const vimg4  = detector.detectFaces(smimg2);

//const smith_faces = [ vimg3, vimg4] ;
let smith_faces = [];
smith_faces.push(vimg3);
smith_faces.push(vimg4);

console.log("Loading msd images ");
const msimg1 = fr.loadImage('./msdhoni.png');
const msimg2 = fr.loadImage('./msdhoni2.png');

const vimg5  = detector.detectFaces(msimg1);
const vimg6  = detector.detectFaces(msimg2);
let dhoni_faces = [];
dhoni_faces.push(vimg5);
dhoni_faces.push(vimg6);

const recognizer = fr.FaceRecognizer();

const numJitters = 15
recognizer.addFaces(smith_faces, 'smith',numJitters);
recognizer.addFaces(viraat_faces, 'viraat',numJitters);
recognizer.addFaces(dhoni_faces, 'msd',numJitters); 


console.log("running prediction");
const msimg3 = fr.loadImage('./msdhoni3.jpg');

const faceImage = detector.detectFaces(msimg3);
const predictions = recognizer.predictBest(faceImage);
console.log(predictions);


I get following stack trace .

 node starter3.js
Loading  viraat images
Loading  smith images
Loading msd images
D:\face_recognition_node\node_modules\face-recognition\lib\src\FaceRecognizer.js:59
      return [face].concat(!numJitters ? [] : fr.jitterImage(face, numJitters))
                                                 ^

Error: JitterImage - Error: expected argument 0 to be of type ImageRGB
    at getJitteredFaces (D:\face_recognition_node\node_modules\face-recognition\lib\src\FaceRecognizer.js:59:50)
    at faces.map.f (D:\face_recognition_node\node_modules\face-recognition\lib\src\FaceRecognizer.js:81:24)
    at Array.map (<anonymous>)
    at Object.addFaces (D:\face_recognition_node\node_modules\face-recognition\lib\src\FaceRecognizer.js:81:15)
    at Object.<anonymous> (D:\face_recognition_node\starter3.js:43:12)
    at Module._compile (module.js:643:30)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
 node starter3.js
Loading  viraat images
Loading  smith images
Loading msd images
D:\face_recognition_node\node_modules\face-recognition\lib\src\FaceRecognizer.js:59
      return [face].concat(!numJitters ? [] : fr.jitterImage(face, numJitters))
                                                 ^

Do i need some kind of image processing to convert images into RGB format ?

Regards
Tanmay

Load image from base64 or canvas?

Can I load image only from specific path? Or is there some other way for example base64 or canvas or something else connected with js variables? It would help me so much.

Any way to create ImageRGB object from Buffer ?

Hi!

This is more of a question. Trying to figure out how to create ImageRGB object without reading from disk, but cant figure out what an ImageRGB really is.

Any idea of how I could make the FaceRecognizer.AddFaces function support a buffer, or how to make an ImageRGB from a buffer or stream. Would be nice to not have to write stuff to disk, just to read it up again.

Make libX11 dependency optional

Hi. I saw that in some issues you've mentioned that GUI dependency could be optional. That will be great and it will also allow reducing docker images size.
E.g. it could check if dlib is built with DLIB_NO_GUI_SUPPORT=ON.

using faceLandmark5Model as the default for FaceDetector

Hi Vincent,

Trust you are doing well.

Was reading DavisKings blog (http://blog.dlib.net/2017/09/fast-multiclass-object-detection-in.html) and saw this -

Unlike the 68-point landmarking model included with dlib, this model is over 10x smaller at 8.8MB compared to the 68-point model's 96MB. It also runs faster, and even more importantly, works with the state-of-the-art CNN face detector in dlib as well as the older HOG face detector in dlib. The central use-case of the 5-point model is to perform 2D face alignment for applications like face recognition. In any of the dlib code that does face alignment, the new 5-point model is a drop-in replacement for the 68-point model and in fact is the new recommended model to use with dlib's face recognition tooling.

The example that he has also uses 5-point model.
https://github.com/davisking/dlib/blob/master/examples/dnn_face_recognition_ex.cpp

At present, you are pre-creating the FaceDetector object in index.js https://github.com/justadudewhohacks/face-recognition.js/blob/master/lib/index.js#L13 with 68-point model.

Based on what I have seen, there is nothing that prevents me to create the detectors in my app code (since you have properly parameterized the lower layers i.e. FaceDetector/index.js does take the model as an input) however based on Davis King's blog do you think it makes sense to

  • parameterize at the highest level (i.e. in index.js as well) for the objects created by the library
  • change the default model to "models.faceLandmarks5Model" instead of "models.faceLandmarks68Model"

Regards & thanks
Kapil

Cant get dlib to run on AWS Lambda when compiling with OpenBLAS.

Howdy!

I got the library working as a AWS Lambda function. I compiled it using their amazonlinux docker container, but as before the performance is really bad without the OpenBLAS support so i installed it using their yum package manager. Tried using blas, openblas, blas-devel and openblas-devel, openblas-static and also lapack and lapack-devel, but I keep ending up with these kind of errors:

libblas.so.3: cannot open shared object file: No such file or directory

or

libopenblas.so.0: cannot open shared object file: No such file or directory

when building the library (iside the amazonlinux docker container) i get this message at the end that makes me believe that the dependencies are not built statically:

Linking CXX shared library libdlib.so
[100%] Built target dlib_shared

or could it be some kind of path issue ?

the libpng and libX11 libraries doesn't seem to have any issues, and i don't really know the difference as the those are also installed using yum as the packages libX11-devel and libpng-devel.

feels like i somehow need to make sure that the openblas library is packaged together with dlib in my node_modules directory or some other way accessible when running in the lambda environment.

any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.