MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MMM-Face-Reco-DNN - All new Face Recognition

    Scheduled Pinned Locked Moved Utilities
    36 Posts 14 Posters 21.6k Views 17 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • nischiN Offline
      nischi @Ivanov_d
      last edited by

      @Ivanov_d Thanks a lot, glad to hear that.

      1 Reply Last reply Reply Quote 1
      • C Offline
        ChrizZz
        last edited by ChrizZz

        as a Noob I have a few questions regarding the installation process - I passed now OpenCV:

        At first for me it looks like this is the newest face recognition module and therefore I should go for installing this one instead of the other 2 options, right?

        Now I finished the OpenCV installation by using the linked guide from pyimagesearch. There OpenCV was installed in an virtual environment. Is this important? Do I have to install all the libs like dlib or face recognition also in this virtual environment?

        nischiN 1 Reply Last reply Reply Quote 0
        • nischiN Offline
          nischi @ChrizZz
          last edited by

          @ChrizZz

          Yes its the newest version of the face reco 😊

          No its not that important that you use a virtual environment, bit with this you can also install different versions on the same machine. but if you have a virtual environment you need to install all dependencies ther, dlib and face reco too.

          1 Reply Last reply Reply Quote 0
          • I Offline
            Ivanov_d
            last edited by

            @ChrizZz I followed the tutorial and installed OpenCV and all dependencies in a virtual environment, but that did not go very well afterwards, you have to reconfigure the module with the correct paths and that can be cumbersome, therefore I started on a clean state and installed OpenCV and the dependencies without a virtual envioronment - e.g. follow the same tutorial without the part related to virtual enviornment. That is the most appropriate for our use case.

            1 Reply Last reply Reply Quote 2
            • C Offline
              ChrizZz
              last edited by

              damn - 2nd try without a virtual environment.

              @nischi: Is there a chance that you merge your module also with MMM-MotionDetector? Currently I use the camera to activate and deactive my screen and Google told me that it isn’t possible that 2 processes use the same camera. The suggested solution was to use a 2nd camera, merge both processes or stream the camera picture.

              nischiN 1 Reply Last reply Reply Quote 1
              • I Offline
                Ivanov_d
                last edited by

                @ChrizZz I have used camera motion detection and I gave it up, because:

                1. It is not very reliable (maybe it was just my cheap camera that I used for testing back then)
                2. it is resource hungry

                Because of that I use an external wireless PIR sensor which is part of my smart home system to turn on/off my SmartMirror and it works great. Since the motion processing happens on my smart home system and the Mirror is turned on/off via SSH command it takes up no resources at all from the MagicMirror which is already at 60% load when using Facial Recognition.

                1 Reply Last reply Reply Quote 2
                • nischiN Offline
                  nischi @ChrizZz
                  last edited by

                  @ChrizZz
                  You can use my other Module https://github.com/nischi/MMM-MotionControl to control TV with my Face Reco Module. It communicate with Notifications and is not using an own Camera Stream.

                  G 1 Reply Last reply Reply Quote 1
                  • C Offline
                    ChrizZz
                    last edited by ChrizZz

                    oh, I didn’t know that you have a modul for it. But unfortunately it isn’t working on my Pi. Your modul doesn’t recognize a motion.

                    Do I have to uninstall the MMM-MotionDetector first?
                    Or do I need to run Face-Reco-DNN or the OCV3 version?

                    //edit: I think I know why it isn’t working. Maybe my display isn’t HDMI-CEC ready. I changed the command of your node_helper.js.
                    Default:

                    turnOn: function() {
                    		var self = this;
                    		exec('echo "on 0" | cec-client ' + this.config.comport + ' -s -d 1', function (error, stdout, stderr) {
                    			self.status = 'on';
                    

                    My version:

                    turnOn: function() {
                    		var self = this;
                    		exec('vcgencmd display_power 1', function (error, stdout, stderr) {
                    			self.status = 'on';
                    

                    Instead of sending a note to my display for standby I switch off the display_power. But I can’t wake up the display again. I think I have to use Face-Reco-DNN or Facial-Recognition-OCV3. Currently I don’t use them because I have to do the setup for the DNN version.

                    nischiN 1 Reply Last reply Reply Quote 0
                    • nischiN Offline
                      nischi @ChrizZz
                      last edited by

                      @ChrizZz
                      Yes you need to use one of the Face Reco Module that this works. Better my new Module ;) it’s much more accurate.

                      C 1 Reply Last reply Reply Quote 1
                      • C Offline
                        ChrizZz @nischi
                        last edited by ChrizZz

                        @nischi said in MMM-Face-Reco-DNN - All new Face Recognition:

                        @ChrizZz
                        Yes you need to use one of the Face Reco Module that this works. Better my new Module ;) it’s much more accurate.

                        Thanks, I will use your new module.

                        During the setup I have another issue. It’s when I want to start encoding I get this error message:

                        Traceback (most recent call last):
                          File "encode.py", line 5, in <module>
                            from imutils import paths
                          File "/usr/local/lib/python3.7/dist-packages/imutils/__init__.py", line 8, in <module>
                            from .convenience import translate
                          File "/usr/local/lib/python3.7/dist-packages/imutils/convenience.py", line 6, in <module>
                            import cv2
                        ModuleNotFoundError: No module named 'cv2'
                        

                        I think it’s a problem of my OpenCV installation where I skipped the virtualenvs. In step 6 of the tutorial I should do this:

                        $ cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
                        $ ln -s /usr/local/python/cv2/python-3.5/cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
                        $ cd ~
                        

                        I skipped that because I have no idea where I have to create the link when I install this without virtualenvs. But it seems that I have to link it…

                        //edit: Key to success:

                        cd ~/opencv-4.0.0/build/lib/python3
                        sudo cp cv2.cpython-35m-arm-linux-gnueabihf.so /usr/local/lib/python3.5/dist-packages/cv2.so
                        
                        nischiN 1 Reply Last reply Reply Quote 0
                        • nischiN Offline
                          nischi @ChrizZz
                          last edited by

                          @ChrizZz
                          Thanks for your solution. Usually it’s because the link for cv2 is to the wrong python Version.
                          Happy to hear that it works.

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            ChrizZz
                            last edited by

                            is it common that it takes 40sec between face recognition and turning the TV on?

                            I see it happen after a freshly restarted pi, that it takes 40/45sec. The scenario is that I restart my pi, mm is autostarting and the TV is turned off by the module. Between the restart and the 1st face recognition is ~3min time.

                            nischiN 1 Reply Last reply Reply Quote 0
                            • nischiN Offline
                              nischi @ChrizZz
                              last edited by

                              @ChrizZz
                              Sound a little bit long to me, for me it works faster. But it took a while until they are startet. Do you use default settings?

                              C 1 Reply Last reply Reply Quote 0
                              • C Offline
                                ChrizZz @nischi
                                last edited by

                                @nischi said in MMM-Face-Reco-DNN - All new Face Recognition:

                                @ChrizZz
                                Sound a little bit long to me, for me it works faster. But it took a while until they are startet. Do you use default settings?

                                My logs file is also a bit weird:

                                [MMM-Face-Reco-DNN] Users ChrizZz logged in.
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                [MMM-Face-Reco-DNN] Users ChrizZz logged out.
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                [MMM-Face-Reco-DNN] Users ChrizZz logged in.
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                [MMM-Face-Reco-DNN] Users ChrizZz logged out.
                                [MMM-Face-Reco-DNN] Users ChrizZz logged in.
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                [MMM-Face-Reco-DNN] Users ChrizZz logged out.
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                CECControl received (current, new): off on
                                CECControl received (current, new): on off
                                
                                

                                This is a 3min part of the logs and the 1st time I was in front of the mirror and recognized by the module this evening.

                                My settings are:

                                		{
                                			module: 'MMM-CECControl',
                                    				config: {
                                      					  // Comport of your Raspberry Pi
                                      					  comport: 'RPI',
                                      					  // Turn the TV off if the Mirror start
                                       					 offOnStartup: true
                                    					}
                                		},
                                		{
                                    			module: 'MMM-MotionControl',
                                   				 config: {
                                     					   // Delay to turn the TV off
                                       						 delay: 60000,
                                       					 // Interval to check modules
                                 					       interval: 5000,
                                 				       // Use the module MMM-Facial-Recognition-OCV3
                                  				      useFacialRecognitionOCV3: false,
                                   				     // Use the module MMM-Face-Reco-DNN
                                   				     useMMMFaceRecoDNN: true,
                                   				     // Array where tv should be on
                                				        ontime: []
                                					    }
                                		},
                                		{
                                			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: 30000,
                                      					// 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: null,
                                      					// Should shown welcome message over alert module from MagicMirror
                                      					welcomeMessage: true
                                    					}
                                		},
                                
                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  dragontattoo
                                  last edited by

                                  Is it working fine??

                                  C 1 Reply Last reply Reply Quote 0
                                  • C Offline
                                    ChrizZz @dragontattoo
                                    last edited by

                                    @dragontattoo said in MMM-Face-Reco-DNN - All new Face Recognition:

                                    Is it working fine??

                                    Depends on how you define working fine…The face recognition is working quite good, setting it up is easy with the advice you get in this thread. For me it’s just the “slow” reaction to activate the display which is an issue. But I’m optimistic that there is a way to solve it and I have a special environment with a display which hasn’t CEC control.

                                    nischiN 1 Reply Last reply Reply Quote 0
                                    • nischiN Offline
                                      nischi @ChrizZz
                                      last edited by

                                      @ChrizZz
                                      Yes i know this issue. i’m currently working on a bugfix. will tell you if i’m done.

                                      1 Reply Last reply Reply Quote 2
                                      • I Offline
                                        Ivanov_d
                                        last edited by

                                        I am turning on the monitor using a PIR sensor and it is instant. Keep in mind that it also depends on your monitor, some are slower to respond - this is my second monitor, the first one was very slow to respond to any HDMI related commands.

                                        1 Reply Last reply Reply Quote 0
                                        • C Offline
                                          ChrizZz
                                          last edited by

                                          I have a new strange error and I think it’s just if I restart mm with “pm2 restart mm”. If I reboot my pi, everything is fine.

                                          SyntaxError: Unexpected token m in JSON at position 0
                                              at JSON.parse (<anonymous>:null:null)
                                              at PythonShell.asJson (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:375:21)
                                              at /home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:326:42
                                              at Array.forEach (<anonymous>:null:null)
                                              at PythonShell.receiveInternal (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:322:15)
                                              at PythonShell.receiveStderr (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:306:21)
                                              at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/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)
                                              at Socket.Readable.push (_stream_readable.js:219:10)
                                              at Pipe.onread (net.js:636:20)
                                          
                                          SyntaxError: Unexpected token T in JSON at position 0
                                              at JSON.parse (<anonymous>:null:null)
                                              at PythonShell.asJson (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:375:21)
                                              at /home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:326:42
                                              at Array.forEach (<anonymous>:null:null)
                                              at PythonShell.receiveInternal (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:322:15)
                                              at PythonShell.receiveStderr (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:306:21)
                                              at Socket.<anonymous> (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/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)
                                              at Socket.Readable.push (_stream_readable.js:219:10)
                                              at Pipe.onread (net.js:636:20)
                                          
                                          { Error: mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
                                          mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x631b2f0 (ENOSPC)
                                          mmal: mmal_connection_enable: output port couldn't be enabled
                                          Traceback (most recent call last):
                                            File "modules/MMM-Face-Reco-DNN/tools/facerecognition.py", line 56, in <module>
                                              vs = VideoStream(usePiCamera=True).start()
                                            File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/stream.py", line 18, in __init__
                                              framerate=framerate)
                                            File "/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/tools/picam.py", line 10, in __init__
                                              self.camera = PiCamera()
                                            File "/usr/lib/python3/dist-packages/picamera/camera.py", line 433, in __init__
                                              self._init_preview()
                                            File "/usr/lib/python3/dist-packages/picamera/camera.py", line 513, in _init_preview
                                              self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
                                            File "/usr/lib/python3/dist-packages/picamera/renderers.py", line 558, in __init__
                                              self.renderer.inputs[0].connect(source).enable()
                                            File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2212, in enable
                                              prefix="Failed to enable connection")
                                            File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
                                              raise PiCameraMMALError(status, prefix)
                                          picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources
                                          
                                              at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Face-Reco-DNN/node_modules/python-shell/index.js:268: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:182:13)
                                              at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
                                          
                                            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 }
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • B Offline
                                            Blauenfeldt
                                            last edited by

                                            I get this too, when my PI can’t connect to the camera. I know that, because if i use
                                            Raspistill -o s.jpg
                                            I will get an error there too. A reboot seems to fix it though. I don’t know what makes it happen, but i suspect the cable.

                                            S 1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy