Tag: Raspberry Pi

Magic Mirror – Face Recognition and general Update

After being absent from this blog for quite some time, I’d like to give you a quick update on my mirror project. The filesystem of my Raspberry Pi’s SD-card got corrupted some time ago and I haven’t found the motivation to reinstall the system and all my scripts since then, well at least not until two days ago. Because I had to setup the system from scratch again anyway I used the opportunity to use the newest Raspbian version “Jessie” this time and also to match my modified mirror interface code with the original from Michael Teeuw again. Some thoughts about the new Linux version: I really like the way systemd handles process managing and starting, seems a lot simpler to me than it was before but that’s not the topic today.

A few months ago I took the code from the Raspberry Pi Face Recognition Treasure Box and modified it in a way so that it’s no longer just able to recognize one valid face but to differentiate between multiple faces and therefore to know who’s standing in front of the mirror. The python script  is now constantly trying to match people to a known set of trained faces and if one is recognized displays a welcome message and personalized information for that user.

Because the number of my components and running processes keeps increasing, I sketched a quick schematic yesterday to not loose sight of who is talking to whom.
Software:Hardware magischer Spiegel

On the bottom of the software side, we have the mirrorcontroller. It is responsible for all kind of GPIO-stuff, like monitoring the motion sensor and a button. In the future it will also controls the colors of some RGB LED’s I will use for lighting up the person in front of the mirror but that’s still to be implemented. If something moves, a relay turns on the display and a signal is send to the face recognition service, which then starts to take pictures and searches them for faces. If the service recognizes a face the data is send to the SocketIOServer, which further sends it to the web interface to display the welcome message and the information for the user. Other features of the SocketIOServer are:

  • Online Banking, to show the users current bank balance
  • Collecting statistics from my Vimeo-videos
  • Investigating how much space is still left on my server
  • Detecting incoming calls via the Fritz!Box (a German internet router and phone system) call monitor
  • Pulling invoices my clients still need to pay from Invoice Ninja

In a future update I will also add gathering my ToDo’s from Wunderlist but until now that’s it.

The Magic Mirror – Update

_MG_3464

I replaced the Raspberry Pi 1 model A with a Pi 2 model B. The mirror is now stating up at more than twice the speed and the animations of the interface also got a bit smoother.
Pi2

Because semitransparent mirrors logically don’t reflect as much as real ones, I decided to add some LED lighting behind milk glass inside the mirror’s housing, to lighten up the person in front of it and therefore making him or her more visible.
LEDs Spiegel

The light is activated through a button. A short press triggers the light, a longer button press switches between two views of the web interface.
Schalter Spiegel

Python Uncertainty

Maybe one of my readers is a bit more experienced when it comes to Python – probably not that hard – and can explain to me why my first script does not work and the second one on the other hand does. Biteule and I only came as far as to suspect, that it has something to do with the threading of the GPIO-callbacks but what exactly the problem is neither of us understands. It’s not like zerorpc is not imported and available in the first script when it gets executed, after all it is able to throw an error (LostRemote: Lost remote after 10s heartbeat), so why does it make a difference where I import the module?

import RPi.GPIO as GPIO
import time
import zerorpc

nodebridge = zerorpc.Client()
nodebridge.connect("tcp://127.0.0.1:4242")

GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN)

def switchview(switchview_taster):
    nodebridge.switchview()

try:
    GPIO.add_event_detect(27, GPIO.FALLING, callback=switchview, bouncetime=600)
    while 1:
        time.sleep(100)
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.IN)

def switchview(switchview_taster):
    import zerorpc
    nodebridge = zerorpc.Client()
    nodebridge.connect("tcp://127.0.0.1:4242")
    nodebridge.switchview()

try:
   GPIO.add_event_detect(27, GPIO.FALLING, callback=switchview, bouncetime=600)
   while 1:
      time.sleep(100)
var io = require('socket.io').listen(1234);
var zerorpc = require("zerorpc");

var pythonbridge = new zerorpc.Server({
  switchview: function(reply) {
    io.sockets.emit('switchview');
    reply(null);
  }
});

pythonbridge.on("error", function(error) {
  console.error("RPC server error:", error);
});

pythonbridge.bind("tcp://0.0.0.0:4242");

UPDATE 12.02.15 – 14:51:

The Magic Mirror – EMC interference

Quick Update! My uncle got me a mirror sample, so this is how the whole thing looks with glass in front of it 🙂
Spiegelmuster

As it seems my components interfear somehow and influence each other… I recently added a button to shutdown the mirror. It works by constantly setting a GPIO-pin to 3.3V, pressing the button grounds the pin and draws the voltage to 0V. A Python script registers this change and shuts down the OS. Strangely this also happens if the motions sensor enables the monitor. At first I assumed there might be something wrong with my circuits, so my uncle and I thought about how the 230V from the monitor could influence the Pi over the relays. Another guess was, that the monitor drains to much power at startup and with that collapses the 3.3V for a really short amount of time. Later I realized that this was also happening if I connected the monitor directly to a power outlet without the relay in-between.

alte LampeI just picked up this old lamp, because I needed some light to correctly judge how reflective the mirror actually was when used normally.  Well, I didn’t quite expect what happened next… Turning on (and off) the lamp (when placed a certain points near the other components) turns of the monitor for about two seconds. It does not seem to influence the Pi though but probably something similar is going on with the shutdown triggers.

UPDATE 22:22

I experimented a bit further with the lamp or to be precisely with its power cable. If I place the lamp’s cable over the Pi, the same thing happens, as if I turn on the monitor, a shutdown gets triggered as soon as the lamp is turned on or turned off. The problem therefore probably really is some kind of electromagnetic radiation.

The Magic Mirror – Raspberry Pi

I recently started a new projected, which of course is a great reason to write an article about it!

I had a DVI-monitor laying around in my room for quite a considerable time now. It was always connected to my Raspberry Pi with ever changing functionality. In the beginning I used it as a XBMC media center to watch movies and listen to music on my stereo. After that I wanted to use it to display useful information but found it strange pretty quickly to have a monitor standing around just to display information. Besides I didn’t even know what kind of information to show on it, so I again used it as a media center again.

Some time ago – while searching for interesting Raspberry Pi projects – I rediscovered the “Magic Mirror” build by Michael Teeuw and spontaneously decided to build one myself. I then found my self dissembling the monitors housing and starting to think how to best accommodate the Pi in this setup. I also changed some bits of Michaels original interface, from showing the same compliments in the UI all day to showing compliments based on the time of the day (my first Git-Pull-Requests; yeah!).

I didn’t really like the idea of having a monitor in my room, running 24/7 even if no-one was present who could actually look at the screen, so I ordered a relay and a motion sensor and wrote a small Python script to turn the monitors power only on when someone is in the room. Jonathan from Studio Einz helped me build this small circuit to switch the relay’s 5V circuit with the 3V from the Pi’s GPIO-pin’s. (Look at that fancy LED! We sadly didn’t have a diode so the LED had to do the trick :D)

Transistor Board

Relais

Bewegungsmelder

Raspberry Pi

Some users of the FRITZ!Box (a German internet router and phone system) may know: The device has a build in call monitor, which is easily read for example with Node.js and this handy module. Incoming calls then get redirected  to the web interface trough Socket.IO, which further displays this nice alert.

Anruf

There also is a feature to alert me when someone is ringing at the door in my code but before that’ll work I first have to connect my bell to the FRITZ!Box. Now I just need an actual mirror and a housing for the project.

Oh! If someone has an idea what else I could display on the mirror: I am listening!

Copyright © 2024 MeType

Theme by Anders NorenUp ↑