HowTo: Use a Webcam as a Magic Mirror - Part 2
Novell Cool Solutions: Feature
Digg This -
Posted: 10 Nov 2005
This HowTo describes a system which can be used at home and in shops to retain several views of an object or person, so that comparisons can be made between them on a computer screen as a way of selecting a product. The incentive for this system was that when trying on new spectacle frames, I could not see what they really looked like. I realised that because the computer can remember several views, that many other uses where one would like to pick the best of several choices, could be an advantage for all sorts of things in the home and in shops, so I decided to create such a system using the shell, Runtime Revolution, a web cam, and some picture grabbing and saving software. I have called it the "magic mirror" and I would like you to do the same if you make one, to protect the IP for the community.
This is part two of this HowTo. (See Part One.) In this part we shall look at web cameras and their software. How the camera will work and what physical requirements must be met to make sure the system is usable.
Your web camera must have a Linux driver. Some do not have one yet, so you must check the Linux hardware pages before you purchase one.
Start by looking at:
This also leads on to a page about picture grabbing software. SUSE 9.2 and 9.3, comes with xawtv which you can use with a USB Web cam.
Another site for USB drivers is:
Digital video cameras which plug into a TV card and those small USB video cameras are all referred to as web cams. For this application, any sort will do, although the small USB cameras are unobtrusive and can be fitted easily into many places.
When using a USB web cam for this application, care must be taken that the hardware and software which grabs a snap from the video stream from the camera, will handle movement without blurring, although this shouldn't be a real problem as the user will be posing for the shot.
The placement of the web cam is very important in order to minimise unwanted reflections. For example, if you are trying on a pair of spectacle frames, which usually have plain glass in them, and are looking at the on screen picture, The screen will be reflected in the glasses. This is not any good, so a completely different physical layout must be developed to give this system meaningful and useful functionality.
This is where innovation and inventiveness on the part of the system developer comes into play. Lateral thinking is one of the most important tools a developer has in their arsenal. This is when the developer thinks of something that works in a different application that may solve their problem.
For example, we all know that when taking indoor family photographs, red eye reflections can be alleviated by putting a piece of tissue over the fixed flash unit, and having bright diffused lighting from another source will do the same job.
So how do we diffuse or get rid of the screen light and still be able to see ourselves, you may well ask. More lateral thinking. Get rid of the number one problem which is the screen.
Now how do we look at ourselves? How about if we use a conventional mirror, with a conveniently placed web cam and the picture taking buttons below and in front of or to the side of the mirror.
Now we see why it is called a Magic Mirror, because it is a real mirror enhanced with some computer video technology. The use of a real mirror lets us do several useful things. One is that lighting can be diffused from the sides or top. Two is that mirror sizes can be tailored to the purpose. Three is that the camera focus can be accurately set. Four is that the camera can be placed either completely hidden behind a half silvered area of the mirror, like in spy movies, or somewhere convenient out of sight to the side or top of the subject.
I prefer the spy movie idea, but this is an expense, especially with an existing mirror which is fixed directly to a wall. With alternative placements there will be issues with the camera picture not being exactly the same as that seen in the mirror, but these can be minimised with intelligent placement.
Using a real mirror allows the application to be easily used in dress and shoe as well as spectacle shops, and of course at home when dressing up for an outing. A big advantage is that users may click the button with their back to the mirror, and really see what they look like from this perspective. The screen can be placed at the side of the mirror so that the user is able to see the pictures they have taken, and replace them if desired.
Now that we have worked out all of our development strategy, found our camera and our software, it is time to put every thing together on a prototype machine. I've got an old P3 which has so many test gadgets plugged into it, I'm sure they'll start talking to each other one of these days. You can pick these up at auction or second hand computer dealers for under $AUD 300. You will probably eventually want to port the system to a laptop, for portability around the home and especially if you going to market the idea to shops, but a cheap prototype is the sensible first step to make sure it all goes according to plan, before investing any serious money.
I found a creative NX Pro webcam. There is a sourceforge site for a driver for this chip, but I haven't had any success with it and discovered another driver which works, by searching the SUSE forums. This is the spca5xx driver which compiled and installed and loaded the modules when I plugged in the camera. Starting xawtv gave a very good night time picture as the NX Pro has some good features for adjusting the picture in low light environments.
If you want to compile the additional spcaview and spcagui software, make sure you install the aalib and SDL development libraries from the SUSE 9.x media.
To grab a single picture from the camera, you can use the xawtv tools. There are two methods, one used while xawtv is running and one without.
While xawtv is running the command is:
xawtv-remote snap jpeg win $HOME/mypic1.jpg
and without is, presuming the webcam is on the first video device:
v4lctl -c /dev/video snap jpeg 640x480 $HOME/mypic2.jpg
As you can see from the second command, you can set the size of the picture. Look at the man page to see everything you can do with this great tool.
So the simplest form of the $HOME/IKEA/bin/grabpic.sh shell script is
#!/bin/bash #grabpic.sh picnumber #Grabs a pic and saves it to $HOME/IKEAM/tmp/file$1.jpg #Use v4lctl to grab picture #Assumes to camera is /dev/video and xawtv is not running. # v4lctl -c /dev/video snap jpeg 640x480 $HOME/IKEAM/tmp/file$1.jpg
Don't forget to set the executable flag on this shell script with
chmod +x $HOME/IKEA/bin/grabpic.sh
Turn your RunRev development into a standalone and execute it. Try it out to achieve the best placement of lights and mirrors for your purpose. Try it out with a full length mirror and your sister/girlfriend/wife/daughter/mother and show them what they look like from the front/mirrored/leftside/back/rightside. Do the same for make up and hair styles. Sold it to the family yet?
Here are some real pictures. My hacker friends left at the stroke of midnight.
You can see the glasses reflection when I'm looking at the camera placed above the screen, but not when it is grabbing the reflection in the mirror.
So build it, put it on a lap top, and take it with you when you buy your next pair of spectacle frames. Spectacular!
Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com