Head Tracking to Create Window Effect - CvIrrCamController

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Head Tracking to Create Window Effect - CvIrrCamController

Post by FreakNigh »

I made a little class to control your camera position in relation to where your head is. It uses opencv to do the head tracking with a webcam. The code has been tested with linux and comes with windows executable. Constructive criticism only please.

This lib will properly (should, I did a ton of testing..) be able to handle any cam position and target correctly. It also lets you change the target and position during action, and has a debuging feature to let you watch yourself in the cam.

Youtube video of the demo code: http://www.youtube.com/watch?v=nciqfiKD8_g

"Lib" download: http://hestia.nighsoft.net/files/CvIrrC ... .1.tar.bz2

winrar and / or 7zip should be able to handle unzipping a *.tar.bz2

Image
Last edited by FreakNigh on Mon Aug 04, 2008 11:17 pm, edited 3 times in total.
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Post by FreakNigh »

And this is the test.cpp that uses the class. The actual class files cpp / h are here.. http://hestia.nighsoft.net/files/CvIrrC ... .1.tar.bz2

It is all based off of the simple tutorials given by both irrlicht and opencv.

Code: Select all

#include <irrlicht/irrlicht.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>

#include "CvIrrCamController.h"

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

IrrlichtDevice *device;
IVideoDriver* driver;
ISceneManager* smgr;

int main()
{
	device = createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16, false, false, false, 0);
	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
   
	device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
   
	//something for 3d reference
	IAnimatedMesh* mesh = smgr->getMesh("media/sydney.md2");
	IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
	if (node)
	{
		node->setMaterialFlag(EMF_LIGHTING, false);
		node->setMD2Animation ( scene::EMAT_STAND );
		node->setMaterialTexture( 0, driver->getTexture("media/sydney.bmp") );
		node->setPosition(vector3df(10,10,-10));
	}
	
	//and some more
	device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
	IAnimatedMesh* mesh2 = smgr->getMesh("20kdm2.bsp");
	ISceneNode* node2 = 0;
	if (mesh2)
		node2 = smgr->addOctTreeSceneNode(mesh2->getMesh(0), 0, -1, 128);
	if (node2)
		node2->setPosition(vector3df(-1300,-144,-1249));

	//camera stuff
	ICameraSceneNode* camera = smgr->addCameraSceneNode(0, vector3df(50,5,50), vector3df(0,0,0));

	//load our controller class
	CvIrrCamController* cam_control = new CvIrrCamController("haarcascade/haarcascade_frontalface_alt.xml");
	//set it to control our camera
	cam_control->setCamera(camera);
	//start the webcam
	cam_control->startWebcam();
	//and this unless you dont want it
	cam_control->ShowDebugWindow();

	while(device->run())
	{
		int x, y;
		
		//update the camera position based on head tracking
		cam_control->UpdateCamPosition();
		
		driver->beginScene(true, true, SColor(255,100,101,140));
		
		//draw some lines for effect
		/*
		for(x=-200;x<=200;x+=50)
			for(y=-200;y<=200;y+=50)
				driver->draw3DLine(vector3df(x,y,200), vector3df(x,y,-200));
		*/

		smgr->drawAll();

		driver->endScene();
	}
   
	device->drop();

	return 0;
}
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Hey that's pretty wicked, you seem to be doing alot of webcam related stuffs. I was thinking of doing something similar to this by placing an ARToolKit marker on a baseball cap and tracking that.

Oh I just refreshed and saw your code snippet, that's so easy to get working, good job on that.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Post by FreakNigh »

I was thinking the SAME EXACT THING with artoolkit!! I almost got the code working to use artoolkit and irrlicht (instead of artoolkit and opengl) but those matrix's are still a pisser for me atleast. Then I want to make that into an easy merger lib too... I have to do all this stuff for work so I thought I'd spend the time to make some libs out of it all..
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

hey that is pretty cool nice job.. sub for sub on the tube man.
FreakNigh
Posts: 122
Joined: Thu Oct 19, 2006 7:31 am
Location: Orlando FL, USA
Contact:

Post by FreakNigh »

Latest version 0.3.8 now tracks 3D with speed regulation for noise filtering and also has feature tracking for when the algorithm loses the head.

youtube - http://www.youtube.com/watch?v=ILwTAG8XbmA

download code - http://www.nighsoft.com/index.php?game= ... controller
frarauj
Posts: 2
Joined: Wed Sep 24, 2008 7:46 pm

Post by frarauj »

man, thats awsome. That could generate a great product for fairs and exibitions.

I tried to compile your code, but i'm getting the error LNK1104 "cannot open file highgui.obj"

could anyone give me some light about that problem?

thanks!
Crank
Posts: 10
Joined: Fri Jan 09, 2009 2:37 am

Post by Crank »

For somereason, it seems like you class is not compatible with linking to the latest version of opencv. Are there any license restrictions on this? Can you also update the original post with your latest build, I found a higher on while searching google, but the link was dead.

If you dont mind, a small guide on how to link to opencv would be awesome. Im interested in using this for a project im working on. I will need commercial approval of you im guessing. If you need to, please email me at:

crank@sylereanonline.com

Thank you.
SushiBox Productions
Post Reply