A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [webcam] Replace mouse with lightsource

  1. #1
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770

    [webcam] Replace mouse with lightsource

    While experimenting with motion detection late at night with the lights out and using an OLD webcam, I found I could track a light source pretty easily in a dark room. I was wondering if this works with better webcams, or if they see too much light for it to work? You may have to adjust the brightness and/or contrast of your webcam to get it to work well (my webcam is so old it doesn't have those adjustment options). Does anyone know if there are examples of this technique already in use.
    PHP Code:
    my_cam Camera.get();
    webcam_video.attachVideo(my_cam); // webcam_video is a video object

    now = new BitmapData(webcam_video._widthwebcam_video._height);

    createEmptyMovieClip('holder'getNextHighestDepth());
    holder.attachBitmap(nowholder.getNextHighestDepth());
    with(holder){
      
    _x=webcam_video._width;
      
    _y=webcam_video._height+10;
      
    _xscale=-100;
    }

    createEmptyMovieClip('crossHairs'getNextHighestDepth());
    with(crossHairs){
      
    lineStyle(1,0xFFFFFF);
      
    moveTo(0,-6);
      
    lineTo(0,6);
      
    moveTo(-6,0);
      
    lineTo(6,0);
      
    moveTo(0,-4);
      
    lineTo(4,0);
      
    lineTo(0,4);
      
    lineTo(-4,0);
      
    lineTo(0,-4);
    }

    crossHairs.onEnterFrame=function(){
      
    now.draw(webcam_video);
      
    now.threshold(nownow.rectangle, new flashGeomPoint(00), '<='0xFF6666660xFF0000000xFF0000FFfalse);
      
    lightBox now.getColorBoundsRect(0x00FF00000x00FFFFFFfalse);
      if(
    lightBox.width 0){
        
    this._x Stage.width - (lightBox.webcam_video._width) * Stage.width;
        
    this._y = (lightBox.webcam_video._height) * Stage.height;
      }
    }; 
    It seems to work with any light source that is not bright enough to light your hand. I've used my cellphone screen, a penlight, even my mouse's laser, though you have to make sure the mouse's laser is pointed at the webcam, which is a bit akward, but works great for shooting. Oh yeah, make sure your computer screen doesn't illuminate anything enough for the webcam to see it!
    (Sample attached)
    Attached Files Attached Files

  2. #2
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Be nice if you could specify a colour range so you could use it during the day, and have say bright green tags instead of lightsources.

    I'll try and have a play with this when I get home. My webcam's pretty new.

  3. #3
    Senior Member
    Join Date
    Nov 2003
    Location
    Las Vegas
    Posts
    770
    You can definitely play with different color thresholds, a combination might give you what you want.

    However, remember how colors are handled by the threshold function. It's not looking for a particular color channel value, but an overall value of the combined color channels. You can perform two thresholds in order to isolate a single color channel (for green, remove 0x0000ff and below, then copy 0x00ff00 and below or remove above 0x00ff00), and then another to remove anything brighter than your target range in the same color channel, then a final check for anything brighter than your minimum range should give you the color you are looking for.

    The issue during the day is that reflected light contains almost every color there is, so in my first experiments, there were light artifacts everywhere after performing the thresholds. In the dark it was much easier since threshold is essentially a brightness check.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center