nischi / MMM-Face-Reco-DNN

Face recognition with opencv and deep neural network
MIT License
91 stars 46 forks source link

Not detecting faces with MagicMirror #18

Closed Keyes closed 4 years ago

Keyes commented 4 years ago

I cannot get the facial recognition to work. The messaages/plugins in magic mirror are not switched at all, only "default everyone" plugins are shown. When I open tools/facerecognition.py manually, I can see the camera feed and my face being recognized correctly, but apparently I doesn't work with MM.

Is there a way to enable some additional logging or something?

I'm using a raspberry pi 4 with 1gigs of ram and OpenCV 4.1

nischi commented 4 years ago

do you installed ocv in a virtual environemnt?

djmobeus commented 4 years ago

Hi nischi, I'm having the same problem. OCV installed in virtual environment, I'm using a pi camera and when I run facerognition.py all faces get detected properly, when I launch MM only default modules are shown but when I look in to camera no other modules appear.

Any suggestions would be much appreciated.

Thanks

Keyes commented 4 years ago

do you installed ocv in a virtual environemnt?

yes, OpenCV is installed in a virtual environment and linked to the "outside"

djmobeus commented 4 years ago

I have just finished performing a full wipe of my pi and full reinstall of MM and everything needed to make sure that I didn't miss anything the first time. MM still only shows default modules, nothing happens while looking at camera within MM but running facerecognition.py works.

Any ideas?
Thanks

nischi commented 4 years ago

Have you set the python path correctly with the setting "pythonPath"? Otherwise it will run with the python of the magic mirror which can have some issues?

otherwise send me shortly your full config and i will check.

djmobeus commented 4 years ago

Thanks for getting back to me.

I’m quite new to python and Linux.

I’ve pretty much followed the directions on your readme and the opencv site.

How can I check that the pythonPath is correct and do you want the full config for MM?

I can send you anything you need within the next few minutes.

Thanks

nischi commented 4 years ago

If you run your virtual environment you could run following command to get the python path which you need to configure in the setting pythonPath of my module which python3

djmobeus commented 4 years ago

That was it! I've been going through the config file over and over and I just kept on missing that.

BRILLIANT!

Keyes commented 4 years ago

Still no change on my side.

Here is my config:

modules: [
    {
        module: 'MMM-Face-Reco-DNN',
        config: {
            pythonPath: "/home/pi/.virtualenvs/cv/bin/python3"
        }
    },
    /* ... */
]   

This is the python path I get when I enter the virtual environment (workon cv) and look up the python path (which python 3)

nischi commented 4 years ago

so do you get no error message in the log, right? have you tried to open MagicMirror in dev mode?

If you want to debug on Raspberry Pi you can use npm start dev which will start MM with Dev Tools enabled.

how you set the classes on the other modules?

djmobeus commented 4 years ago

incase this helps anybody. This is what I've added in the config file

