Monday, June 11, 2007

Pong Playing Computer playing against another computer using a webcam as an eye!


Download video (5.54 MB)

Several years ago, when I was a stupid little schoolboy, I created a really fun and addictive game called Ping Pong. It was based on the classic arcade game, PONG, and had some cool features like gradual speed increase, two game modes, and some neat sound effects.

I had almost forgotten about that game until I saw this auto wood-chopper project in which a computer plays a simple game on a PSP using only a webcam to view its screen. I thought the idea was pretty good. So, I decided to make my own computer play that old pong game of mine on another computer using a webcam for vision! I fired up my code editor, and after several hours of coding and experimentation, my image recognition code started looking good. It uses edge detection to determine the boundaries of the ball and the bat in the webcam’s field of view. The area of the ball is more than the bat, so that’s how it differentiates between the two. The other steps are more or less similar to the things I did for my object tracking app. Like the auto wood-chopper dude, I thought about using motors to press the keyboard keys on my laptop. However, I thought it would be overkill when I could write a simple TCP client/server program to establish communication between the two computers.

Be sure to watch the video above! I’d love to hear what you think. Oh and here’s a similar project in which a computer plays Minesweeper on another computer using a webcam – wow!

You can download my fun Pong game from here. (1.20 MB)

This was a very exciting project. In my opinion, one of the coolest webcam based projects I’ve done so far. I entered the world of webcams after working on CamCapture – a project based on a Coding4Fun article by Scott Hanselman. :) Webcams are fun but I sometimes wonder why they’re called Webcams. I never use them for online video conversations! In my opinion, they should be simply called USB cameras. :)

38 comments:

Anonymous said...

Wow...you're amazing.

Jonathan Zuck said...

Awesome!

Ashish Derhgawen said...

Thanks :D

Anonymous said...

Simply cool .. :-)

Anonymous said...

Man this pisses me off, the damn computer plays pong better than me! ;)

Anonymous said...

i want to have time to do such things ...
Very cool :>
Next step : a robot & real ping pong table ?

Anonymous said...

Well done Ashish! that was well thought of and executed.

Anonymous said...

really cool! you are becoming an expert on cameras and image recognition! :)

next step is face recognition for a robot, i think ;)

Ashish Derhgawen said...

Thanks everyone. :D

@nico: Real ping pong? That's a really cool idea..but I bet it'll be really difficult too! Well..I guess nothing is impossible. :)

@niko - italy: Thanks for the comment. :) I've been thinking over face recognition for quite a long time..its a really cool thing. Some people have definitely achieved face detection..I have no idea how advanced face recognition is right now. I guess face detection should be the first step.

Anonymous said...

Soooo ehm who won?

Anonymous said...

I'm a little disappointed.

With the information provided you could have your "bot" determine the angle and velocity of the ball in a fraction of a second, and have the paddle be exactly where the ball will hit every time. Rather than simply matching the y-coordinates.

And better yet, it could adaptively use the full length of the paddle to put the ball as far away from the other player as possible.

Nice idea, but you could do better.

Ashish Derhgawen said...

@jared: I thought about determining the angle and velocity of the ball..but then I thought it would just make things more complicated. However, I think I'll give it a try. :)

Anonymous said...

That's pretty cool! So who won? And how long did it take? I assume neither opponent won if you didn't increase velocity.

Ashish Derhgawen said...

Yeah, they keep playing for hours if I don't increase velocity. If I make the ball go really fast, the image recognition code ultimately fails to track the ball quickly enough. :)

Anonymous said...

Awesome!!!!!!

Unknown said...

Sweet!!

Anonymous said...

Thats pretty neat ! Keep up the interesting work.

Anonymous said...

Great Idea ! Now we are closer to Terminator Scenario!

Anonymous said...

In a hurry, but check this out: http://www.imageaddicts.net/uploads/collision.jpg

Anonymous said...

After work, I checked the file I uploaded. The resolution was low. Try this higher resolution grayscale version:

http://www.imageaddicts.net/uploads/collisionBIG.jpg

Eventually I will get around to fully implimenting this method in my flash pong game.

For anyone out there looking for info on line intersection detection or how to test if two line segments intersect, I have plenty of code to share.

Anonymous said...

Nerd... Nerd... Nerd...

Anonymous said...

soo cool

cautionsign said...

it is cool. very cool enough~

Anonymous said...

Not bad ;) I love pong!

Anonymous said...

Cool software Ashish.

Anonymous said...

What programming language did you use for the pong game?

Anonymous said...

You could've used Camstudio, instead of Screen Recorder Gold.

Anonymous said...

What's the background music?

Anonymous said...

can u help on how to do that? would u mind to send me steps to make that.... just like yours...im interested b4 in programming..and iv seen what youve got so i like it

Anonymous said...

you can contact me @gbtniel@yahoo.com

Anonymous said...

When both PCs become "aware", we'll have you to thank. Very cool. Nice tune selection.

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

Good Job! :)

Anonymous said...

This is a great site. Thank you for your information. I THANK YOU I SALUTE YOU IT,S A AMZING SITE.

Anonymous said...

Hey,

Thanks for that important information, it really helpful..Interesting article

Tahseem said...

It was your great attempt yaar

sarkar said...

Awesome work!!

Anonymous said...

It is extremely interesting for me to read this post. Thank you for it. I like such themes and everything that is connected to this matter. I definitely want to read a bit more soon.