Arduino-Powered Webcam Mount    Posted:


Earlier this month, I completed yet another journey around the biggest star in our galaxy. Some of my beloved family members thought this would be a good occasion to send me some cash, and I also got a gift card for being plain awesome at work. Even though we really do need a bigger car and whatnot, my wife insisted that I only spend this money on myself and whatever I wanted.

Little did she know the can of worms she just opened up.

I took pretty much all of the money and blew it on stuff for my electronics projects. Up to this point, my projects have all been pretty boring simply because nothing ever moved--it was mostly just lights turning on and off or changing colors. Sure, that's fun, but things really start to get interesting when you actually interact with the physical world. With the birthday money, I was finally able to buy a bunch of servos to begin living out my childhood dream of building robots.

My first project since getting all of my new toys was a motorized webcam mount. My parents bought me a Logitech C910 for my birthday because they were tired of trying to see their grandchildren with the crappy webcam that is built into my laptop. It was a perfect opportunity to use SparkFun's tutorial for some facial tracking (thanks to OpenCV) using their Pan/Tilt Servo Bracket.

It took a little while to get everything setup properly, but SparkFun's tutorial explains perfectly how you can get everything setup if you want to repeat this project.

The problem I had with the SparkFun tutorial, though, is that it basically only gives you a standalone program that does the facial tracking and displays your webcam feed. What good is that? I actually wanted to use this rig to chat with people!! That's when I set out to figure out how to do this.

While the Processing sketch ran absolutely perfect on Windows, it didn't want to work on my Arch Linux system due to some missing dependencies that I didn't know how/care to satisfy. As such, I opted to rewrite the sketch using Python so I could do the facial tracking in Linux.

This is still a work in progress, but here's the current facial tracking program which tells the Arduino where the webcam should be pointing, along with the Arduino sketch.

Now that I could track a face and move my webcam in Linux, I still faced the same problem as before: how can I use my face-tracking, webcam-moving program during a chat with my mom? I had no idea how to accomplish this. I figured I would have to either intercept the webcam feed as it was going to Skype or the Google Talk Plugin, or I'd have to somehow consume the webcam feed and proxy it back out as a V4L2 device that the Google Talk Plugin could then use.

Trying to come up with a way of doing that seemed rather impossible (at least in straight Python), but I eventually stumbled upon a couple little gems.

So the GStreamer tutorial walks you step-by-step through different ways of using a gst-launch utility, and I found this information very useful. I learned that you can use tee to split a webcam feed and do two different things with it. I wondered if it would be possible to split one webcam feed and send it to two other V4L2 devices.

Enter v4l2loopback.

I was able to install this module from Arch's AUR, and using it was super easy (you should be root for this):

modprobe v4l2loopback devices=2

This created two new /dev/video* devices on my system, which happened to be /dev/video4 and /dev/video5 (yeah... been playing with a lot of webcams and whatnot). One device, video4, is for consumption by my face-tracking program. The other, video5, is for VLC, Skype, Google+ Hangouts, etc. After creating those devices, I simply ran the following command as a regular user:

gst-launch-0.10 v4l2src device=/dev/video1 ! \
    'video/x-raw-yuv,width=640,height=480,framerate=30/1' ! \
    tee name=t_vid ! queue ! \
    v4l2sink sync=false device=/dev/video4 t_vid. ! \
    queue ! videorate ! 'video/x-raw-yuv,framerate=30/1' ! \
    v4l2sink device=/dev/video5

There's a whole lot of stuff going on in that command that I honestly do not understand. All I know is that it made it so both my face-tracking Python program AND VLC can consume the same video feed via two different V4L2 devices! A co-worker of mine agreed to have a quick Google+ Hangout with me to test this setup under "real" circumstances (thx man). It worked :D Objective reached!

I had really hoped to find a way to handle this stuff inside Python, but I have to admit that this is a pretty slick setup. A lot of things are still hardcoded, but I do plan on making things a little more generic soon enough.

So here's my little rig (why yes, I did mount it on top of an old Kool-Aid powder thingy lid):

And a video of it in action. Please excuse the subject of the webcam video, I'm not sure where that guy came from or why he's playing with my webcam.

Comments

Incompetent Secretaries    Posted:


Attention!

This is an opinionated rant. If you're offended, that's your problem. Feel free to leave comments about your hurt feelings.

Attention!

To the secretary/assistant: If you're reading this, I truly apologize for any offense you may take from my article. If you're new to the job, I'll apologize again--it's not always easy to hit the ground running. I'm just trying to understand the world a bit better than I did when I woke up this morning.

Several weeks ago, I received an email from the secretary/assistant of my Computer Information Technology department chairperson. This email contained a request for me, as a student graduating with a degree in CIT, to fill out a survey to gauge how well the program is functioning from my perspective.

Attached to said email was a Microsoft Excel spreadsheet, formatted for Excel 2007. As an avid Linux user and open-source advocate, I am appalled when I encounter simple files that are not formatted in what could be considered the "lowest common denominator" format, especially when they come from my CIT department. So many other formats would have worked just fine: .doc, .xls, .rtf, .txt, and even the infamous PDF with editable form fields. Come on folks...

Anyway, it's not so revolting to me when other departments send out such abominations. But when the files come from a department which teaches and encourages the use of Linux and whatnot, there seems to be a problem. Several full-time CIT professors even refuse to use Windows and instead choose to use a Macintosh. Yeah, sure, our university requires that students have Microsoft Office for a lot of classes, and they still provide computer labs with the software if we're too poor (or opinionated, like me) to buy it ourselves.

After getting over my own self-righteousness about file formats, I decided to download the spreadsheet anyway. I opened it up in my trusty OpenOffice and filled in the appropriate details. When it came time to save the file with my responses, I opted for OpenOffice's default spreadsheet format: ODS. In my mind, I figured that this individual, the secretary/assistant to the department chairperson, must have access to something that can at least read ODS files.

Well, I mailed off the survey last night. This morning I received the following response from the department chairperson himself:

I dont know what program you used but it is not working with my computer.If you could save it in another program and send it to me again as soon as possible that would be great. Thanks so much

There's something to be said about a CIT department chairperson, the official representative of the program, who is unaware of the ODS format. There's no excuse for that. I like the department chairperson, so I won't rag on him much. Instead, I'll rag on his little helper. When I returned home from class today, I found this email in my inbox, from the secretary/assistant:

I have an hp computer and my windows programs are 2007. If you could change something on the file that would make it so i can read it that would be very helpful.

Wow. Seriously? Apparently it makes a difference in this person's mind that their computer is an "hp" (so is mine). And the "windows programs are 2007," eh... What an ambiguous statement. I sure hope this individual is not a CIT major, minor, or in any other way affiliated with technology.

My question to you is this: how often do you encounter individuals who are blatantly incompetent to be fulfilling the duties with which they have been tasked? I mean, shouldn't there be some reasonable expectation that a person working in a position, such as this secretary/assistant, have some (even rudimentary) working knowledge of the industry in which they are employed? Or am I simply expecting too much from my peers? Am I asking too much of this poor individual who is the target of today's rant?

If I am not alone in my frustration, please speak up. Please also let me know if I am just being cruel and unusual.

Oh, and if you're wondering, I am going to send the survey back in a format that is more portable... I'm not that mean, despite what you might think after reading this article.

Comments