GithubHelp home page GithubHelp logo

mmm-face-reco-dnn's Introduction

Face Recognition with Open CV

This module detects and recognizes your face for MagicMirror².

With this module you can show and hide all other modules depending on which person is recognized. For example, if you are in front of the mirror, the mirror will show you your agenda, but if a stranger is in front, the agenda will not be shown.

Screenshot

This module works in the background, and so no screenshots are available.

Dependencies

Installation

The installation is much more simplified now. You can run npm ci to install all the node packages and after that it will install all packages with pip. This can take a while to compile the whole opencv stuff.

Be sure that your raspberry pi has enough cooling to do this job, it will be heavy used.

But that this is working you need installed system wide tools before:

  • node with nvm
    • install instructions
    • run nvm install --lts to install latest LTS version
    • run nvm use --lts to use latest LTS version
  • pip
    • sudo apt install python3-pip
  • libcap-dev
    • sudo apt install libcap-dev
  • install python dependencies
    • If you working with Bookworm you need to create first an virtual environment, please have a look in the next chapter
    • pip install face-recognition numpy dlib picamera2 opencv-python

Some additional steps for Bookworm and above to run it with an virtual environment

If you want/need to install it with an virtual environment, you need to do following steps before you install the packages with pip

  • create environment with python3 -m venv ~/python-facereco
  • activate environment with source ~/python-facereco/bin/activate
  • install pip packages with pip install face-recognition numpy dlib picamera2 opencv-python
  • Because some libraries uses global installed libs which are not available with pip, you need to change the config of your virtual environment
    • nano ~/python-facereco/pyvenv.cfg
    • Change line include-system-site-packages = false to include-system-site-packages = true

Install the Module

Load this module directly from GitHub using the following commands.

cd ~/MagicMirror/modules/
git clone https://github.com/nischi/MMM-Face-Reco-DNN.git
cd MMM-Face-Reco-DNN
npm install

Face Dataset

First of all you need to create your face dataset. The module is preconfigured such that you store your dataset in the folder dataset in the root of the module. It is possible to use another folder if you want to.

Put each person in a seperate subdirectory like this:

- dataset
  - thierry
    - img01.jpg
    - img02.jpg
    - img03.jpg
  - adam
    - img01.jpg
    - img02.jpg
    - img03.jpg
  - james
    - img01.jpg
    - img02.jpg
    - img03.jpg
  - john
    - img01.jpg
    - img02.jpg
    - img03.jpg

It's enough if you have around 10 pictures for each person. Try to use pictures in different settings and lighting if possible as it may help to build a better model of the person's face.

Facial Recognition Embeddings

After you set up your dataset, we need to go to the embeddings for the recognitions. I prepared a script for that. It took a while to run on my Macbook and will take much longer on a Raspberry Pi, so if possible, use it on a computer with more power and then transfer the resulting file.

You will find a script called encode.py in folder tools of the module. You can simply run following command:

npm run encode

After that you are ready to configure the module and use it on your MagicMirror.

Module Usage

To setup the module in MagicMirror², add the following section to the config.js file in the MagicMirror/config directory.

{
    module: 'MMM-Face-Reco-DNN',
    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 when there is no face detected ie no one is in front of the camera
      noFaceClass: 'noface',
      // Module set used for when there is an unknown/unrecognised face detected
      unknownClass: 'unknown',
      // Module set used for when there is a known/recognised face detected
      knownClass: 'known',
      // Module set used for strangers and if no user is detected
      defaultClass: 'default',
      // Set of modules which should be shown for any user ie when there is any face detected
      everyoneClass: 'everyone',
      // Set of modules that are always shown - show if there is a face or no face detected
      alwaysClass: 'always',
      // xml to recognize with haarcascade
      cascade: 'modules/MMM-Face-Reco-DNN/model/haarcascade_frontalface_default.xml',
      // pre encoded pickle with the faces
      encodings: 'modules/MMM-Face-Reco-DNN/model/encodings.pickle',
      // Brightness (0-100)
      brightness: 0,
      // Contrast (0-127)
      contrast: 0,
      // Rotate camera image (-1 = no rotation, 0 = 90°, 1 = 180°, 2 = 270°)
      rotateCamera: -1,
      // method of face recognition (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). The default is "hog".
      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, with Bookworm you need to set the virutal environment like /home/youruser/python-facereco/bin/python3. You can also find out the correct path if you are activated the virtual environment and run "which python3")
      pythonPath: null,
      // Boolean to toggle welcomeMessage
      welcomeMessage: true,
      // Dictionary for person name mapping in welcome message
      // Allows for displaying name with complex character sets in welcome message
      // e.g. jerome => Jérôme, hideyuki => 英之, mourad => مراد
      usernameDisplayMapping: null,
      // 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/',
      // How much distance between faces to consider it a match. Lower is more strict.
      tolerance: 0.6,
      // allow multiple concurrent user logins, 0=no, any other number is the maximum number of concurrent logins
      multiUser: 0,
      // resoltuion of the image
      resolution: [1920, 1080],
      // width of the image for processing
      processWidth: 500,
      // output image on mm
      outputmm: 0,
      // turn on extra debugging 0=no, 1=yes
      debug: 0,
    }
}

Notifications

The module sends notifications if a user is logged in or logged out. In addition you can request the list of logged-in users to check if somebody is in front of the mirror. You can then use it for your own module, such as MMM-MotionControl.

Notification Direction Description
USERS_LOGIN out Sent if new users are detected in front of the mirror
USERS_LOGOUT out Sent if users leave the camera's view
LOGGED_IN_USERS out All logged in (in front of mirror) users
GET_LOGGED_IN_USERS in Request all logged in users

Facial Recognition States

There are 3 states that of facial recogntion that this module runs in. The states are not directly configurable but rather you use the classes to define which modules are activated in the various states.

State Description
noface This is the state when facial recognition has found no faces
unknown This is the state when facial recognition has found a face that it does NOT recognise
known This is the state when facial recognition has found a face that it does recognise

Classes

In order for this module to do anything useful you have to assign classes to your modules. Do not set any classes on this module itself, it has no output and will not work.

There are a series of classes that drive the showing/hiding of modules based on the state of facial recognition. The following table gives a view of which classes drive which states.

When a state changes, the classes from the old state are hidden and the classes from the new state are shown. Anytime that a specific class appears in both states, nothing happens to the modules tagged with that specific class.

For example:

  • starting from no faces detected, when an unknown face is detected, any modules tagged with the noface class will disappear and any modules tagged with the unknown class will appear.
  • starting from no faces detected, when an unknown face is detected, any modules tagged with the default class will remain unchanged, because default provides both the Noface and the Unknown states.
  • starting from no faces detected, when an known face is detected, any modules tagged with the default class will be hidden and modules tagged with known or "specific user's name" ie to specify modules for a certain user, use their name as the class name

The state to class mappings are:

States that the class is active in
Class Noface Unknown Known
noface Y
unknown Y
known Y
default Y Y
everyone Y Y
always Y Y Y
"specific user's name" Y
{
    module: 'example_module',
    position: 'top_left',
    // Set your classes here seperated by a space
    // Always shown
    classes: 'always'
},
{
    module: 'example_module_2',
    position: 'top_left',
    // Only shown for Thierry and James
    classes: 'thierry james'
},
{
    module: 'example_module_3',
    position: 'top_right',
    // Only shown for James
    classes: 'james'
}
{
    module: 'example_module_4',
    position: 'top_right',
    // Only shown for known (recognised users)
    classes: 'known'
}

Known Issues

  • Support for multiple concurrently logged in users is not yet complete.

mmm-face-reco-dnn's People

Contributors

4p3rtur3 avatar anderm3 avatar camillemarius avatar chrizzz90 avatar danth avatar dependabot[bot] avatar dvbit avatar hknozturk avatar horstbaerbel avatar jimbydude avatar majurgens avatar michlf avatar nischi avatar nischiemineo avatar njoerd114 avatar njwilliams avatar paultranvan avatar peterbaumert avatar pierrephi avatar sergge1 avatar x3mer 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mmm-face-reco-dnn's Issues

cant make docker file

Im getting this error.
please anyone share the solution
pi@raspberrypi:~/MagicMirror/modules/MMM-Face-Reco-DNN/tools $ make
docker build --build-arg UID=1000 --build-arg GID=1000 -t mmm-face-reco-dnn-dataset-runner .
make: docker: Command not found
make: *** [Makefile:6: image] Error 127

Question about recognized or not while logged in

So I got this working today and is working quite well...

My question is ...

My config has Myself (only person in my dataset) and default for modules to show.

When I come into detection not recognized (because I hold my fingers up to my face)...the modules show correctly for Default.
When I remove my hand from my face... the mirror (2 seconds or so) recognizes me and shows my additional modules.

But .. while I am "logged in" when I put my fingers up to my face again to be unrecognized the modules do not go away that default should not see... so it is as if it is still recognizing me....

Shouldn't the modules go away in this instance because it checks for recognition every 2 seconds?

EDIT : nevermind it seems to be working now.... weird.

PiCamera vs others cameras

Hi @nischi,

In facerecognition.py script I see a --usePiCamera option, does this option increase performances compare to not using it?

I'm using the Pi Camera V2 module connected via the SPI connector but I can't use the picamera Python library because this library relies on the libmmal library which can't be used yet with the 64-bit versions.

Thanks for the great work. 👍

No pictures being taken with extendDataset: true

This seems to be a bigger issue since the modules are not updating but there are no pictures being taken and put in the "unknown" folder. opencv NOT installed in the virtual environment. Do I need to update a path for that?

Make image brighter

Hey,

I tried your module because I never got the old one working. I have one big problem and am not able to correct for this:
I have my picam mounted behind the mirror glass. With raspistill I can take reasonable good pictures, but with the opencv3 module I could only get very dark pictures. As far as I could find out the method of acquiring pictures is different.
Is there a way to boost brightness or contrast for the stream?

Best Regards,
Anduril

Failed reco's and pictures without anyone in front of the cam

I receive failed recognitions with a really different looking person and I saw that the module saves recognized pictures without anyone in front of the cam.

Is it possible that the picture resolution 640x480px is too low to create a database? Is there a way to increase the resolution?

Had pi one week and Face-Reco working great but

Please excuse me, I am not by any stretch of the imagination a coder in way, but I created a MM and installed your Module on it and it is working great on my pi3 B+.

Can I ask, how I would use your module to play a .WAV or .MP3 file when user is detected, I am also looking to add a Face Recon door lock. Any guidance would be appreciated

Great module and easy to follow guide, even for me. One week with Magic Mirror and a Pi.

No Detection

Hello I have completed the installation and now wanted to test the detection. Unfortunately, nothing happens, only the modules are displayed, which are visible to all. I think the camera is not recognized, something still needs to be changed if you do not use the Raspberry Pi camera, except the 1 in the config? I dont get any Fail Messages at Start.

ENABLE/DISABLE HELP

can i enable/disable the facial recognition modules using PIR sensors.
facial recognition is keeping camera busy all the time. so if i want to use camera for some other purpose its hard to do.

so is it possible ?

Thank you

Possibility to have face recognition run on another Server

Facerecognition is quite expensive in terms of CPU and Memory...

I'm thinking of running the whole thing on an external Pi/Spare Laptop and publish messages via MQTT... The module could just consume them and load would not be an issue anymore.

I'm going to look if I can modify the module to make this an option.

Python Type Checking and the face comparison script

I have an error happening when a face is detected. I made a post in the MM2 forum, and the only response I have so far is:

@KSumwalt it seems that python has added type checking, which it wasn’t using before.

there was another python related type checking problem a few days ago…

looks like the node_helper has launched the python script to compare the face files, and run into a problem checking the parms passed to it.

I have loaded the MMM-Face-Reco-DNN and even used the i_face_recognition.py from https://www.pyimagesearch.com/2018/06/25/raspberry-pi-face-recognition/ with the encodings file generated from the MMM-Face-Reco-DNN instructions and had that .py file recognize faces. So I backed everything out of my config file except the default MMM-Face-Reco-DNN settings from the instructions and when I manually start MM2 everything looks fine. I am running on a Raspberry Pi 4. I did install a different facial recognition module, but it was not in the config file and decided not to use it when I saw it only recognized 1 person. When I step in front of the camera, this comes up in the terminal where I manually started MM2:

