Thursday, March 6, 2014

Camera as a Joy Stick using Color detection and Tracking (very simple approach)


Just to pass some time and learn stuff I decided to play a vintage Flight Simulation game "YS Flight Simulation". Back in 2006 I used to enjoy this game a lot on my 512MB P4 machine running XP. Makes me nostalgic when I start playing this game. Anyhow, the problem at hand was to control the flight, which has mouse based control by default, using my webcam as a Joystick. Why? Why not. The Logitech webcam I had fit snugly in my palm and I didn't mind straining my wrist a bit. Python and OpenCV was my logical choice (so is every hobbyist's). 
      
           I went ahead and stuck a red marker on the wall. Color based thresholding was done and the red region corresponding to the marker's image was extracted. I kept things simple by removing any other objects adding to the background clutter that have been resting on my table (for an embarrassingly long time)  from corrupting my clean segmentation. I read the screen resolution using functions provided in the win32api module. Once done, I mapped the coordinates of the camera with that of the screen and rescaled the centroid of the marker mask. Executed it. It Didn't work (was far my expectation ). Problem was that the coordinates were mapped improperly in the reverse order. So remapped them and then also used  squared coordinates as against the centroid coordinates directly to make the system more sensitive to motion. You my also use exponential or other non-linear function of the coordinates to achieve faster rates of motion.

No comments:

Post a Comment