29
M1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010 SCM-CityU 1

SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

  • View
    217

  • Download
    1

Embed Size (px)

Citation preview

Page 1: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

SM1205 Interactivity

Topic 10: Motion Tracking Part II

Spring 2010 SCM-CityU 1

Page 2: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Motion Tracking Library

• In cityu.scm package (developed by Hongbo Fu)

– Webcam class • An easy-to-use wrapper for webcam access

Spring 2010 SCM-CityU 2

import cityu.scm.Webcam; // import Webcam class

// create a webcam with size 400 x 300var webcam:Webcam = new Webcam(400, 300);

// webcam will dispatch READY event when the webcam is ready to usewebcam.addEventListener(Webcam.READY, onCameraReady);

function onCameraReady(e:Event): void {addChild(webcam);

}

import cityu.scm.Webcam; // import Webcam class

// create a webcam with size 400 x 300var webcam:Webcam = new Webcam(400, 300);

// webcam will dispatch READY event when the webcam is ready to usewebcam.addEventListener(Webcam.READY, onCameraReady);

function onCameraReady(e:Event): void {addChild(webcam);

}

Page 3: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Motion Tracking Library

• In cityu.scm package (developed by Hongbo Fu)

– MotionTracker class

Spring 2010 SCM-CityU 3

var tracker:MotionTracker=new MotionTracker(webcam);var tracker:MotionTracker=new MotionTracker(webcam);

Page 4: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

MotionTracker Class• Properties– trackX: Number; trackY: Number• Center of tracked region • With respect to top-left corner of webcam (instead of stage)

• Methods– hitTestObject

– hitTestPoint – hideTrackedArea– hideTrackedCenter

Spring 2010 SCM-CityU 4

Spring 2010

4

(0, 0)

(trackX, trackY)

Page 5: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Demos

Spring 2010 SCM-CityU 5

Page 6: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Clipping Regions• By default, motion tracking is done over the entire

video domain – Check MotionTracker-Skeleton.fla

Spring 2010 SCM-CityU 6

Page 7: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Clipping Regions • What if motion only within specific regions (called

clipping regions) are needed?– Motion outside those clipping regions will be ignored

• Demo

Spring 2010 SCM-CityU 7

clipping regions

Page 8: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Clipping Regions • Specify a clipping region when creating a motion tracker

– cl, ct, cr, cb are with respect to top-left cornerof webcam

– trackX, trackY are also withrespect to top-left cornerof webcam

– You can have only ONE clipping region for one tracker

Spring 2010 SCM-CityU 8

tracker = new MotionTracker(webcam,

cl, ct, cr, cb);tracker = new MotionTracker(webcam,

cl, ct, cr, cb);

cl

cr

ct cb

Clipping Region

Page 9: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Multiple Clipping Regions • To have multiple clipping regions, you can create

multiple trackers – All trackers share the same Webcam instance – Each tracker has its own associated clipping region

Spring 2010 SCM-CityU 9

// initialize 1st motion tracker tracker = new MotionTracker(webcam, 0, 0, 200, 200);

// initialize 2nd motion tracker tracker2 = new MotionTracker(webcam, 300, 300, 500, 500);

// initialize 1st motion tracker tracker = new MotionTracker(webcam, 0, 0, 200, 200);

// initialize 2nd motion tracker tracker2 = new MotionTracker(webcam, 300, 300, 500, 500);

Page 10: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Class Exercise • Extend the previous example to have two clipping regions

as follows– Hint: create two trackers with their own clipping regions– How trackers work at the overlapped areas of clipping regions?

Spring 2010 SCM-CityU 10

Page 11: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example: Ping-Pong Game

Spring 2010 SCM-CityU 11

box

barL

ball

barR

box2

Page 12: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example: Ping-Pong Game• Use tracker and tracker2 to control barL and barR,

respectively

Spring 2010 SCM-CityU 12

Page 13: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Class Exercise

• Make ball bounce against stage borders – Change ball’s x and y properties continuously in onTimer

event listener – Check if ball hits

stage borders

Spring 2010 SCM-CityU 13

Page 14: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Hit Test between Ball and Bars

• Let’s just use hitTestObject method

Spring 2010 SCM-CityU 14

if (ball.hitTestObject(barR)) { trace("barR got hit");

}

if (ball.hitTestObject(barL)) { trace("barL got hit");

}

if (ball.hitTestObject(barR)) { trace("barR got hit");

}

if (ball.hitTestObject(barL)) { trace("barL got hit");

}