[2020-08-09 00:59:28.399] [ERROR] Whoops! There was an uncaught exception...
[2020-08-09 00:59:28.400] [ERROR] PythonShellError: TypeError: ' (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
at ChildProcess.emit (events.js:200:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
----- Python Traceback -----
File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 143, in
if minDistance < args["tolerance"]: {
traceback: 'Traceback (most recent call last):\n File ' +
'"modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line ' +
'143, in \n if minDistance < args["tolerance"]:\n' +
"TypeError: '<' not supported between instances of " +
"'numpy.ndarray' and 'str'\n",
executable: 'python3',
options: null,
script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
args: [
'--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
'--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
'--usePiCamera=1',
'--source=0',
'--rotateCamera=0',
'--method=dnn',
'--detectionMethod=hog',
'--interval=2000',
'--output=0',
'--extendDataset=False',
'--dataset=modules/MMM-Face-Reco-DNN/dataset/',
'--tolerance=0.6'
],
exitCode: 1
}
[2020-08-09 00:59:28.409] [ERROR] MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
[2020-08-09 00:59:28.409] [ERROR] If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues

There is a little more information at the linked forum post, include the config file if you need it. Is there any assistance you can provide?

Kindest Regards,
Karl Sumwalt

Cannot install face_recogniton

I cannot install the facial_recognition dependency.

pi@raspberrypi:~ $ pip install face_recognition
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting face_recognition
  Using cached https://files.pythonhosted.org/packages/3f/ed/ad9a28042f373d4633fc8b49109b623597d6f193d3bbbef7780a5ee8eef2/face_recognition-1.2.3-py2.py3-none-any.whl
Requirement already satisfied: dlib>=19.7 in ./.virtualenvs/cv/lib/python3.5/site-packages (from face_recognition) (19.17.0)
Collecting face-recognition-models>=0.3.0 (from face_recognition)
  Downloading https://www.piwheels.org/simple/face-recognition-models/face_recognition_models-0.3.0-py2.py3-none-any.whl (100.6MB)
     |█████▎                          | 16.6MB 6.9MB/s eta 0:00:13
Requirement already satisfied: numpy in ./.virtualenvs/cv/lib/python3.5/site-packages (from face_recognition) (1.16.4)
Requirement already satisfied: Pillow in ./.virtualenvs/cv/lib/python3.5/site-packages (from face_recognition) (6.1.0)
Collecting Click>=6.0 (from face_recognition)
  Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
**ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
    face-recognition-models>=0.3.0 from https://www.piwheels.org/simple/face-recognition-models/face_recognition_models-0.3.0-py2.py3-none-any.whl#sha256=8d6b0af2e37a17120c3f13107974bc252142a4ffcb4e58eabdfcf26608e52c24 (from face_recognition):
        Expected sha256 8d6b0af2e37a17120c3f13107974bc252142a4ffcb4e58eabdfcf26608e52c24
             Got        5499006a04cf993a1e6799a4d574f1382ddc7a7f007430680eda67d5c40d16e6**

I tried some solutions from stack overflow but none of them worked. Any ideas?

Need help coding logins/logouts

Hi

I'm trying to fix the a problem in the following scenario:

  1. multiple concurrent logins disabled
  2. user 1 moves in front of camera
  3. login occurs properly
  4. user 2 moves in front of camera
  5. login attempted but rejected
  6. user 1 moves away from camera
  7. user 1 logout occurs
  8. EXPECTING: user 2 login occurs, but it never does, until the next step
  9. user 2 moves away from camera
  10. user2 moves back in front of camera
  11. user 2 login occurs properly

Whilst I am expecting the user 2 login to occur (STEP 8) it does not because something still thinks that user 2 is logged in until they actually move away from the camera.

Something else is holding user 2 as logged in while they stay in front of the camera.

The logins/logouts appear to be driven by something else, probably the python code. I don't quite understand how there are working and calling the socketNotificationReceived function.

So, I am not currently sure how I can resolve this problem. I might need help with the python code, if that is what is hold the user as logged in until they move away

Thanks

'toLowerCase' error

Hello again;

After some time away on other projects, I have finally gotten back to straightening out my last installation of your module.

python3 facerecognition.py < runs the facial recognition fine and recognizes me - this in a nice change from the other installations I tried. However, I am getting this new error from the electron console on the mirror:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined at main.js:398 at Array.filter (<anonymous>) at modulesByClass (main.js:397) at Array.withClass (main.js:369) at Class.login_user (:8080/modules/MMM-Fa…Face-Reco-DNN.js:67) at Class.socketNotificationReceived (:8080/modules/MMM-Fa…ace-Reco-DNN.js:137) at module.js:246 at r.<anonymous> (socketclient.js:25) at r.emit (socket.io.js:6) at r.onevent (socket.io.js:8) main.js:398 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined at main.js:398 at Array.filter (<anonymous>) at modulesByClass (main.js:397) at Array.withClass (main.js:369) at Class.logout_user (:8080/modules/MMM-Fa…ace-Reco-DNN.js:106) at :8080/modules/MMM-Fa…ace-Reco-DNN.js:152

Video streams stays open when restarting MM

If you restart MagicMirror with

pm2 restart mm

pm2 starts another process, however, the video stream is not closed in the previous process and stays open, thus, the new process cannot start its own video stream and recognize faces in it because there is already another stream opened and not closed, therefore in the new instance of MagicMirror no face recognition is happening.

That is very evident with external USB cameras that have a usage LED. It stays lit even after you close MagicMirror. The issue is resolved when you restart the Raspberry.

Module not showing up appropriately

I'm unable to get the module to show up correctly on the screen. I have attached an image of the display along with the config file, please help.
IMG_20190703_145955222

`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: "alert",
		classes: "default everyone"
	},
	
	{
		module: "updatenotification",
		classes: "default everyone",
		position: "top_bar"
	},
	{
module: 'MMM-Facial-Recognition-OCV3',
position: 'top_left',
classes: 'default everyone',
config: {
    // Threshold for the confidence of a recognized face before it's considered a
    // positive match.  Confidence values below this threshold will be considered
    // a positive match because the lower the confidence value, or distance, the
    // more confident the algorithm is that the face was correctly detected.
    threshold: 80,
    // force the use of a usb webcam on raspberry pi (on other platforms this is always true automatically)
    useUSBCam: false,
    // Path to your training xml
    trainingFile: '/home/pi/MagicMirror/modules/MMM-Facial-Recognition-OCV3/training.xml',
    // recognition intervall in seconds (smaller number = faster but CPU intens!)
    interval: 2,
    // Logout delay after last recognition so that a user does not get instantly logged out if he turns away from the mirror for a few seconds
    logoutDelay: 15,
    // Array with usernames (copy and paste from training script)
    users: [],
    //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",
    // Boolean to toggle welcomeMessage
    welcomeMessage: true
}

},
{
module: "clock",
position: "top_left",
classes: "default everyone"
},
{
module: "calendar",
header: "US Holidays",
position: "top_left",
classes: "default everyone",
config: {
calendars: [
{
symbol: "calendar-check",
url: "webcal://www.calendarlabs.com/templates/ical/US-Holidays.ics"
}
]
}
},
{
module: 'MMM-Face-Reco-DNN',
classes: "default everyone",
position: "top_right"
},
{
module: "compliments",
position: "lower_third",
classes: "default everyone"
},
{
module: "currentweather",
position: "top_right",
classes: "default everyone",
config: {
location: "New York",
locationID: "", //ID from http://bulk.openweathermap.org/sample/; unzip the gz file and find your city
appid: "YOUR_OPENWEATHER_API_KEY"
}
},
{
module: "weatherforecast",
position: "top_right",
header: "Weather Forecast",
classes: "default everyone",
config: {
location: "New York",
locationID: "5128581", //ID from https://openweathermap.org/city
appid: "YOUR_OPENWEATHER_API_KEY"
}
},
{
module: "newsfeed",
position: "bottom_bar",
classes: "default everyone",
config: {
feeds: [
{
title: "New York Times",
url: "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml"
}
],
showSourceTitle: true,
showPublishDate: true
}
},
]

};

/*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") {module.exports = config;}
`

PythonShellError: AttributeError: 'NoneType' object has no attribute 'shape'

I receive an error in the pm2 logs:

`
[2020-09-06 15:14:07.898] [ERROR] Whoops! There was an uncaught exception...
[2020-09-06 15:14:07.901] [ERROR] PythonShellError: AttributeError: 'NoneType' object has no attribute 'shape'
at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21)
at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32)
at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
at ChildProcess.emit (events.js:200:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)

----- Python Traceback -----
File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 106, in <module>
  frame = imutils.resize(originalFrame, width=500)
File "/usr/local/lib/python3.7/dist-packages/imutils/convenience.py", line 69, in resize
  (h, w) = image.shape[:2] {

traceback: 'Traceback (most recent call last):\n File ' +
'"modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 106, in ' +
'\n frame = imutils.resize(originalFrame, width=500)\n File ' +
'"/usr/local/lib/python3.7/dist-packages/imutils/convenience.py", line ' +
"69, in resize\n (h, w) = image.shape[:2]\nAttributeError: 'NoneType' " +
"object has no attribute 'shape'\n",
executable: 'python3',
options: null,
script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
args: [
'--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
'--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
'--usePiCamera=0',
'--source=0',
'--rotateCamera=0',
'--method=dnn',
'--detectionMethod=hog',
'--interval=2000',
'--output=0',
'--extendDataset=True',
'--dataset=modules/MMM-Face-Reco-DNN/dataset/',
'--tolerance=0.6'
],
exitCode: 1
}
`

Everything is up to date. My config:

{ module: 'MMM-Face-Reco-DNN', config: { // Logout 30 seconds after user was not detecte anymore, if they will be detected between this 30 Seconds, they delay will start again logoutDelay: 30000, // How many time the recognition starts, with a RasPi 3+ it would be good every 2 seconds checkInterval: 2000, // Module set used for when there is no face detected ie no one is in front of the camera noFaceClass: 'noface', // Module set used for when there is an unknown/unrecognised face detected unknownClass: 'unknown', // Module set used for when there is a known/recognised face detected knownClass: 'known', // 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', // Set of modules that are always shown - show if there is a face or no face detected alwaysClass: 'always', // 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: 0, // If using another type of camera, you can choose // i.e. 0 = /dev/video0 or 'http://link.to/live' source: 0, // Rotate camera rotateCamera: 0, // 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: null, // 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: true, // If extendDataset is true, you need to set the full path of the dataset dataset: 'modules/MMM-Face-Reco-DNN/dataset/', // How much distance between faces to consider it a match. Lower is more strict. tolerance: 0.6, // allow multiple concurrent user logins, 0=no, 1=yes multiUser: 0, } },

ModuleNotFoundError: No module named 'imutils'

Hi

I've followed all the instructions on your module page and did not get any errors. I went to run encode.py and I get:

Traceback (most recent call last):
  File "encode.py", line 5, in <module>
    from imutils import paths
ModuleNotFoundError: No module named 'imutils'

I found some other similar post in the forum but they are slightly different and I don't really know anything about python so I'm not really sure how the import system works and why it can't find imutils.

Is there a particular version of python you need. From the forum I saw someone was running python 3.7. I also have python 2.7.16 and python3 v3.7.3

If I pip uninstall imutils, it seems to want to remove it from /home/pi/.local/lib/python2.7/site-packages/imutils/.
This does not quite seem right.

I went through the install again and used pip3 instead of pip eg pip3 install COMPONENT
and now it works.

I think this is a documentation issue

Face recognition is not working

In my Magic mirror project I'm using this module to hide and unhide module.
The classes: default and classes:"my name" is working.
But when I use classes:"everyone" it's not working.
Any solution.
What I need is...
If no one is infornt of mirror only clock module should be shown
If any motion detected or any unknown user came whom I dint added in datasets....that time it should show temperature, news feed, compliments and calendar.
I made clock as default and other module as everyone.
It's not working.

cv2 module installed in a virtenv

I have followed the instructions for compiling and building the OpenCV 4.1, but I did it as per instruction in a virtual enviornment, however MagicMirror is started outside of that virtual enviornment and cv2 is not there and the error that I am getting is:

tail -50  /home/pi/.pm2/logs/mm-error.log
        response: [Circular],
        originalHost: 'api.spotify.com',
        originalHostHeaderName: 'host',
        responseContent: [Circular],
        _destdata: true,
        _ended: true,
        _callbackCalled: true },
     toJSON: [Function: responseToJSON],
     caseless: Caseless { dict: [Object] },
     body: { error: [Object] } } }
ATTENTION: default value of option force_s3tc_enable overridden by environment.
(node:7628) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
SyntaxError: Unexpected token T in JSON at position 0
    at JSON.parse (<anonymous>)
    at PythonShell.asJson (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:358:21)
    at /home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:310:42
    at Array.forEach (<anonymous>)
    at PythonShell.recieveInternal (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:306:15)
    at PythonShell.receiveStderr (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:290:21)
    at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:108:18)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:279:12)
    at readableAddChunk (_stream_readable.js:260:13)
{ Error: ImportError: No module named 'cv2'
    at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21)
    at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32)
    at ChildProcess.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
    ----- Python Traceback -----
    File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 5, in <module>
      from stream import VideoStream
    File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/stream.py", line 2, in <module>
      from webcam import WebcamVideoStream
    File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/webcam.py", line 3, in <module>
      import cv2
  traceback:
   'Traceback (most recent call last):\n  File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 5, in <module>\n    from stream import VideoStream\n  File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/stream.py", line 2, in <module>\n    from webcam import WebcamVideoStream\n  File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/webcam.py", line 3, in <module>\n    import cv2\nImportError: No module named \'cv2\'\n',
  executable: 'python3',
  options: null,
  script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
  args:
   [ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
     '--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
     '--usePiCamera=0',
     '--method=dnn',
     '--detectionMethod=hog',
     '--interval=2000',
     '--output=0' ],
  exitCode: 1 }

