Sunday, March 30, 2008

Enhanced version of head tracking and openGl

This video shows my enhanced approach - using CV_HAAR_FIND_BIGGEST_OBJECT - to combine OpenCV head tracking with a 3d OpenGL environment so that the user will see objects from their head's point of view. Since this headtracking is 2d, no depth information has been obtained still, although I'm planning it for some next post. Now, it takes around 20 ms for the face recognition algorithm, which gives a nice refresh rate.

Thanks to Vadim Pisarevsky for the function.

41 comments:

Sam said...

That is a truly amazing idea! Any chance you're releasing the code for it?
oorelisysoo@gmail.com

Daniel Lélis Baggio said...

Thanks, Sam :)
I'll make the code available, but I'll clean it up firstly.
I'll send some of what's available through e-mail for now.
This code is going to be present in my project at NUI http://code.google.com/soc/2008/nuig/about.html
Be with God :)

Paul de Lange said...

I thought I was the only one who had had this idea...

To overcome the jumpyness I tried adding some 'momentum' to the objects. The idea was they would keep moving until the next head position was detected (at which point the code would adjust itself for smooth movements). ie: the screen is refreshing at 30hz but the tracker is only refreshing at 10hz or whatever. It helped a little when you only moved in one direction but it was probably more jumpy during direction changes.

It was an idea that might work if I could get some time to play with it more.

Feel free to use it.

danieru said...

Hi Daniel,
Cool stuff:-) I've been wanting to setup something similar for a while to control the cursor with head movement. I've just started playing around with opencv. The sample program facedetect.c works quite well with the haar cascades that came with opencv, but like you said the default settings for the cvHaarDetectObjects function are not really fast enough for realtime (I was getting between 200-300ms per frame). That's when I poked around on google and found your blog. I'm quite interested in the "CV_HAAR_FIND_BIGGEST_OBJECT" parameter, but when I try to compile, the parameter isn't being recognized. What is the actual value? I'm guessing you're defining it before the function call. Here's how I'm calling the function:

CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
1.1, 2, CV_HAAR_FIND_BIGGEST_OBJECT,
cvSize(30, 30) );

thanks if you can provide info on this, and thanks for the informative post!

Daniel Lélis Baggio said...

Hi danieru, in order to get CV_HAAR_FIND_BIGGEST_OBJECT to work you need to checkout opencv from sourceforge cvs, which is more updated than the tarballs. If you need help doing that, just leave me a message.
Full code about headtracking is available at code.google.com/p/ehci
Stay with God,
Daniel

yems said...

Hi Daniel,

i find your experiment very good and i have a big interest of image processing...
please can you send me your code?

I have a private project and think you can help me:
I have a 3D camera and receive some data by him. I have an c++-application which allow me to get the pixel value (like range, intensity, gray,... als unsigned char or unsigned short) from camera...
Now i want to convert this values to get the image (2D or 3D or twice).
Please can you tell me how i can do it using an applicationn or by expanding my application?

What is the difference between OpenCV and OpenGL?

Can you send me too some sample code for understanding?

My application is a console application with Visual Studio C++ 2005

Cheers,
Richard

yems said...

Hi Daniel,

sorry, i had forgotten my mail:
frididy@googlemail.com

thanks,
Richard

Daniel Lélis Baggio said...

Yems,
> please can you send me your code?

You can get the code at
http://code.google.com/ehci
It's in the samples directory.

>I have a private project and think you can help me:
>I have a 3D camera and receive some data by him. I have an c++-application which allow me to get the pixel value (like range, intensity, gray,... als unsigned char or unsigned short) from camera...
>Now i want to convert this values to get the image (2D or 3D or twice).
I don't have any experience with 3D cameras, but I understand that there are basically two types, the ones with at least two webcams (and you have to make some calculus to the the 3d image) and the ones that will make a sweep, which will require some 3d processing to build the image. Maybe you could give more details about the camera, like the model or the API you're using.

>Please can you tell me how i can do it using an applicationn or by expanding my application?
I would need to get a better description of your setup.

