Study on Somatosensory interaction airkinect-Case 2

Source: Internet
Author: User

Directory:

Research on Somatosensory interaction and Kinect-Basic

Study on Somatosensory interaction airkinect-Case study 1

Study on Somatosensory interaction airkinect-Case 2

 

 

We have completed the connection between Kinect and flash through airkinect. here is an example of introducing a magic hat. When a person enters the Kinect camera, she uploads a magic hat on the screen.

 

When the program is triggered, add three event handlers to the airkinect object:
Cameraimageevent. rgb_image_update-events generated each time an image is updated
Userevent. users_with_skeleton_added-a new skeleton event occurs.
Userevent. users_with_skeleton_added-enable the Kinect event on the skeleton

 

if (Kinect.isSupported()) {  // <----- get Kinect instance  _device = Kinect.getDevice();    // <----- add listener for Kinect  _device.addEventListener(CameraImageEvent.RGB_IMAGE_UPDATE, rgbImageUpdateHandler, false, 0, true);  _device.addEventListener(UserEvent.USERS_WITH_SKELETON_ADDED, skeletonsAddedHandler, false, 0, true);  _device.addEventListener(UserEvent.USERS_WITH_SKELETON_REMOVED, skeletonsRemovedHandler, false, 0, true);    ...    // <----- start the Kinect  _device.start(settings);}

2. When a new skeleton is found, we create a hat movieclip to produce the magic effect:

 

The magic effect of the hat (_ hat1) is made by the flash ide time frame.

...[Embed(source="assets/hat1.swf")]private var _Hat1:Class;...private function skeletonsAddedHandler(event:UserEvent):void{  for each(var addedUser:User in event.users){    var sprite:Sprite = new Sprite();    var head:SkeletonJoint = addedUser.getJointByName("head");    var headRGB:Point = head.position.rgb;    sprite.name = addedUser.trackingID.toString();    sprite.x = headRGB.x;    sprite.y = headRGB.y;        // <----- add the MovieClip to stage    sprite.addChild(new _Hat1() as MovieClip);    _sprites.push(sprite);    this.addChild(sprite);  }}

If the skeleton is disconnected from the Kinect, Division the hats corresponding to the skeleton:

private function skeletonsRemovedHandler(event:UserEvent):void{  for each(var removedUser:User in event.users){    for(var i:int=0; i<_sprites.length; i++){      var id:String = removedUser.trackingID.toString();      if(_sprites[i].name==id){        this.removeChild(_sprites[i]);        _sprites.splice(i, 1);      }    }  }}
During each update of the image, the head and neck locations of each skeleton are tracked, and the size of the hats is determined based on the distance between the two, and use tweenlite to move the hat to the head:

private function rgbImageUpdateHandler(event:CameraImageEvent):void{  // <----- get Kinect RGB Camera image to display  _bitmapData.draw(event.imageData);    for each(var user:User in _device.users) {    if (user.hasSkeleton) {      var head:SkeletonJoint = user.getJointByName("head");      var neck:SkeletonJoint = user.getJointByName("neck");      var headRGB:Point = head.position.rgb;      var neckRGB:Point = neck.position.rgb;      var diff:Number = Math.abs(neckRGB.y - headRGB.y);      var diffBase:Number = 50;      var scale:Number = diff/diffBase;      var id:String = user.trackingID.toString();            // <----- find the MovieClip      for(var i:int=0; i<_sprites.length; i++){        if(_sprites[i].name==id){          // <----- change the MovieClip position          TweenLite.to(_sprites[i], 0.1, {x:headRGB.x, y:headRGB.y, scaleX:scale, scaleY:scale});          break;        }      }    }  }}

You can refer to the [lower limit] example of lower limit.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.