Can I take "out" cv2 outside of the virtual enviornment or somehow make MagicMirror use that inside of the virt env?

Enhancement - Create dataset for unrecognized people

If the camera can't recognize a known person it should make screenshots in a selected or useful time period and save it in a new folder (timestamp? Like unknown_190831_1635). After that, the user can select the picture and create a new dataset.

Errors starting Magic Mirror

When I run npm start i get the following:

Whoops! There was an uncaught exception... SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse (<anonymous>) at PythonShell.asJson (/home/pi/MagicMirror/node_modules/python-shell/index.js:375:21) at /home/pi/MagicMirror/node_modules/python-shell/index.js:326:42 at Array.forEach (<anonymous>) at PythonShell.receiveInternal (/home/pi/MagicMirror/node_modules/python-shell/index.js:322:15) at PythonShell.receiveStderr (/home/pi/MagicMirror/node_modules/python-shell/index.js:306:21) at Socket.<anonymous> (/home/pi/MagicMirror/node_modules/python-shell/index.js:109:22) at Socket.emit (events.js:182:13) at addChunk (_stream_readable.js:279:12) at readableAddChunk (_stream_readable.js:260:13) MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection? If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues Whoops! There was an uncaught exception... { Error: ImportError: No module named 'cv2' at PythonShell.parseError (/home/pi/MagicMirror/node_modules/python-shell/index.js:260:21) at terminateIfNeeded (/home/pi/MagicMirror/node_modules/python-shell/index.js:139:32) at ChildProcess.<anonymous> (/home/pi/MagicMirror/node_modules/python-shell/index.js:131:13) at ChildProcess.emit (events.js:182:13) at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12) ----- Python Traceback ----- File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 5, in <module> from stream import VideoStream File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/stream.py", line 2, in <module> from webcam import WebcamVideoStream File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/webcam.py", line 3, in <module> import cv2 traceback: 'Traceback (most recent call last):\n File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 5, in <module>\n from stream import VideoStream\n File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/stream.py", line 2, in <module>\n from webcam import WebcamVideoStream\n File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/webcam.py", line 3, in <module>\n import cv2\nImportError: No module named \'cv2\'\n', executable: 'python3', options: null, script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py', args: [ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml', '--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle', '--usePiCamera=1', '--method=dnn', '--detectionMethod=hog', '--interval=2000', '--output=0' ], exitCode: 1 }

I tried updating the version of python-shell manually but this gives me another error:

PythonShell is not a constructor

Default Modules Not Showing Up

Hi,

This module works perfectly. And when it recognizes me, it says hi to me. But the default modules are not showing up. All I can see is a blank screen.
How do I fix this?

[ERROR] (node:4460) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

I get this error when I have already installed everything using "sudo pip3 install".

[ERROR] (node:4460) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[20:23:58.260] [LOG] Refreshed access token because it has expired. Expired at: 20:23:57 now is: 20:23:58
[20:24:04.015] [LOG] [MMM-Face-Reco-DNN] loading encodings + face detector...
[20:24:04.197] [LOG] Whoops! There was an uncaught exception...
[20:24:04.197] [ERROR] { Error: FileNotFoundError: [Errno 2] No such file or directory: 'modules/MMM-Face-Reco-DNN/tools/encodings.pickle'
at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21)
at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32)
at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
at ChildProcess.emit (events.js:182:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
----- Python Traceback -----
File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 66, in
data = pickle.loads(open(args["encodings"], "rb").read())
traceback:
'Traceback (most recent call last):\n File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 66, in \n data = pickle.loads(open(args["encodings"], "rb").read())\nFileNotFoundError: [Errno 2] No such file or directory: 'modules/MMM-Face-Reco-DNN/tools/encodings.pickle'\n',
executable: 'python3',
options: null,
script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
args:
[ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
'--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
'--usePiCamera=1',
'--method=dnn',
'--detectionMethod=hog',
'--interval=2000',
'--output=0',
'--extendDataset=False',
'--dataset=modules/MMM-Face-Reco-DNN/dataset/' ],
exitCode: 1 }

Module connection with the MagicMirror failure

As far as I can tell the facial recognition is working correctly, it was able to recognize specific faces when facerecognition.py is ran. After adding the module to the Mirror config file the mirror would not load, Electron launches but it appears the module is causing the mirror to crash. (exact same configuration as in the readme) There are no errors, I just get the gray screen with the cursor.

I have tested other modules and checked for js validation errors and please note the MM-Face-Reco-DNN module is up to date as of this posting.

If you have any idea what could be causing this please let me know.

"UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position "

