Friday, April 11, 2008

Coding4Fun: Webcam Based Laser Tracking for Human-Computer Interaction

Here's a new Coding4Fun article I did - Webcam Based Laser Tracking for Human-Computer Interaction.
In this article, we will put together a program which will allow us to move the mouse cursor on our computers with a laser pointer, and even generate mouse clicks using only a webcam for computer vision.

You can also use it for impressing your friends by drawing things on your computer with a laser.

Enjoy! :)


Anonymous said...

On Coding4Fun you mentioned that your program performs slower if you capturing full resolution.
So your suggestion was to reduce resolution and then program would perform faster.

Here is another solution.
- I've noticed you camera is capturing 28 frames per second. That is a lot for a mouse and a user. if you would skip some of the frames and not process them it should be faster as well. Try to put a timer and grab frames only lets say every 100s milisecond, so you would be processing 10 frames per second as oppose to 28.

This should imrpove performance without reducing resolution.

Take care.

Software Engineer.
Was referenced from

Franklyn said...

Hey ashish i've been following up your projects for a while now , keep up the great work ! . i hope to do a few of these myself during the summer. Anyways i was just wondering if you could make the assumption that the difference in position between frames is small (within a certain threshold) this would mean that after finding the initial position of the laser you could adjust your for loop bounds to search a smaller region of the image for example +/- 50 pixels in length and width from where you first found it, so instead of searching the entire region again you could search a smaller bounded region. I'm not sure if this would work but it seems reasonable.

Franklyn said...

I just wanted to add that even if it doesnt give a performance boost it might curb the adverse effects of improper lighting.

Ashish Derhgawen said...

franklyn: I think I tried doing that to improve performance myself. However, after I added the image processing code (cropping/resizing), I removed it. If it curbs the adverse effects of improper lighting, I think it would be worth adding! :)

Ivan: Humm...when I said that the program performs slower if you capture full resolution, I meant that you won't get a decent frame rate.

Fast performance = Good frame rate

The reason for adding the image processing code is to improve frame rate. If I capture only 10 frames/second, that would slow down the code...wouldn't it?


Anonymous said...

OT: Have been reading your stuff for some time now. Me no hardware-know-all but love programming, computer-graphics. Came across this link, might interest you:


Tadas said...

you are doing a great job. I am making similar system for my diploma in the univercity, but i have a problem. I dont know how to calibrate my system. My camera sees a screen, but of course it is not rectangular, but has some perspective. What i want to do is to make it rectangular - transform the image, but i cant find a method to do that. So i wonder maybe you know how to do that.
If you do could you please e-mail me ( Any help would be very appreciated.


Prashant said...

I haven't looked into your code, but I notice some talk of improper lighting. This is quite easy to correct if you add a preprocessing step to each frame. I am speaking mostly from a Speech recognition background, but the same can be applied in 2D for images:

take fft -> log -> differentiate -> integrate with initial value zero -> exponentiate -> inverse fft.

This should normalize the gain (ie. lighting differences). You can use the open source fftw library. Dont know if that has a .net binding though.

Btw I'll be home for the summer, might visit delhi. Will let you know. Cheers!

Sherwin said...

You work on some really cool projects! Until my previous semester in college, coding was interesting but much like a chore. But the classes I just finished this semester made coding seem much more fun, and the projects you work on prove even more so!

I'm about to work on a project with my own webcam. Just began learning about this library called OpenCV created by Intel. Hopefully it's as easy to use as the Code4Fun's developer package that you use :P

Perhaps I'll also create a blog eventually and I'll let you know! :D

Anonymous said...

this has nothing to do with the webcam based laser tracking, but i was wonder how and/or if it even possible to control this floppy drive stepper motor through visual basic? if you can help me, my email is,

thanks for the time.

Anonymous said...

its in reply to this page:

Joel M. Pinto said...

Hi Ashish,

I am waiting for your next article since april. seems that you've stopped posting. Please continue.

I think that u dont get an idea. Then, why dont u try Color Sensor:
hope you like it.

BazzaBogle said...

Do you have a compiled version for download> .exe?

Alan Parekh said...

Fantastic project (and site). Keep up the great work!

Anonymous said...

Can you please send the software to me via email.

singleinottawa said...

hi Ashish,

thanks for your article and video on this! I was wondering if you can send me the source code so I can try this myself.


Armando Andrés Meabe said...

Hello! Congratulations for your projects (and sorry for my english!), I was doing exactly the same when people of Microsoft Argentina pointed my to your blog. Your version works great!
Maybe I could show you my version when I finish it.
Cheers from Argentina.

Anonymous said...

Hi, I tried to install visual studio, but this overflowing 1GB of developer data crashed my system!

So why not offering a simple .exe-file for testing your work.

And if people then decide to go deeper in your work, then they can download the source.

It shouldn't be, that people spent ours for ours to install software, just to test your program!

So please, make it available for people, like me! :)