>What is the difference between OpenCV and OpenGL?
OpenCV is a computer vision library, it has several algorithms for segmentation, classification, image processing and others.
OpenGL is a graphics library, most used for drawing 3D shapes with textures, lights and shaders in real time (no raytrace).
You should check some NeHe tutorials on OpenGL and the examples that come with OpenCV (check out their 1.1 version!).

>Can you send me too some sample code for understanding?
Take a look at the code in ehci project.

>My application is a console application with Visual Studio C++ 2005
Could you send some output of the application?

Stay with God,
Merry Christmas!

Anonymous said...

hi,daniel
i tried running the headtracking code but i got an error that ehci.h file is missing...

Anonymous said...

hi daniel,

can u also please send me the code of your enhanced version...


manchu_cse@yahoo.co.in
please help me!!!!!!!

Daniel Lélis Baggio said...

Manchu,

the official last version is 0.5 and you can get it from here:

http://code.google.com/p/ehci/downloads/list

The 0.6 is almost ready, but it's only in the svn right now.

I don't know what's your compilation environment, but should be something like this:

On Linux you'd probably need to add the -I /path/to/where/ehci.h/is (notice that it's a capital i, for include),
and in Visual C++ you'd have to add the same directory to your includes in your project settings.

[]'s

Anonymous said...

hi daniel,
i am working on windows environment ..... can u please tell me how to include the path in windows?....

Daniel Lélis Baggio said...

For sure.
Check out this link:

http://www.lavishsoft.com/wiki/index.php/Visual_Studio_Paths

You're all set :)

[]'s

Anonymous said...

hi daniel,
thank you ...
do the face tracking code works only for a single person?
i tried with the camshift demo code that's available in the opencv environment and it tracks only one person at a time.. Actually i wanted to track more than one person .... Is the latest version working for the multiple person tracking?

Anonymous said...

hi.. daniel check out your mail...

Anonymous said...

hi daniel ..
this is manchu i have sent you a mail.. please check it out.. can you please help
me.. opencv facedetection code in linux could not find the camera .. i am using gqcam but when i try to open gqcam i get a window with a green screen ...

Joe Dunfee said...

I've been interested in this topic for a while now, though I don't have enough programming ability to do much with it. In my case, my interest is in regards to CAD visualization, since 3D machine design is what I do for a living.

I wanted to encourage you to consider integrating some of your work into an existing CAD program. This is because I keep reading about university projects where someone does something like what you've done, but the project never goes beyond the demonstration phase. It never gets used for anything practical.

If you make your program integrate with any of the CAD programs, then you will end up with something that is useful in the real world.

Joe Dunfee cadcoke4@yahoo.com

bhatti said...

my project is face recognition but i want to know some help from u
how i can initiate this project
which plateform would be better
or code

thanks

Daniel Lélis Baggio said...

There's an implementation of face tracking in OpenCV's library.
You just need to install and run it.
http://sourceforge.net/projects/opencvlibrary/
Good luck!
(it is called facedetect and you should run it as
./facedetect --cascade=../../haarcascades/haarcascade_frontalface_alt.xml )

Anonymous said...

hi... daniel
This is manchu.. i tried to execute the code in linux but was stuck with the camera issue.. couldn't make up till the last .. but i have completed with my project in windows... thank you for helping me...

Daniel Lélis Baggio said...

It's great that you've succeeded with your project.
You are welcome.
[]'s

Tommy said...

Hi Daniel,

I am very new to OpenCv. I am running it from Windows Platform. Which package and version should i download in order to run CV_HAAR_FIND_BIGGEST_OBJECT? I have opencv_1.0 with me now. Please help! Thanks

Daniel Lélis Baggio said...

Hey Tommy, OpenCV is very cool :)

