Live Webcam Chroma Keying in Flash

A example of why people use green screens when doing chroma keying

A example of why people use green screens when doing chroma keying

Hi guys had a friend ask me today if Flash can do chroma keying for a webcam,

i said it could and gave instruction to the various functions and processes required, however 15 mins later decided this was a jolly fun thing to attempt to do, several hours and much playful tinkering later…

Got the working demo here

As always (or at least where I feel I can without compromising projects) here’s the full source

(ps tried to keep the code as simple as possible, so should be fairly easy to reuse)

Ant

12 Responses

  1. Great post, Thank you for sharing,

    Mark - December 29th, 2008 at 8:34 pm
  2. Cheers I think, I can’t tell if your a bot which would be bad and make me sad

    Or your a developer, in which case it would make me happy, if also somewhat jealous of the subject matter your working on…

    hmm…

    Zapper - January 4th, 2009 at 4:09 pm
  3. Hi,

    great stuff,
    I’m using your source to make an interactive chroma instalation, for my graduation at art school, i’m looking for a way to include some sort of collision detection to really make it interactive.

    sorry for my poor english and many thanx for the share

    Iris - May 4th, 2009 at 12:38 pm
  4. nice, you could try a pixel colour test on one of the thresh hold bitmaps, if you send my a wee sample i’ll have a wee look for you

    Zap

    Zapper - May 6th, 2009 at 9:55 am
  5. Hi,

    thanx, very nice!

    The “fade” range kept being a bit noisy, I’m getting better results by using
    wanted_percentage_int = 1 – (eudian_dist_int – chroma_fade_distance_squared_int)/(chroma_distance_squared_int – chroma_fade_distance_squared_int)

    (line 208 in your example)

    Aart Jan - May 30th, 2009 at 11:12 am
  6. Cheers mate, yeah there’s a few bits that were done in a rush could definately be improved

    remember having to build it pretty quick, it was part of some experiments i was doing, in the head of bbc scotland’s private office, only had about 2-3 hours to do the lot

    it was really well sound proofed so i had machine head full volume, giant wide screen projector, dimmed lighting, it was really cool, musta looked wierd to everyone outside the office, as it was all glass walls

    shame i haven’t been able to release the wii controller 3d geasure engine, it was really cool, this was just a side part,

    i’ll have to see if they’ll let me release the code base

    Zapper - May 30th, 2009 at 12:25 pm
  7. Hi,
    I’m using your source to build an interactive art installation. But I’m running in some problems. I’m exporting your “webcam_after_mc” to a png file using the png enconder classes from adobe.(it’s an AIR app). These images i’m intended to display them on top of another webcam feed.

    Now your keying works great! No troubles with that. The only thing I’m running into is that the exported image is not a transparent one. The keyed elements are all white.

    So can you help me to get those key’ed elements transparent?
    Greets,

    Michiel

    michiel - June 15th, 2009 at 4:31 am
  8. Ah i see , instead of “webcam_after_mc” use “after_bitmap.bitmapData”

    http://livedocs.adobe.com/flex/3/langref/mx/graphics/codec/PNGEncoder.html

    Remember to import something like this at the top
    import flash.utils.ByteArray;
    import mx.graphics.codec.PNGEncoder;

    then add something like this at the end of the chroma loop
    var encoder:PNGEncoder = new PNGEncoder();
    var some_bytearr:ByteArray = encoder.encode(after_bitmap.bitmapData);

    best of luck with your art project,

    Zap

    Zapper - June 15th, 2009 at 1:26 pm
  9. Hello,
    would it be possible to overlay a transparent flash video stream with alpha/chroma information (prerecorded, stream from the server) onto the picture from the local webcam, record this and save it on the server merged to one video file?
    I have the feeling you could really have some good ideas. Maybe you could contact me on my email, I need this for a research project. I would really appreciate your help!

    G - September 15th, 2009 at 3:26 pm
  10. Nice work Adobe flash and AS3 love it man its so powerful, just getting into it now as it happens. Flash is the future lol. I am most definitely not a bot, but know how annoying they are.

    spence - March 10th, 2010 at 8:30 pm
  11. oh by the way livecams the first post – most definitely a bot, you are back linking to a pr0n site there mate.

    spence - March 10th, 2010 at 8:32 pm
  12. Very well written post. If you need to listen to BBC Radio on the iPhone – I strongly recommend BBC Radio iPhone Streams – it is easily the most convenient way to listen to BBC Radio on the iPhone, iPad or iPod Touch and it’s free at BBCStreams.com.

    Craig Boyd - April 2nd, 2010 at 11:56 am

Leave a Reply