face-recognition.js icon indicating copy to clipboard operation
face-recognition.js copied to clipboard

recognizer.addFaces gives "Process finished with exit code -529697949"

Open ArnabBanerji opened this issue 7 years ago • 4 comments

I am creating an array of ImageRGB and I have a unique name to be added.

const fr = require('face-recognition');
const fs = require('fs');
const recognizer = fr.FaceRecognizer();
const fileDataFaceMapped = require('./fileDataFaceMapped.json'); //Contains Data

/*
* Example:
* [
    {
        "file_id": 0,
        "filePath": ".//24th evening-D800E/DSC_7417.JPG",
        "fileName": "DSC_7417.JPG",
        "tags": [
            "24th evening-D800E",
            "24th",
            "evening-D800E",
            "evening",
            "D800E",
            "PersonA",
            "PersonB",
            "PersonC"
        ],
        "outputFileName": "./web-album/24th_evening_D800E_DSC_7417.jpg",
        "outputThumbnailFileName": "./web-album/thumbnails/24th_evening_D800E_DSC_7417.jpg",
        "resizeComplete": true,
        "complete": true,
        "faces": [
            {
                "confidence": 1.0591269731521606,
                "rect": {
                    "area": 18906,
                    "bottom": 586,
                    "top": 450,
                    "right": 835,
                    "left": 698
                },
                "outputFileName": "./faces-db/0_0.jpg",
                "personName": "PersonA"
            },
            {
                "confidence": 0.9910643100738525,
                "rect": {
                    "area": 18906,
                    "bottom": 545,
                    "top": 408,
                    "right": 1512,
                    "left": 1376
                },
                "outputFileName": "./faces-db/0_1.jpg",
                "personName": "PersonB"
            },
            {
                "confidence": 0.5483637452125549,
                "rect": {
                    "area": 27060,
                    "bottom": 648,
                    "top": 484,
                    "right": 587,
                    "left": 424
                },
                "outputFileName": "./faces-db/0_2.jpg",
                "personName": "PersonC"
            }
        ],
        "width": 1618,
        "height": 1080,
        "facesExtracted": true
    }
*]
* */

const faceModelFile = './faceModel.json';

const ignoreNames = ['unknown']; //any name matching with an element in this array will be ignored.

const numJitters = 2;


function mapNameToFile() {
    let faceImageMap = {};
    for (let i = 0; i < fileDataFaceMapped.length; i++) {
        let file = fileDataFaceMapped[i];

        let faces = file.faces || [];

        for (let j = 0; j < faces.length; j++) {
            let face = faces[j];
            if (face.personName && (ignoreNames.indexOf(face.personName.toLowerCase()) === -1)) {
                faceImageMap[face.personName] = faceImageMap[face.personName] || [];
                faceImageMap[face.personName].push(face.outputFileName);
            }
        }
    }
    return faceImageMap;
}


function init() {
    let faceImageMap = mapNameToFile();
    fs.writeFileSync('./mapNameToFile.json', JSON.stringify(faceImageMap, null, 4));
    console.log('mapNameToFile written!');

    for (let name in faceImageMap) {
        console.log('Name :: ' + name);
        let files = faceImageMap[name];
        let imgArr = [];
        let imageLimit = Math.min(files.length, 1); //To Minimize Images to be added to see if crashing stopped.
        for (let i = 0; i < imageLimit; i++) {
            let file = files[i];
            let timeStr = 'Loading ' + file;
            console.time(timeStr);
            let fileImage = fr.loadImage(file);
            imgArr.push(fileImage);
            console.timeEnd(timeStr);
        }
        let timeStrFaceAdd = 'Adding faces for ' + name;
        console.time(timeStrFaceAdd);
        recognizer.addFaces(imgArr, name);
        console.timeEnd(timeStrFaceAdd);

    }
    const modelState = recognizer.serialize();
    let timeStr = 'Writing model.';
    console.time(timeStr);
    fs.writeFileSync(faceModelFile, JSON.stringify(modelState, null, 4));
    console.timeEnd(timeStr);
}

init();

ArnabBanerji avatar Apr 14 '18 21:04 ArnabBanerji

Same :(

nullmastermind avatar Jul 04 '18 16:07 nullmastermind

I was getting the same error. I tried something and it worked (kind of). The thing is that if your face image files are less than 100x100 (min width 100, min height 100), it throws this error. I devised a way to avoid faces that are less than these specs. Do let me know if this worked!

ArnabBanerji avatar Jul 04 '18 17:07 ArnabBanerji

Ahh yes, the smallest size I was able to use were 105x105 sized images. Everything below that size seems to crash the application.

justadudewhohacks avatar Jul 04 '18 19:07 justadudewhohacks

Tks ArnabBanerji . It worked.

nullmastermind avatar Jul 04 '18 23:07 nullmastermind