Carlos Barbosa
Carlos Barbosa

Reputation: 1432

Color detection in AS3 possible?

Hey, i was wondering what do the AS3 experts would do to detect a color with the webcam (red) and draw a sprite on those color boundaries.

Thanks in advance.

Upvotes: 0

Views: 2302

Answers (2)

djip.co
djip.co

Reputation: 1037

I know I'm a bit late to the parade but perhaps it can help others. I just put online a class called ChromaTracker that probably would do what you are looking for.

Basically, you feed the ChromaTracker object with a color and a DisplayObject (it can be a webcam feed assigned to a Video object) and it will detect where in the BitmapData the color can be found. You can then fetch a Bitmap of the detected pixels, a Rectangle object of the outer boundary formed by all detected pixels or a Point object representing the center of the blob of detected pixels.

With that information, it would be very easy for you to add your Sprite on top of the detected pixels. You can download the class plus a demo on my site : http://cote.cc/projects/chromatracker. There is also a full API documentation.

Upvotes: 0

Simon Groenewolt
Simon Groenewolt

Reputation: 10665

You can access the pixel data in BitMap (Or more correctly, the associated BitMapData) to write your own filter, or you could use a BitmapFilter.

You should be able to capture a bitmap from the webcam by drawing Video to a bitmap you create (use draw() to draw the current video image).

So this should get you a bitmap and a way of detecting pixels in it. Now you can change the bitmap to add your own graphics (or put them in a sprite that is on top of the bitmap). Show the bitmap on screen after you've changed it, and repeat this for every frame :-)

See http://www.kasperkamperman.com/blog/flash-code/as3-apply-bitmap-filters-to-a-webcam-image/ for some inspiration.

Upvotes: 1

Related Questions