Page 15: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Hit Test between Ball and Bars

• Collision response

Spring 2010 SCM-CityU 15

Case 1: Ball is on left sideof barR

Case 2: Ball is on right sideof barR

Page 16: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Hit Test between Ball and Bars• But how to determine which case to handle?• Solution: use signs of ball’s speedX– speedX > 0 Case 1

• Response: put ball exactly at the left sideof barR

– speedX < 0 Case 2• Response: put ball

exactly at the right sideof barR

Spring 2010 SCM-CityU 16

Page 17: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Class Exercise

• Add sound effects when ball hits stage borders/bars – You can use Flash built-in sounds

• Hints– Export sounds for

ActionScript

Spring 2010 SCM-CityU 17

var ws:WoodSound = new WoodSound(); ws.play();var ws:WoodSound = new WoodSound(); ws.play();

Page 18: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Moving Speed • Use MotionTracker’s speedX and speedY to get the

moving speed of tracked object

• speedX (in pixels)– Positive value if object moves along positive x-axis – Negative value if objects moves along negative x-axis

• speedY (in pixels)– Positive value if object moves along positive y-axis – Negative value if objects moves along negative y-axis

Spring 2010 SCM-CityU 18

trace(tracker.speedX, tracker.speedY);trace(tracker.speedX, tracker.speedY);

Page 19: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example • Transfer moving speed of tracked object to ball– E.g., hand

• Demo

Spring 2010 SCM-CityU 19

Page 20: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example • Let’s modify the previous ping-pong example– Keep one tracker only, without any clipping region– No vertical bars– Add friction

Spring 2010 SCM-CityU 20

Page 21: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example • Change ball’s speeds only if there is some intersection

between ball and moving object

Spring 2010 SCM-CityU 21

if (tracker.isTracked() && tracker.hitTestPoint(ball.x, ball.y, true)) {

speedX += tracker.speedX; speedY += tracker.speedY;

}

if (tracker.isTracked() && tracker.hitTestPoint(ball.x, ball.y, true)) {

speedX += tracker.speedX; speedY += tracker.speedY;

}

Page 22: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Example

• Interact with more balls (demo)

Spring 2010 SCM-CityU 22

Page 23: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Assignment 3

• Topic: Webcam Interaction with Motion

• Requirements– Use motion tracker – Interact with motion – Have music/sound elements – Meaningful system – Documentation (in Word format)• Title, motivation, how-to-use, screenshots, references

Spring 2010 SCM-CityU 23

Page 24: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Assignment 3

• Submission – Via ACS • Max total file size: 50M• .fla, .swf, .doc (documentation) files and other files

– Deadline: 23:59:59, 12 May (Wed), 2010• No late submission is allowed

• In-class presentation, 12 May, 2010– Each student has roughly 5 minutes for presentation

Spring 2010 SCM-CityU 24

Page 25: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Assignment 3

• Assessment – Based on • Implementation difficulty + UI design + creativity (80%)• Presentation performance (10%)• Documentation (10%)

– Note: if you use any technique which has not been taught in this course, you must state its source or reference in the documentation clearly • Otherwise, some marks will be deducted

Spring 2010 SCM-CityU 25

Page 26: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Summary of MotionTracker

• Make sure your Flash application is under the same folder as the tracking library

Spring 2010 SCM-CityU 26

Page 27: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Summary of MotionTracker

• Without clipping region

• With clipping region

– cl, ct, cr, cb are with respect to top-left cornerof webcam

Spring 2010 SCM-CityU 27

tracker = new MotionTracker(webcam);tracker = new MotionTracker(webcam);

tracker = new MotionTracker(webcam,

cl, ct, cr, cb);tracker = new MotionTracker(webcam,

cl, ct, cr, cb);

Page 28: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Summary of MotionTracker

• Properties – trackX, trackY: center of tracked region • With respect to top-left corner of webcam

– speedX, speedY• Moving speed of

tracked object

Spring 2010 SCM-CityU

2828

Spring 2010

28

(0, 0)

(trackX, trackY)

Page 29: SM1205 Interactivity Topic 10: Motion Tracking Part II Spring 2010SCM-CityU1

Summary of MotionTracker

• Methods– hitTestObject• To test if bounding boxes of display object and tracked

region intersect with each other

– hitTestPoint• To test if a given point is within the tracked region

– isTracked• To check if any moving object is tracked

– hideTrackedArea– hideTrackedCenter

Spring 2010 SCM-CityU 29