Just get the 1.1pre (http://sourceforge.net/project/showfiles.php?group_id=22870) and you'll be fine.

Come back here in case you have any problems,

stay with God,
Danny

Tommy said...

Thanks dude, I have just got it fixed. Do you have any idea to lower down the false positive for the OpenCv Face Detector? I am using the original haar trained cascade.

Thanks all.

Daniel Lélis Baggio said...

That's great!

The straightforward idea would be to decrease the scale factor to something near 1.0 and to increase your webcam resolution.

You could as well try different Cascade options, like using CANNY or other parameter.

Another one would be to increase the negative images in the cascade, but it would require training them again.

Good luck,
kind regards,
stay with God!

Tommy said...

Hi Daniel,

I have downloaded ehci. How should I use it in Visual Studio? Is it required setting like OpenCV. Where can I find the configuration steps?

Tommy said...

Hi Daniel,

I tried to compile your boxView3D.cpp
In VS08, I dont have the header unistd.h so I disabled this and usleep(100). All the errors gone except this one:
Error 1 fatal error LNK1107: invalid or corrupt file: cannot read at 0x996 D:\Program Files\Ehci\lib\ehci.h

The error pointer stopped at:
#ifndef EHCI_H_
#define EHCI_H_
in ehci.h

I need your advice bro. Thanks.

ASHISH said...

hey daniel,
I am doing a project for 3-d model reconstruction of face using 2-d images .. can you help me with necessary to do list for opengl library....
Also I need help wid initialization for 3d graphics in Visual Studio C++ environment...

Daniel Lélis Baggio said...

Hey Ashish,
you'll get a good idea on how to set up OpenGL in Visual Studio C++ through Nehe's tutorials:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01
After you dig into that we could discuss your ideas on the 3d model from 2d :)
Kind regards,
Daniel

Anonymous said...

dear Daniel,
Would you like to write step by step how to build on Visual Studio C++?

regards

Daniel Lélis Baggio said...

Shame on me...

There's an easy way to create the Visual Studio files with the CMake or SCons... I should have done it...
But basically, you'll need to include OpenCV's .h and link to their libraries, pretty much like how it's described here:
http://opencv.willowgarage.com/wiki/VisualC%2B%2B

Thanks for your point,
Daniel

daynie said...

thankyou Daniel,
I've been read the instruction on http://opencv.willowgarage.com/wiki/VisualC%2B%2B.
Now, I want create the "ehci-0.6 project" and setting for Include, Source and Library files.
Which file in "ehci-0.6.tar.gz", I should added into MVisStudio2008?

regards,

goodeda1122 said...
This comment has been removed by a blog administrator.
dandumit said...

Hi,
It is very interesting. Could this be used for recognizing electronic components ? I mean shapes like rectangles generally and their position (X-Y and rotation) ?

REgards,
Daniel

Anonymous said...

Daniel, I am trying to get opencv to pass a parameter value to openGL (openGL has loaded a 3d model) however I have struck a problem. I can't get openCV and openGL to work at the same time, the main issue is glutMainLoop(); once this is called it grabs control of the program and I can no longer get any data from opencv. Hw did you get around this issue in your application? Did you use freeGLUT? I am working on the MacOSX operating system.
Thanks in advance for any help.

Michele Giacalone said...

Why don't you make it multithreaded?
Rendering and face detection should be done in different processes.

gargsajal9 said...

Nice idea!!
As i am a new comer to opengl n opencv... i want to know how to run the opengl object movement n opencv head detection parallely... as opengl object n opencv head detection both are in infinite loop.... so i m kinda struck now..

gargsajal9 said...

Nice idea!!
As i m a new comer to opengl n opencv..
i want to know how to run the opengl object movement n opencv head detection parallal..
As in mine opengl object n opencv head detection are in infinite loop... so only one can run.. i m kinda struck now.. help plzz
Sajal

ashu said...

Hey, im ashu. Im doing project on OpenCV to communicate with API's. Can you pls help me with your coding pls.
ashu.shrff8@gmail.com

Flexi-Eload Prepaid said...

Can i have the samples code to use OpenCV with OpenGL? Thanks..

fook1987@gmail.com

Elisa Agustina said...

This is great idea! May I learn from your code, to build an application using openCV too?
Please send to elicelz@gmail.com
Thanks

Cheers!