Saturday, March 30, 2013

Camera problems

After two weeks of messing with this, I still can't get consistent function from the webcam with any software.  I've tried motion, mplayer, vlc, and webcam so far.  I have managed to get a few successful image captures from motion, but it mostly just complains about not being able to connect to the camera and other complainy stuff.

I'd like to see them get better OOTB support for webcams on the platform... it was actually easier to write my own webserver for the pi (which I did last week, complete with CGI support!) than to get the stupid camera to work.

Most of my time has been spent with motion, which a co-worker has running on an Ubuntu box at work 24-7.  I've been through every darned setting in the massive config file like 8 times and can get different (wrong) behavior, but none of it amounts to streaming video or even functioning snapshot capture.

Monday, March 25, 2013

Find my pi

Now that I've got the pi up and running, I don't necessarily want to plug it in to keyboards and mice and monitors all the time... it's easier just to feed it 5V and log in from the laptop via ssh which is what I'm doing right now.

I've been doing this by using a broadcast ping from my Mac terminal app.  This just involves pinging the whole subnet by setting (typically) the last byte of the ping target to 255 (all bits = 1).  

Then you get responses from all devices on your local area network.  Unfortunately you have to try them all until you find the right one.  On my home network it tends to always get the same address (192.168.1.124) which is handy.

To enable broadcast ping, you can use this script:

echo '..'

echo '# Disable ignore broadcast request'
echo 'net.ipv4.icmp_echo_ignore_broadcasts = 0'

read -n1

sudo nano /etc/sysctl.conf

Adding the second echo line (sans quotes, echo) to your /etc/sysctl.conf will enable broadcast ping.

Detecting the pi automatically on the network is one of the problems I plan to tackle.  Being able to connect to it with minimal fanfare no matter where I am is a goal.





Bubble Face

So right now I'm mostly working on the plumbing aspects of the camera project, but I've also been working on some prototyping related to facial recognition in Matlab.  I made this video on YouTube illustrating the "bubble face" algorithm I've built to identify the bounding region around human faces in a robust fashion. 



It can be summed up as:

  1. Grayscale
  2. Shrink
  3. Belligerent bells (difference of Gaussian HPF)
  4. High/low edge detection
  5. Morphological filter (1x contraction, 1x dilation)
  6. Bubble Face
The bubble face algorithm itself blows up an ellipse like a balloon with the individual nodes getting "tied up" by edge features.  Every node is attached elastically to its nearest neighbors though, so the balloon can "pull through" features that don't fit.  It stops inflating when it detects something "reasonably elliptical" (based on coefficient of variance of the anchor point radii currently tied to edge features - the red points) and relaxes for a bit (which smooths out the distortion) before inflating again.  It does 3 cycles of this and tends to do a pretty good job of bounding facial features as long as it originates in a location near-ish to the center of the face.

I'm a long way off from thinking about porting this to the pi, but using pi to do some image and audio signal processing will be something I'll get to once I've got a working platform.


Setup

So I've had the pi for about a week now.  I purchased it from Amazon and had it delivered (Prime) at the vanguard of a 4-day blitz of nubbins, dongles, adapters, bit buckets, and encasements.  Here it is!  In all its pint-sized glory...


