Monday, March 5, 2012

Helicopter Auto Pilot - Camera Tracking (h-c-d-L)

Back to Helicopter Auto Pilot - Introduction
Download source code & runtimes: Heli Control

Camera Tracking (h-c-d-L)
For tracking the helicopter I'm using a Logitech HD 1080 webcam capable of 30 fps. After processing the images it slows down to approximately 27 fps.

For processing the image I adapted, in a very rudimentary fashion, a C++ program I found somewhere in the internet that can read the frames from the camera and processes them trying to find the brightest spot in the picture. For that reason the best situation to use this is indoors and at night when no sunlight can penetrate the room. You don't need to have the lights off but you must avoid having any strong light source like lamps, leds, screens or some reflective surfaces.

The program is in the folder called HeliFind. It was compiled using C++ Express 2010.
The program requires OpenCV 2.2.

Same as the wiimote script this program sends the tracking information to a specific ip and port.
The current version has the IP and port hardcoded in Video.CPP:

RecvAddr.sin_port = htons(53525);
RecvAddr.sin_addr.s_addr = inet_addr("");

If someone is interested I can change this so it's a parameter when you run the program. Otherwise you can change it yourself.

After you run the program an empty window opens, click on Help/About and it starts to track the brightest point in the image. For better performance turn off all automatic processing from the camera like True Light, True Sound, Auto White Balance, Auto Focus, and reduce exposure and brightness to a minimum. Your image should be almost black except for the LED in the helicopter.

Back to Helicopter Auto Pilot - Introduction


Tim said...

Great tutorial and videos. Thanks especially for the video about decoding the IR stream from the controller. Do you think it would be possible to replace the helicopter's LED with an IR led instead an place a filter over the webcam to block the visible light. It may make it more robust in various light conditions. The reason I propose this is because my only decent camera is the Wii Remote camera that I have been using for the Wiimote Whiteboard.

Tim said...

Perhaps another reason to use the Wii Remote's infrared camera instead of the Logitech webcam is that the Wii Remote is wireless, giving you the freedom to locate the camera anywhere, without needing a second laptop/computer, assuming the one PC is powerful enough to handle it. My understanding is that the Wii Remote's camera has a resolution of 1024 x 768 at 100Hz.

TechMind said...

Hi Tim
Thank you.
That was actually my first choice, to use the wiimote. I liked the fact the wiimote could do the tracking by itself at very high speed. I tried replacing the helicopter LEDs with IR LEDs. It didn't work for me mainly because the IR LEDs I used did not have enough range and viewing angle so they needed to be very close and point directly at the wiimote to be trackable.

I've also read the wiimote works at 100hz but I also read somewhere else that the actual rate is closer to 50hz which is still pretty good. With the logitech I got about 27hz.

I encourage you to try it (with just the leds first no helicopter), with more powerful LEDs you may have better luck than I did.

If you succeed, not only you can place the wiimote anywhere, you can also hold it in your hand and control the altitude that way, just by pointing it at the helicopter.