开发者

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