Hi,
i have encountered a problem where whenever i run the magic mirror, the facial recognition module would return
[2020-06-29 05:01:19.553] [ERROR] PythonShellError: UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position 4: ordinal not in range(128) at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:260:21) at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:139:32) at ChildProcess.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:131:13) at ChildProcess.emit (events.js:200:13) at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12) ----- Python Traceback ----- File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 70, in <module> data = pickle.loads(open(args["encodings"], "rb").read()) { traceback: 'Traceback (most recent call last):\n File ' + '"modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 70, in ' + '<module>\n data = pickle.loads(open(args["encodings"], "rb").read())\n' + "UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position " + '4: ordinal not in range(128)\n', executable: 'python3', options: null, script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py', args: [ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml', '--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle', '--usePiCamera=1', '--source=0', '--rotateCamera=0', '--method=dnn', '--detectionMethod=hog', '--interval=2000', '--output=0', '--extendDataset=False', '--dataset=modules/MMM-Face-Reco-DNN/dataset/'

when i run the encoding.py and the facialrecognition.py individually it works no problem.
but the problem arises when opening the magic mirror.

as a test, i tried emptying the dataset folder and ran encoding.py, and confirmed that when running facialrecognition.py, my face is detected as unknown.

when i tried running the magic mirror, it shows hello stranger message.

so i guess there might be something in the encoding process of the images? the pickle process perhaps?

thank you for your time

Working on OpenCV 3.6.4

Hi there,

I was able to make it work with OpenCV 3.6.4 in my Raspberry Pi 3 B+. Just saying so anyone doesn't break their heads trying to compile a higher version.
I'm using the official RaspPi Camera v2.

I'll leave here the Terminal output to show the OpenCV version and running MM + a small gif showing it working on the MM.

pi@raspberrypi:~/MagicMirror $ pip3 list | grep opencv*
opencv-python           3.4.6.27
pi@raspberrypi:~/MagicMirror $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.6'
>>> exit()
pi@raspberrypi:~/MagicMirror $ npm run server

> [email protected] server /home/pi/MagicMirror
> node ./serveronly

[2020-05-21 08:47:37.061] [LOG]    Starting MagicMirror: v2.11.0
[2020-05-21 08:47:37.077] [LOG]    Loading config ...
[2020-05-21 08:47:37.090] [LOG]    Loading module helpers ...
[2020-05-21 08:47:37.151] [LOG]    Initializing new module helper ...
[2020-05-21 08:47:37.153] [LOG]    Module helper loaded: MMM-Face-Reco-DNN
[2020-05-21 08:47:37.158] [LOG]    No helper found for module: alert.
[2020-05-21 08:47:37.253] [LOG]    Initializing new module helper ...
[2020-05-21 08:47:37.254] [LOG]    Module helper loaded: updatenotification
[2020-05-21 08:47:37.256] [LOG]    No helper found for module: helloworld.
[2020-05-21 08:47:37.258] [LOG]    No helper found for module: compliments.
[2020-05-21 08:47:37.260] [LOG]    No helper found for module: clock.
[2020-05-21 08:47:37.261] [LOG]    No helper found for module: currentweather.
[2020-05-21 08:47:37.263] [LOG]    No helper found for module: weatherforecast.
[2020-05-21 08:47:38.333] [LOG]    Initializing new module helper ...
[2020-05-21 08:47:38.334] [LOG]    Module helper loaded: MMM-Coinbase
[2020-05-21 08:47:39.180] [LOG]    Initializing new module helper ...
[2020-05-21 08:47:39.181] [LOG]    Module helper loaded: newsfeed
[2020-05-21 08:47:39.182] [LOG]    All module helpers loaded.
[2020-05-21 08:47:39.469] [LOG]    Starting server on port 8080 ... 
[2020-05-21 08:47:39.483] [LOG]    Server started ...
[2020-05-21 08:47:39.485] [LOG]    Connecting socket for: MMM-Face-Reco-DNN
[2020-05-21 08:47:39.486] [LOG]    Starting module helper: MMM-Face-Reco-DNN
[2020-05-21 08:47:39.488] [LOG]    Connecting socket for: updatenotification
[2020-05-21 08:47:39.489] [LOG]    Connecting socket for: MMM-Coinbase
[2020-05-21 08:47:39.490] [LOG]    Connecting socket for: newsfeed
[2020-05-21 08:47:39.492] [LOG]    Starting module: newsfeed
[2020-05-21 08:47:39.492] [LOG]    Sockets connected & modules started ...
[2020-05-21 08:47:39.493] [LOG]    
Ready to go! Please point your browser to: http://xxx.xxx.x.x:8080
[2020-05-21 08:47:59.491] [LOG]    [MMM-Face-Reco-DNN] loading encodings + face detector...
[2020-05-21 08:47:59.631] [LOG]    [MMM-Face-Reco-DNN] starting video stream...
[2020-05-21 08:48:36.063] [LOG]    [MMM-Face-Reco-DNN] Users jess logged in.
[2020-05-21 08:48:39.973] [LOG]    [MMM-Face-Reco-DNN] Users jess logged out.
[2020-05-21 08:48:51.232] [LOG]    [SIGINT] Received. Shutting down server...
[2020-05-21 08:48:51.235] [LOG]    [MMM-Face-Reco-DNN] Terminate python
[2020-05-21 08:48:51.239] [LOG]    Stopping module helper: updatenotification
[2020-05-21 08:48:51.241] [LOG]    Stopping module helper: MMM-Coinbase
[2020-05-21 08:48:51.243] [LOG]    Stopping module helper: newsfeed
[2020-05-21 08:48:51.246] [LOG]    [MMM-Face-Reco-DNN] Terminate python

Now in the MM:
MM-opencv

BG translation

Can you please add a Bulgarian transaltion as well:

{
  "message": "Здравей %person, радвам се да те видя!",
  "title": "Лицево разпознаване",
  "stranger": "непознат"
}

I was unable to do it ... the module was throwing an error when I added. bg.json to the translations folder and adding it to the getTranslations function in MMM-Face-Reco-DNN.js

The error after starting the module is:

SyntaxError: Unexpected token T in JSON at position 0
    at JSON.parse (<anonymous>)
    at PythonShell.asJson (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:358:21)
    at /home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:310:42
    at Array.forEach (<anonymous>)
    at PythonShell.recieveInternal (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:306:15)
    at PythonShell.receiveStderr (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:290:21)
    at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:108:18)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:279:12)
    at readableAddChunk (_stream_readable.js:260:13)
{ Error: FileNotFoundError: [Errno 2] No such file or directory: 'modules/MMM-Face-Reco-DNN/tools/encodings.pickle'
    at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21)
    at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32)
    at ChildProcess.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
    ----- Python Traceback -----
    File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 49, in <module>
      data = pickle.loads(open(args["encodings"], "rb").read())
  traceback:
   'Traceback (most recent call last):\n  File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 49, in <module>\n    data = pickle.loads(open(args["encodings"], "rb").read())\nFileNotFoundError: [Errno 2] No such file or directory: \'modules/MMM-Face-Reco-DNN/tools/encodings.pickle\'\n',
  executable: 'python3',
  options: null,
  script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
  args:
   [ '--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
     '--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
     '--usePiCamera=0',
     '--method=dnn',
     '--detectionMethod=hog',
     '--interval=2000',
     '--output=0' ],
  exitCode: 1 }