{ module: 'MMM-Face-Reco-DNN', classes: "default everyone", config: { // Logout 15 seconds after user was not detecte anymore, if they will be detected between this 15 Seconds, they delay will start again logoutDelay: 15000, // How many time the recognition starts, with a RasPi 3+ it would be good every 2 seconds checkInterval: 2000, // Module set used for strangers and if no user is detected defaultClass: 'default', // Set of modules which should be shown for every user everyoneClass: 'everyone', // XML to recognize with haarcascae cascade: 'modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml', // Pre encoded pickle with the faces encodings: 'modules/MMM-Face-Reco-DNN/tools/encodings.pickle', // You wanna use pi camera or usb / builtin (1 = raspi camera, 0 = other camera) usePiCamera: 1, // Method of face detection (dnn = deep neural network, haar = haarcascade) method: 'dnn', // Which face detection model to use. "hog" is less accurate but faster on CPUs. "cnn" is a more accurate deep-learning model which is GPU/CUDA accelerated (if available). detectionMethod: 'hog', // How fast in ms should the modules hide and show (face effect) animationSpeed: 0, // Path to Python to run the face recognition (null / '' means default path) pythonPath: '/home/pi/.virtualenvs/cv/bin/python3', // Should shown welcome message over alert module from MagicMirror welcomeMessage: true, // Save some pictures from recognized people, if unknown we save it in folder "unknown" // So you can extend your dataset and retrain it afterwards for better recognitions extendDataset: false, // if extenDataset is set, you need to set the full path of the dataset dataset: 'modules/MMM-Face-Reco-DNN/dataset/' } },

and for each module I have just added this classes: "default everyone" or classes: "John" for a specific user

Keyes commented 4 years ago

I started MM with npm start dev and it turned out it was missing some python modules (for whatever reason I don't know, I'm sure I installed them) - but: Now the log is looking good, but still not detecting faces.

Here is the log:

(cv) pi@mirrorpi:~/MagicMirror $ npm start dev

> magicmirror@2.9.0 start /home/pi/MagicMirror
> sh run-start.sh "dev"

Starting MagicMirror: v2.9.0
Loading config ...
Loading module helpers ...
Initializing new module helper ...
Module helper loaded: MMM-Face-Reco-DNN
No helper found for module: helloworld.
No helper found for module: alert.
Initializing new module helper ...
Module helper loaded: updatenotification
No helper found for module: clock.
Initializing new module helper ...
Module helper loaded: MMM-MoonPhase
No helper found for module: currentweather.
No helper found for module: weatherforecast.
All module helpers loaded.
Starting server on port 8080 ... 
Server started ...
Connecting socket for: MMM-Face-Reco-DNN
Starting module helper: MMM-Face-Reco-DNN
Connecting socket for: updatenotification
Connecting socket for: MMM-MoonPhase
Starting module helper: MMM-MoonPhase
Sockets connected & modules started ...
Launching application.
[MMM-Face-Reco-DNN] loading encodings + face detector...
[MMM-Face-Reco-DNN] starting video stream...
nischi commented 4 years ago

can you send me the full config file?

Keyes commented 4 years ago
/* Magic Mirror Config Sample
 *
 * By Michael Teeuw http://michaelteeuw.nl
 * MIT Licensed.
 *
 * For more information how you can configurate this file
 * See https://github.com/MichMich/MagicMirror#configuration
 *
 */

var config = {
    address: "localhost", // Address to listen on, can be:
                          // - "localhost", "127.0.0.1", "::1" to listen on loopback interface
                          // - another specific IPv4/6 to listen on a specific interface
                          // - "", "0.0.0.0", "::" to listen on any interface
                          // Default, when address config is left out, is "localhost"
    port: 8080,
    ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
                                                           // or add a specific IPv4 of 192.168.1.5 :
                                                           // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
                                                           // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
                                                           // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],

    language: "en",
    timeFormat: 24,
    units: "metric",

    modules: [
        {
                module: 'MMM-Face-Reco-DNN',
            classes: "default everyone",
                config: {
                pythonPath: "/home/pi/.virtualenvs/cv/bin/python3"
            }
        },
        {
                        module: "helloworld",
                        position: "bottom_bar", // This can be any of the regions.
                        config: {
                                text: "Testmessage!"
                        },
                        classes: "default everyone"
                },
        {
                        module: "helloworld",
                        position: "bottom_bar", // This can be any of the regions.
                        config: {
                                text: "Default Testmessage!"
                        },
                        classes: "default"
                },
        {
                        module: "helloworld",
                        position: "bottom_bar", // This can be any of the regions.
                        config: {
                                text: "Everyone Testmessage!"
                        },
                        classes: "everyone"
                },
        {
            module: "helloworld",
            position: "bottom_bar", // This can be any of the regions.
            config: {
                text: "Hello Julian!"
            },
            classes: "julian"
        },
        {
            module: "alert",
            classes: "default everyone"
        },
        {
            module: "updatenotification",
            position: "top_bar",
                        classes: "default everyone"
        },
        {
            module: "clock",
            position: "top_left",
                        classes: "default everyone"
        },
        {
            module: "MMM-MoonPhase",
            position: "top_center",
            config: {
                updateInterval: 43200000,
                hemisphere: "N",
                resolution: "detailed",
                basicColor: "white",
                title: false,
                phase: false,
                x: 100,
                y: 100,
                alpha: 0.6
            },
                        classes: "default everyone"
        },
        {
            module: "currentweather",
            position: "bottom_left",
            config: {
                location: "XXXXXXXXX",
                locationID: "XXXXXX",  //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
                appid: "XXXXXXXX",
                showHumidity: true,
                useKMPHwind: true,
                showWindDirectionAsArrow: false
            },
                        classes: "default everyone"
        },
        {
            module: "weatherforecast",
            position: "bottom_left",
            header: "Weather Forecast",
            config: {
                location: "XXXXXXX",
                locationID: "XXXXX",  //ID from http://bulk.openweathermap.org/sample/city.list.json.gz; unzip the gz file and find your city
                appid: "XXXXXXXXXXXXXX",
                showRainAmount: true,
                maxNumberOfDays: 5,
                forecastEndpoint: "forecast"
            },
                        classes: "default everyone"
        }
    ]

};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}
nischi commented 4 years ago

can you remove classes from my module? because it has no output, it's not needed. maybe thats the problem.

Keyes commented 4 years ago

I added the classes after seeing @djmobeus' config, and it wasn't working before - but I will try that again later

Keyes commented 4 years ago

Just as I thought - no change here without classes

nischi commented 4 years ago

have you once tried to comment out all other modules? maybe leave the clock and do your name to the classes.

Keyes commented 4 years ago

I just tried this, no result. I also tried the development mode again, and there is no further output after „starting video stream...“, while facedetection.py still recognizes me :/

nischi commented 4 years ago

but i do not see any issue. thats strange. possible to test only my module with a clean magic mirror installation? Sorry i know thats annoying but i try to figure out whats wrong.

nischi commented 4 years ago

Please reopen the issue if we should go further.