Before being on holidays I wanted to complete this other personal project using my favourite two toys: Python and Blender
Today I’ll show you how to get with cheap technology such as a webcam, a pen and a laser, cool things like object tracking in the BGE. Of course when you don’t have enough money to buy awesome (and really expensive..) hardware, then you go with software solutions.
First of all, what’s object tracking? For those who don’t know it yet, it’s a “is the process of locating a moving object (or several ones) in time using a camera. An algorithm analyses the video frames and outputs the location of moving targets within the video frame.” (from Wikipedia) So basically, it’s like the computer is able to see and detect moving objects. There are many approaches to this, I used laser lights and color-tracking. Somehow color-tracking is simpler, but my plan is of course to do full motion tracking in the future. Unfortunately I couldn’t use OpenCV because my webcam was not supported, so I used Videocapture to get PIL data from the webcam, Python Imaging Library (PIL) to handle the matrix and sockets to communicate internally with Blender. Why sockets? Read my previous post
Laser tracking is simpler, however you can’t have depth which restricts movements in the BGE to two dimensions. On the other hand tracking objects is good if you want to have a full 3D interaction. How do you get the depth? Just checking the size of the bounding box area, when it gets bigger it means the object is closer and viceversa. Another important concept in this is the threshold. You need some time to tune it in order to get a perfect tracking. Spheres are the easiest to track since the shape doesn’t change if you rotate them. I didn’t have any sphere, so I used also a red d20 from my dungeons and dragons kit
Anyway, stop talking, enjoy the video and if you have question post it below
Sources will be available in a couple of days, I need to clean them up a bit from test code and write also some comments. If you are interested in another cool thing about webcams and BGE check this video made by Nathan Letwory, one of the Blender’s coder living here in Finland who I never had the pleasure to meet, but just exchange a couple of emails
Edit: look at what Mike Pan did using BlenderTrack, amazing and brilliant idea. I was actually wondering how to head track using this script, but Mike was faster and smarter than me
Enjoy his video and let’s see what comes next!