Thanks in advance

Build this module or test on computer Ubuntu

Hi nischi,

Are you using raspberry to develop this module or use the other devices?. As normally, i will try/edit/create modules on my laptop before i copy it to my raspberry. And absolute, only some modules can work without GPIO :D.
But on laptop we have camera, Do you have any packages or tutorials to setup on Ubuntu for this module? I really want to test some solutions for better performance :D.

Thanks!
Best regards,
Anh Quan

'NoneType' object has no attribute 'shape'

Running into the following error when livestream is starting:

[2020-06-10 03:24:30.896] [LOG] [MMM-Face-Reco-DNN] loading encodings + face detector...
[2020-06-10 03:24:31.153] [LOG] [MMM-Face-Reco-DNN] starting video stream...
[2020-06-10 03:24:34.320] [LOG] Whoops! There was an uncaught exception...
[2020-06-10 03:24:34.321] [ERROR] PythonShellError: AttributeError: 'NoneType' object has no attribute 'shape'
at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:246:21)
at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:129:32)
at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:121:13)
at ChildProcess.emit (events.js:200:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
----- Python Traceback -----
File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 101, in
frame = imutils.resize(originalFrame, width=500)
File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/imutils/convenience.py", line 69, in resize
(h, w) = image.shape[:2] {
traceback: 'Traceback (most recent call last):\n File ' +
'"modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 101, in ' +
'\n frame = imutils.resize(originalFrame, width=500)\n File ' +
'"/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/imutils/convenience.py", ' +
'line 69, in resize\n (h, w) = image.shape[:2]\nAttributeError: ' +
"'NoneType' object has no attribute 'shape'\n",
executable: '/home/pi/.virtualenvs/cv/bin/python3.7',
options: null,
script: 'modules/MMM-Face-Reco-DNN/tools/facerecognition.py',
args: [
'--cascade=modules/MMM-Face-Reco-DNN/tools/haarcascade_frontalface_default.xml',
'--encodings=modules/MMM-Face-Reco-DNN/tools/encodings.pickle',
'--usePiCamera=0',
'--source=0',
'--rotateCamera=0',
'--method=dnn',
'--detectionMethod=hog',
'--interval=2000',
'--output=0',
'--extendDataset=False',
'--dataset=modules/MMM-Face-Reco-DNN/dataset/'
],
exitCode: 1
}

Have tried debugging but without much success unfortunately. Some help would be appreciated!

Error: Cannot find module 'python-shell'

I get the following error when starting MagicMirror with the module configured:

WARNING! Could not load config file. Starting with default configuration. Error found: Error: Cannot find module 'python-shell'
App threw an error during load
Error: Cannot find module 'python-shell'
    at Module._resolveFilename (internal/modules/cjs/loader.js:602:15)
    at Function.Module._resolveFilename (/home/pi/MagicMirror/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (internal/modules/cjs/loader.js:528:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_helper.js:10:23)
    at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_helper.js:87:3)
    at Module._compile (internal/modules/cjs/loader.js:711:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:722:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
{ Error: Cannot find module 'python-shell'
    at Module._resolveFilename (internal/modules/cjs/loader.js:602:15)
    at Function.Module._resolveFilename (/home/pi/MagicMirror/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (internal/modules/cjs/loader.js:528:25)
    at Module.require (internal/modules/cjs/loader.js:658:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_helper.js:10:23)
    at Object.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_helper.js:87:3)
    at Module._compile (internal/modules/cjs/loader.js:711:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:722:10)
    at Module.load (internal/modules/cjs/loader.js:620:32) code: 'MODULE_NOT_FOUND' }
ATTENTION: default value of option force_s3tc_enable overridden by environment.

I have all dependencies installed and I have encoded the images.

welcome message

Not really an issue, more of a question: is it possible to change the alert message itself?
Like, if I send an Alert via MMM-Remote-Control, it pops up in the center, and kinda hide the other modules. If someone could tell me how to approach, I´d be more than happy :D
Thanks in advance, great module btw!

Running magicmirror in client mode in k8s

I'm running my mm setup using server/client mode where the server is running in a kubernetes container.

Has anyone tried using this setup? I cannot figure out why my camera is not being used properly.
I am loading the video device into the pod like usual and inside the pod I am able to run commands like raspistill -o test.jpg and am able to get an accurate image from the camera. But when I try to run this module it hangs on starting the VideoStream. I've tried raising Exceptions right after the VideoStream.start line and it never gets hit just hangs in the .start command.

I am assuming the module is using the camera attached to the server and not trying to access a camera that could potentially be on the browser (client) side since the python scripts are executed from the node_helper and not the main MMM-Face-Reco-DNN.js file.

k8s snippet

      volumes:
      - name: dev-video0
        hostPath:
          path: /dev/video0
...
        volumeMounts:
        - mountPath: /dev/video0
          name: dev-video0

CV2 error on encode

Hello Nischi;

So I've finally managed to install Open CV 4.1 and all its dependancies, as well as your new module. I am having issues on the encoding, here's the output:

$ python3 encode.py -i ../dataset/ -e encodings.pickle -d hog [INFO] quantifying faces... [INFO] processing image 1/40 [INFO] processing image 2/40 [INFO] processing image 3/40 [INFO] processing image 4/40 [INFO] processing image 5/40 [INFO] processing image 6/40 [INFO] processing image 7/40 [INFO] processing image 8/40 [INFO] processing image 9/40 [INFO] processing image 10/40 [INFO] processing image 11/40 [INFO] processing image 12/40 [INFO] processing image 13/40 Traceback (most recent call last): File "encode.py", line 40, in <module> rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) cv2.error: OpenCV(4.1.0) /home/pi/opencv-4.1.0/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

I thought it might be one of the images that was already greyscale, that one was removed - still no difference. It always stops on lucky 13 too.

Error while running the command python3 encode.py -i ../dataset/ -e encodings.pickle -d hog

Hi,
I have a few errors when I run the command python3 encode.py -i ../dataset/ -e encodings.pickle -d hog.
Log below:-

Traceback (most recent call last):
File "encode.py", line 5, in
from imutils import paths
File "/home/pi/.local/lib/python3.7/site-packages/imutils/init.py", line 8, in
from .convenience import translate
File "/home/pi/.local/lib/python3.7/site-packages/imutils/convenience.py", line 6, in
import cv2
File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 89, in
bootstrap()
File "/usr/local/lib/python3.7/dist-packages/cv2/init.py", line 79, in bootstrap
import cv2
ImportError: libtesseract.so.4: cannot open shared object file: No such file or directory


How do I solve this?

Can you display the video on the mirror?

In the python file, images are shown using cv2.imshow(). Is there a way to show these on the mirror? This makes it visual and shows people what's going on under the hood, would be a cool feature!

Cheers

Set rotation of PiCamera

It'd be nice to provide an option to set the rotation of the camera when using the Raspberry Pi camera module. This is useful if the camera is mounted the wrong way around for the default orientation.

I have managed to do this temporarily by modifying picam.py and adding the line self.camera.rotation = 270, but a config option would be better.

Alert notification

Well this is more of a feature request than an issue, the module itself is working well but it would be more complete if this particular feature is added. So I set the interval to 2 seconds so each time I’m infront of the mirror, the mirror keeps on updating and sending the alert notification and since I have google tts enabled , it keeps on announcing; it would be more perfect if the face-reco module doesn’t send an alert notification if the same user is detected the second time in and only send alert notification the next time a new user is detected.

Facial Recognition Not Working

Hello!

So I recently installed everything as instructed and when I went to use python encode.py or python3 encode.py I was struck with errors about not being able to import cv2 or imutils. HOWEVER, when I did the following, I was able to use the encode.py script:
source ~/.profile
workon cv
python3
import cv2
exit()

Then run python3 encode.py or python encode.py in the virtual environment and it worked (at present, I'm only using one face set to verify between my profile and the default profile, so I only encoded 10 photos).

Now I have the module installed and configured as mentioned and am not getting any response from the module. The encodings.pickle file is present and MagicMirror is having no problem running, but I stare and stare at my camera and unfortunately get no response. Not sure what I am doing wrong at the moment, and unfortunately my linux coding skills/understanding are pretty basic. Any help/guidance as to what I may have done or still need to do would be greatly appreciated!

USB camera support

Does your code Supports USB camera.

I am using Logitech USB camera and below is the error I am getting on running python3 facerecognition.py

{"status": "loading encodings + face detector..."}
{"status": "starting video stream..."}
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 456, in _init_camera
    self._camera = mo.MMALCamera()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2279, in __init__
    super(MMALCamera, self).__init__()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 633, in __init__
    prefix="Failed to create MMAL component %s" % self.component_type)
  File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
    raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to create MMAL component b'vc.ril.camera': Out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "facerecognition.py", line 73, in <module>
    vs = VideoStream(usePiCamera=True).start()
  File "/home/pi/.local/lib/python3.7/site-packages/imutils/video/videostream.py", line 18, in __init__
    framerate=framerate, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/imutils/video/pivideostream.py", line 10, in __init__
    self.camera = PiCamera()
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 431, in __init__
    self._init_camera(camera_num, stereo_mode, stereo_decimate)
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 460, in _init_camera
    "Camera is not enabled. Try running 'sudo raspi-config' "
picamera.exc.PiCameraError: Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.

default modules not showing for strangers

I have found that when the module recognizes a stranger, those modules just labeled "default" are not shown. Classes "default everyone" are shown for strangers but "default" are not shown. Is anyone else seeing this issue? Maybe my configuration is incorrect.

Config

Im having issues getting it working, sorry such a noob at this stuff

I installed everyrting
but i cant seem to make a good config file when i start the pm2 program it automaticly goes to the error where you need a config file

default modules are not working

I installed and configured this modules, and this modeules work well, but other modules include default modules are not working well.

Not detecting faces with MagicMirror

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

Report: OpenCV 4.2.0 working and compile guide

I tried your module with OpenCV 4.2.0 from git and it works fine. Here's what I did to make it compile (rough draft of install script; might not work, but you get the idea):

#!/bin/bash
echo "Installing OpenCV 4.2.0 build dependencies..."
sudo apt --no-install-recommends install build-essential cmake git pkg-config -y
echo "Installing OpenCV 4.2.0 core dependencies..."
sudo apt --no-install-recommends install libgtk-3-dev libopenblas-dev liblapack-dev gfortran libatlas-base-dev libtbb2 libtbb-dev -y
echo "Installing OpenCV 4.2.0 image / video dependencies..."
sudo apt --no-install-recommends install libavcodec-dev libavformat-dev libswscale-dev libjpeg-dev libpng-dev libtiff-dev libv4l-dev -y
#echo "Installing OpenCV 4.2.0 python dependencies..."
#sudo apt --no-install-recommends install python-dev libpython-dev python-pip python-numpy python-setuptools python-wheel -y
echo "Installing OpenCV 4.2.0 python3 dependencies..."
sudo apt --no-install-recommends install python3-dev libpython3-dev python3-pip python3-numpy python3-setuptools python3-wheel -y
echo "Installing OpenCV 4.2.0 python3 packages..."
pip3 install setuptools
pip3 install dlib
pip3 install face_recognition
pip3 install imutils
cd ~
git clone --branch 4.2.0 --depth 1 https://github.com/opencv/opencv.git
cd opencv
mkdir build
cd build
echo "CMake'ing OpenCV 4.2.0..."
cmake -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D PYTHON_DEFAULT_EXECUTABLE=$(which python3) -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
echo "Building OpenCV 4.2.0. This may take a while..."
CORES=$(grep -c '^processor' /proc/cpuinfo 2>/dev/null)
make -j $CORES
echo "Done."

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.