Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
-
Upload
rocke-zoolander -
Category
Documents
-
view
217 -
download
0
Transcript of Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
-
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
1/8
Through the Interface
October 10 , 2012
Creating a face-recognising security cam with a Raspberry Pi Part 4
This is the final part of the series o n creating a face-recognising security cam. We started by showing how to get
motion detec tion working, and then followed with an initial overv iew and then posts on the separate Facebook
downloader too l and the onboard face detec tion component. In this post, well see how we managed to co nnectup a USB-power ed LED message-board from DreamCheeky.
I was originally inspired to use this dev ice to pr esent the results of the Facecam while hav ing dinner at a friend
place. Hes a fellow geek even his welco me mat says so so we Googled around for a solution and came up wit
the DreamCheeky, mainly b ecause someone had already created a Linux driv er for it.
The device is USB-powered and Im thankfully able to po wer both this and the Logitech webcam directly from
the Raspberry Pi: I dont need to resort to a powered USB hub, which is sometimes needed if your webc am need
more juice than the average.
Here are the steps I followed to install and build the necessary compo nents on the Raspberry Pi:
# Create our main folder
cd
mkdir led
cd led
# Get the libhid source and build it
wget "http://alioth.debian.org/frs/download.php/1958/libhid-0.2.16.tar.gz"
tar -xzf *.tar.gz
rm *.gz
cd lib*
./configure && make
sudo make install
# We need a symbolic link to the libhid output for later
sudo ln -s /usr/local/lib/libhid.so.0 /usr/lib/libhid.so.0
sudo ldconfig
# Get the source code for the dcled component
wget "http://www.last-outpost.com/~malakai/dcled/dcled-2.0.tgz"
tar -xzf *.tgz
rm *.tgz
cd dc*
# Make the dcled component
sudo pacman -S make libusb
make
sudo make install
Im not 1 00% happy with the abov e proc ess: for home use its OK, but as the required library , libhid is licensed
under the GPL license there are serious limitations on how y ou might want to release this as
We realise that this is a serious impediment. The GPL is a "viral" licence, and you w ill only be able to use
libhid in other GPL projec ts. We w ould like to change the licence, but libhid uses the MGE UPS SYSTEMS
http://www.mgeups.com/opensource/projects/hidparser.htmhttp://www.last-outpost.com/~malakai/dcledhttp://www.dreamcheeky.com/led-message-boardhttp://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-2.htmlhttp://www.mgeups.com/opensource/projects/hidparser.htmhttp://libhid.alioth.debian.org/http://www.last-outpost.com/~malakai/dcledhttp://www.geekologie.com/2007/04/theres-no-place-like-127001.phphttp://www.dreamcheeky.com/led-message-boardhttp://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-3.htmlhttp://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-2.htmlhttp://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-1.htmlhttp://through-the-interface.typepad.com/through_the_interface/2012/09/creating-a-motion-detecting-security-cam-with-a-raspberry-pi-part-2.htmlhttp://through-the-interface.typepad.com/through_the_interface/2012/08/creating-a-motion-detecting-security-cam-with-a-raspberry-pi-part-1.htmlhttp://through-the-interface.typepad.com/through_the_interface/ -
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
2/8
HID Parser, whic h is GPL, and thus we c annot. Our so lution is to rew rite the HID parser. One o f these day
We are also in contact with MGE, trying to convince them to lo osen the ir licence . If the licencing issues a
solve d, we are likely to re-release libhid under the A rtistic Licence.
That said, there is apparently hope that itll be possible at some po int to swap this module out for an alternative
Once the needed c omponents are built, it should be a simple matter of calling the dcled c ommand to test
whether it display s text properly or not. Here are the usage instructions for dcled:
[pi@alarmpi ~]$ dcled --help
Usage- dcled [opts] [files]
--brightness -b How bright, 0-2
--clock -c Show the time
--clock24h -C Show the 24h time
--bcdclock -B Show the time in binary
--debug -d Mostly useless
--echo -e Send copy to stdout
--help -h Show this message
--message -m A single line message to scroll
--nodev -n Don't use the device
--preamble -p Send a graphic before the text.
--repeat -r Keep scrolling forever
--fastprint -f Jump to end of message.
--speed -s General delay in ms
--test -t Output a test pattern
--font -g Select a font
--fontdir -G Select a font directory
Available preamble graphics:
1 - dots - A string of random dots
2 - static - Warms up like an old TV
3 - squiggle - A squiggly line
4 - clock24 - Shows the 24 hour time
5 - clock - Shows the time6 - spiral - Draws a spiral
7 - fire - A nice warm hearth
8 - bcdclock - Shows the time in binary
Optional fonts:
1 - small - Very small characters
2 - sga - Standard galactic alphabet
3 - small_inv - Very small inverted characters
Y ou can easily test the unit, then, by using this c ommand to send a repeatedly scrolling message to the screen:
sudo dcled -r "This is a test"
If you see the following message, then yo uve pro bably forgotten to run as root v ia sudo:
hid_force_open failed with return code 6
Couldn't find the device. Was expecting to find a readable
device that matched vendor 1d34 and product 13. Is the
device plugged in? Do you have permission?
Y ou can also use the lsusb command to c heck whether the dev ice has be en rec ognised by the Pi.
Now we have the driver working, its a fairly simple matter to c reate another daemo n to look for files in a certai
folder and then send the messages they co ntain to the message-board before deleting them. Well use the "-p 7
option to cause the message to be po sted with a flame-like pre- & post-amble.
Heres the C/C++ code I used to implement this:
https://twitter.com/asbradbury/status/242317798750187520http://www.opensource.org/licenses/artistic-license.phphttp://www.mgeups.com/opensource/projects/hidparser.htm -
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
3/8
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
usingnamespace std;
// Input and output folder locations
constchar * inDir = "/home/pi/faces/out";
// Get the list of files in a directory
int getdir(string dir, vector &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL)
{
char msg[200];
snprintf(
msg,
sizeof(msg)-1,
"Error(%d) opening %s",
errno,
dir.c_str()
);
syslog(LOG_INFO, msg);
return errno;
}
while ((dirp = readdir(dp)) != NULL)
{
files.push_back(string(dirp->d_name));
}
closedir(dp);
sort(files.begin(), files.end());
return 0;
}
int main(void)
{
// Our process ID and Session ID
-
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
4/8
pid_t pid, sid;
// Fork off the parent process
pid = fork();
if (pid < 0)
{
exit(EXIT_FAILURE);
}
// If we got a good PID, then we can exit the parent process
if (pid > 0)
{
exit(EXIT_SUCCESS);
}
// Change the file mode mask
umask(0);
// Open any logs here
openlog("ledmsgd", LOG_PID|LOG_CONS, LOG_USER);
// Create a new SID for the child process
sid = setsid();
if (sid < 0)
{
// Log the failure
syslog(LOG_INFO, "Unable to get SID.");
closelog();
exit(EXIT_FAILURE);
}
// Change the current working directory
if (chdir("/") < 0)
{
// Log the failure
syslog(LOG_INFO, "Unable to change working directory.");
closelog();
exit(EXIT_FAILURE);
}
// Close out the standard file descriptors
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
// Daemon-specific initialization goes here
struct stat st = {0};
if (stat(inDir, &st) == -1)
-
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
5/8
{
mkdir(inDir, 0700);
}
vector files = vector();
constchar *contents = NULL;
/* The Big Loop */
syslog(LOG_INFO, "main loop begins");
while (1)
{
// Get the files in our "in" directory
files.clear();
getdir(inDir, files);
if ((int)files.size() >= 3)
contents = files[2].c_str();
else
contents = NULL;
if (contents != NULL)
{
syslog(LOG_INFO, "found a file");
syslog(LOG_INFO, contents);
char input[256];
input[0] = 0;
strcat(input, inDir);
strcat(input, "/");
strcat(input, contents);
char cmd[200];
snprintf(
cmd,
sizeof(cmd)-1,
"dcled -p 7 %s",
input
);
system(cmd);
remove(input);
}
sleep(0.5); /* wait half a second */
}
closelog();
exit(EXIT_SUCCESS);
}
The simplest way to get this source onto the device is to wget it from this blog. Then its a simple matter of
building it (again, apologies for the lac k of makefile ):
wget "http://through-the-interface.typepad.com/files/LedMsgDaemon.cpp"
g++ LedMsgDaemon.cpp -o ledmsgd
Once built yo u should copy & paste the exec utable to the appropriate folder:
cp ledmsgd /etc/rc.d
-
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
6/8
-
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
7/8
Posted at 04:26 PM in Raspberry Pi | Permalink
Comments
Stu dijo...
Hi Kean
I'm try ing to get the DreamCheeky LED message board working from the Pi as you have , just this bit.
Did you hav e any issues getting LibHid working? I am seeing an awful lot of problems with it on the Raspberry P
Raspbian distro.
For starters it requires LibUsb 0.1 and possibly LibUsb-dev. I hav e both of these co mponents installed v ia apt-
get, but it's still complaining with this erro r during make -
root@raspberrypi:~/kost-dcled-c819fec/libhid-0.2.16# make
make all-recursiv e
make[1]: Entering directory `/root/kost-dcled-c819fec/libhid-0.2.16'
Making all in hidparser
make[2]: Entering directory `/root/kost-dcled-c819fec/libhid-0.2.16/hidparser'make[2]: Nothing to be do ne for `all'.
make[2]: Leaving directory `/root/kost-dcled-c819fec/libhid-0.2.16/hidparser'
Making all in src
make[2]: Entering directory `/root/kost-dcled-c819fec/libhid-0.2.16/src'
make[2]: Leaving directory `/root/kost-dcled-c819fec/libhid-0.2.16/src'
Making all in test
make[2]: Entering directory `/root/kost-dcled-c819fec/libhid-0.2.16/test'
make[3]: Entering directory `/root/kost-dcled-c819fec/libhid-0.2.16/src'
make[3]: Leaving directory `/root/kost-dcled-c819fec/libhid-0.2.16/src'
if gcc -DHAVE_CONFIG_H -I. -I. -I.. -DNDEBUG -I../include -I../hidparser -O2 -Wall -W -Werror -MT lshid.o -M-MP -MF ".deps/lshid.Tpo" -c -o lshid.o lshid.c; \
then mv -f ".deps/lshid.Tpo" ".deps/ lshid.Po"; else rm -f ".deps/ lshid.Tpo"; ex it 1 ; fi
lshid.c: In function device_iterator:
lshid.c:32:87 : error: parameter len set but n ot used [-Werror=un used-but-set-parameter]
cc 1: all warnings being treated as errors
make[2]: *** [lshid.o] Error 1
make[2]: Leaving directory `/root/kost-dcled-c819fec/libhid-0.2.16/test'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/kost-dcled-c819fec/libhid-0.2.16'
make: *** [all] Error 2
Any help wo uld be appreciated.
Thanks
Responder Nov ember 03, 201 2 at 03:23 PM
Kean Walmsley dijo en respuesta a Stu...
Hi Stu,
I didn't hit this particular issue, but then I've o nly built it on Arc h Linux A RM, not o n Raspbian.
http://blogs.autodesk.com/through-the-interfacehttp://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html#comment-6a00d83452464869e2017d3d3e2c9d970chttp://void%200/http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.htmlhttp://through-the-interface.typepad.com/through_the_interface/raspberry-pi/ -
7/28/2019 Creating a Face-recognising Security Cam With a Raspberry Pi Part 4
8/8
Good luck with fixing it,
Kean
Responder Nov ember 05, 201 2 at 10 :00 AM
faust dijo e n respuesta a Stu...
i know it's been a while since y ou po sted, but if you e dit lshid.c in y our libhid/test folder, around line 41,comment out the len = *bit, and add those under:
len = len;
custom = custom;
and it should compile fine. im having lots of errors too, but i did manage to make libhid... dcled doesnt want to
co mpile though..
Responder January 0 1, 201 3 at 07 :47 AM
Thomas Schwaiger dijo...This is cool stuff! I dare yo u hook it up to your doo r locking mechanism, so it only unlocks for yo u and yo ur
family! :)
Responder December 1 7 , 201 2 at 08:10 PM
Kean Walmsley dijo en respuesta a Thomas Schwaiger...
The tech isn't quite there yet, but maybe one day ... :-)
Kean
Responder December 1 7 , 201 2 at 08:12 PM
Comment below o r sign in with TypePad Faceboo k Twitter and more...
http://www.typepad.com/sitelogin?uri=http%3A%2F%2Fthrough-the-interface.typepad.com%2Fthrough_the_interface%2F2012%2F10%2Fcreating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html&fp=afd3c6296bdbdce5087aaffd0d89a510&view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&service=openid&post_uri=http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.htmlhttp://www.typepad.com/sitelogin?uri=http%3A%2F%2Fthrough-the-interface.typepad.com%2Fthrough_the_interface%2F2012%2F10%2Fcreating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html&fp=afd3c6296bdbdce5087aaffd0d89a510&view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&service=twitter&post_uri=http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.htmlhttp://www.typepad.com/sitelogin?uri=http%3A%2F%2Fthrough-the-interface.typepad.com%2Fthrough_the_interface%2F2012%2F10%2Fcreating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html&fp=afd3c6296bdbdce5087aaffd0d89a510&view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&service=facebook&post_uri=http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.htmlhttp://www.typepad.com/sitelogin?uri=http%3A%2F%2Fthrough-the-interface.typepad.com%2Fthrough_the_interface%2F2012%2F10%2Fcreating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html&fp=afd3c6296bdbdce5087aaffd0d89a510&view_uri=http%3A%2F%2Fprofile.typepad.com%2F&via=blogside&post_uri=http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.htmlhttp://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html#comment-6a00d83452464869e2017ee6595d70970dhttp://void%200/http://blogs.autodesk.com/through-the-interfacehttp://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html#comment-6a00d83452464869e2017c34b5ef5c970bhttp://void%200/http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html#comment-6a00d83452464869e2017ee6d3d891970dhttp://void%200/http://through-the-interface.typepad.com/through_the_interface/2012/10/creating-a-face-recognising-security-cam-with-a-raspberry-pi-part-4.html#comment-6a00d83452464869e2017c331ea002970bhttp://void%200/