DIY Video Game Controlled by Head Movement (Augmented Reality)
by woodenProjects in Circuits > Software
837 Views, 4 Favorites, 0 Comments
DIY Video Game Controlled by Head Movement (Augmented Reality)
I want to show You how easy nowadays is to make own game which can be controlled by moving Your body. You will need just a laptop with web cam and some programming skill.
If You don't have a laptop&web cam or if You don't know how to programm, You can still read this instructable as entertainment and than You can play my game, because I'm adding it to this article
Language and Motion Detection Library
There is no need to reinvent the wheel. On internet there are many libraries which handle motion detection and they are made for almost any language and free to use.
I decided to use Java because I wanted my game to be platform independent. It can be run on Winddows, Mac, Linux.
I selected the OpenIMAJ library which allows not only to detect the motion but also makes very easy to display and process graphics. You can see ath the picture attachet to this step, that only using few lines of code I'm able to make motion detection application.
If You know Java and want to try, here is the really fast/simple tutorial on how to detect motion and handle graphics in OpenIMAJ.
I decided to make an Arkanoid game as my proof of concept, because it is really simple to implement.
Short Tutorial to See How Easy Is to Detect the Face
I decided to show You how easy in Java&OpenIMAJ to detect the face. If You don't know programming, just skip this step ;-)
Here You have the code:
//first initialize the screen if HD
VideoCapture vc = new VideoCapture( 1240,720 );
//initialization of face detector
FaceDetector fd = new HaarCascadeDetector(40);
//this creeates the window showing the captured webcam video
VideoDisplay vd = VideoDisplay.createVideoDisplay( vc ); vd.addVideoListener( new VideoDisplayListener() {
public void beforeUpdate( MBFImage frame ) {
//this does the face detection and display the frame around the face on screen
List faces = fd.detectFaces( Transforms.calculateIntensity(frame));
for( DetectedFace face : faces ) { frame.drawShape(face.getBounds(), RGBColour.RED);
}
}public void afterUpdate( VideoDisplay display ) { } });
Making the Sounds
Just for additional fun I made some sounds which make the whole game more playable. I take my son (it was a fun for him) and we made some stupid noises like hitting the rotten banana to fridge doors ;-) Later I postprocess the sounds in audacity and reuse them in a game.
Play&Fun
If You are interested in the full code, it is available here on gitlab. You are free to play with it.
If You are not interested with the code and You just want to try the game, I'm attaching it to this step.
The game is written in java, You can run it in Your console using this command:
java -jar ./target/realkanoid-1.0-SNAPSHOT-jar-with-dependencies.jar
or You can just click on the file and probably Your Windows/Mac/Linux system will manage to run it without any problems.
If You decided to try my game, please write in comment about Your feelings. I'm curious if You find it playable :)