[Pictured:

  • IOGEAR 4-port USB 2.0 hub (passive power)
    •       Logitech QuickCam (pictured at bottom)
    •       SanDisk 16GB thumb drive
    •       Wireless dongle for ancient Logitech mouse (not pictured)
  • Old Kindle micro-usb power supply (5V)
  • 32GB (class 4... Zzzzz) SanDisk SD card
  • EdiMax WiFi dongle (hiding underneath hub connector)  
Keyboard and monitor not currently attached - in "SSH-only" mode.




[So that's the monitor (next to my MacBook) on the kitchen table.  Up to this point I've been about 50/50 between tiling terminal windows in the built-in X-win environment and SSH'ing in from either the MacBook or the iPad mini (with SSH client and bluetooth keyboard - great for tweaking on things from bed at 2am or during meetings)]




I went with the latest "wheezy" Raspbian distribution (hard float, recommended distro) for a few reasons:


  1. Being new to the platform and wanting to play with lots of different peripherals, suspect that "vanilla" setup will be easiest and best-supported online for troubleshooting
  2. Where possible, want to enable the broadest-possible audience to follow/replicate/improve upon my results
  3. Don't have any compelling reason (yet) to do anything else (well, hard float issues aside.  More on that later...)
The first couple of days I basically spent getting the thing up and running and getting the various pieces of hardware to show up / mount / fulfill each one its unique and special purpose.  

Below is a rough record of what I did to get stuff up and running.  Before trying to use my bumbling as a template for your own endeavors, I'd recommend giving a look to the basic setup guide.

Step 1: Image the SD Card

The first step was of course imaging the flash disk (for a couple of bucks extra you can order a pre-loaded card on Amazon or from one of these guys... no judgment!).  I first tried RPI-SD Card Builder, but for reasons that I could not ascertain and without any sort of useful hints or error messages it kept crapping out on my MacBook after roughly 15 minutes of chugging.  

I didn't try all that hard to troubleshoot - instead tried out the Pi Filler app, which worked on the first try (YMMV).

[As an aside - Pi Filler's IvanX also has a "finder" app to locate your pi on the network without having to plug in a keyboard and other helpful features.  I'd like to see really helpful tools like this get rolled into the standard distribution - more on this later.  Okay now.  Just a teaser.  I've set up a shell script on my Mac shell to do broadcast ping (response to which on Raspbian is disabled by default / out of the box, natch) and then I try them one at a time with SSH until I get a hit, but am working to make this happen automagically. ]

Thanks, helpful free tool providers of the interwebs!  I hope to follow in your sterling footsteps and provide something of value to the community as well.

Step 2: .....

Step 3: Profit!

After imaging the disk, it was pretty much just a matter of plugging in the usb hub, the HDMI-to-DVI cable to attach the monitor (just borrowing the Dell flatscreen from the home desktop), a usb keyboard (also borrowed from home desktop), and a kindle 5-V micro usb charger (we have what must be dozens of these and the like in every drawer in the house accumulated over the past decade).  That's it!

The system boots into the one-time setup screen.

[I highly recommend doing what I didn't do and following the instructions to update raspi-config before using.  The reason I didn't was pure laziness... I didn't want to drag pi+wires+monitor halfway across the house and re-set up in range of a wired ethernet connection.  In point of fact, I have never used the ethernet jack on my pi - it's been wireless from day 1.  It hasn't cost me anything... but really - doing it the right way may spare you some headaches downstream.]

 Here's what I touched:
  1. Turned off the "desktop on boot" option (personal preference, but I always prefer to start in a shell and startx only when I think it will be helpful or necessary, thank you very much - and this goes double for a little guy like the pi).
  2. SSH on (you didn't get a marvelously-portable Raspberry Pi just to have it shackled to keyboards and monitors and the like all the time, right?)
  3. Set timezone
  4. Changed my password
[OMINOUS PAUSE...]

From there it cheerfully booted up in seconds with a perky scroll of crisp, hi-res Linux-y-looking startup commands under the approving gaze of a plump little raspberry overlord (I call him Baron von Raspby).  While this experience may not carry with it the high-polish commercial sheen of the anthropo/mythical ritual unboxing of the latest Apple iThing, it still got my little hobbyist's heart aflutter watching it boot up for the first time...   

Step 3 Revisited: A Cautionary Tale

Fun fact: did you know that our friends across the pond have their very own keyboard layout?  And that the pi comes with this layout (in my experience, 100% of the time) out of the box?  It's called the "GB" keyboard layout, which I understand to be shorthand for Good Bangers (and mash).  While the folks in "Great Britain" speak the King's English, for those of us in the colonies, know this: when you depress the space bar and go "off alpha" - you're in a twisted shadow-world of through-the-looking-glass proportions.  

So with a quick web search I found the appropriate system file to edit (can't remember offhand but I'll post it later) and changed "GB" to "US" so I could get things like my pipe [|] and hashes [#] and whatnot back to their rightful places on the keyboard.  Problem solved.  

So, on reboot of course, I found myself locked out of the pi.  I'm a little slow sometimes, so it took me a few minutes to realize that my password, which (I don't think I'm compromising my pi's security too much to say this on the internet) contains one or more particular non-alphanumeric characters, was not what I thought it was when I originally entered it with the GB keyboard layout.  So I had to go back and look at the GB keyboard layout on Google Images to find out which characters the characters I thought I was typing I was actually typing when I set my password.

So, the punchline is: if you are in the US, just go with the default password (or at least stick to alphanumeric) until you change the keyboard setup.  After you change the keyboard to 'US', go nuts with your 

pi@raspberrypi ~ $ passwd

Summary

So, as long as you don't shoot yourself in the foot like I did (minor detour), the setup is largely painless and for the most part foolproof if you follow the yellow brick road.  I'll post more on the setup of the peripherals (WiFi, webcam, thumb drive, etc.) later on.

(Photo by Silver Screen Collection/Getty Images)

Salutations

Hi!  I'm starting this blog to chronicle the development of a hobby project using the Raspberry Pi platform that I'm referring to as the "Pi Eye".

What is the Pi Eye?

Simply put, the Pi Eye is a standalone streaming webcam on the rPi platform.  The plan is to use as much freely-available open-source components as possible (except when I get a wild-eyed urge to build something ground-up like, say, a web server - more on that to follow).  The plan is to build something cool and useful and to learn some things along the way.  I'm sharing the experience so that hopefully others can benefit from my stubbed toes and blind wanderings (as well as to get input and advice from the community of users).

A quick tidbit on background: I'm a moderately-skilled programmer and linux user.  My background and schooling is in digital signal processing but I have been in analytical business applications software (SaaS / Cloud "Predictive Analytics" software) for the past 10 years.  I'm most familiar with C/C++ and C# and have used Visual Studio for most of my professional career, but have also used Java, eclipse, and Linux-based development.  My focus has always been on mathematical algorithms and I do a lot of work and prototyping in Matlab, for what that's worth.

I make no claims to being an expert in any of these languages or platforms, but part of the fun of this project for me is getting back into Linux-based dev (something I haven't done much of professionally for upwards of 5 years).  I'm kind of ecstatic about the pi platform and its possibilities, and hopefully can convince a couple of folks to give it a look.

Another objective is to build some tools for the platform to provide a smoother "on-ramp" for non-*[nix/nux]-hax0rs.

Hopefully a few folks in the hobbyist/pi/enthusiast communities will find some of this interesting (or, more selfishly, provide me with some tips and pointers).  I'll make all of the code freely available as well under some TBD minimally-restrictive license.