Designing Applications that See Lecture 6: Processing Dan - - PowerPoint PPT Presentation

designing applications that see lecture 6 processing
SMART_READER_LITE
LIVE PREVIEW

Designing Applications that See Lecture 6: Processing Dan - - PowerPoint PPT Presentation

stanford hci group / cs377s Designing Applications that See Lecture 6: Processing Dan Maynes-Aminzade 30 January 2007 Designing Applications that See http://cs377s.stanford.edu Reminders Assignment #2 due Thursday in lecture Assignment


slide-1
SLIDE 1

stanford hci group / cs377s

Designing Applications that See Lecture 6: Processing

Designing Applications that See http://cs377s.stanford.edu

Dan Maynes-Aminzade 30 January 2007

slide-2
SLIDE 2

Reminders

Assignment #2 due Thursday in lecture Assignment #3 will be released next week Some minor changes to schedule – check the course calendar for details the course calendar for details

30 January 2007 2 Lecture 6: Processing

slide-3
SLIDE 3

Learn More Tools for Your Project

CS247L has open lab sessions about many useful tools for physical prototyping Wednesdays 7-9PM in Gates 104 Upcoming Lab Sessions: Upcoming Lab Sessions:

February 7: Mobile Interaction February 14: Soldering and Electronics (meet at CCRMA instead of Gates 104) February 21: Physical Computing With d.Tools

More info: http://cs247.stanford.edu/lab.html

30 January 2007 3 Lecture 6: Processing

slide-4
SLIDE 4

Today’s Goals

Learn the basics of the Processing environment Understand how to produce and publish Processing applets Processing applets Learn how to capture and process live video in the Processing framework Experiment with color and motion tracking

30 January 2007 4 Lecture 6: Processing

slide-5
SLIDE 5

Outline

Processing introduction Work through some Processing examples JMyron introduction Look at basic video processing examples Look at basic video processing examples Build some motion and color tracking examples Add interactivity to our examples

30 January 2007 5 Lecture 6: Processing

slide-6
SLIDE 6

What is Processing?

An easy-to-use Java compiler A development environment Focused on interactive graphics, sound, and animation animation Produces both locally-run programs and web-embeddable applets Can be used together with “real” Java

30 January 2007 6 Lecture 6: Processing

slide-7
SLIDE 7

Processing Perspective

A development tool for exploring multimedia programming An educational tool for learning programming fundamentals programming fundamentals An ideation tool or “electronic sketchbook” for trying out ideas Targeted for designers, artists, beginning programmers

30 January 2007 7 Lecture 6: Processing

slide-8
SLIDE 8

Nice Things about Processing

Takes care of a lot of the annoying setup logistics for doing video and graphics in Java Easy to create interesting dynamic visuals programmatically programmatically Allows quick experimentation Strong focus on graphics, sound, and simple interactivity (unlike traditional Java programming with a text console)

30 January 2007 8 Lecture 6: Processing

slide-9
SLIDE 9

Getting Help on Processing

Look at the built-in examples More examples: Function reference:

http://www.processing.org/learning/

Function reference: Discussion forums: User-contributed code samples:

30 January 2007 9 Lecture 6: Processing

http://www.processing.org/reference/ http://www.processing.org/discourse/ http://www.processinghacks.com/

slide-10
SLIDE 10

Available Libraries

Built-In

Video Networking Serial Communication Importing XML, SVG Importing XML, SVG Exporting PDF, DXF, etc.

External Contributions

Sound: Ess, Sonia Computer Vision: JMyron, ReacTIVision, BlobDetection Interface: proCONTROLL, Interfascia Many others

30 January 2007 10 Lecture 6: Processing

slide-11
SLIDE 11

A Quick Tour

30 January 2007 11 Lecture 6: Processing

slide-12
SLIDE 12

Toolbar Buttons

Run Stop New Open Save Export

30 January 2007 12 Lecture 6: Processing

slide-13
SLIDE 13

Sketches

30 January 2007 13 Lecture 6: Processing

slide-14
SLIDE 14

Tabs

30 January 2007 14 Lecture 6: Processing

slide-15
SLIDE 15

Coordinates

30 January 2007 15 Lecture 6: Processing

slide-16
SLIDE 16

Programming Modes

Basic

For drawing static images and learning programming fundamentals

Continuous

Provides a setup() and draw() structures and allows writing custom functions and classes and using keyboard and mouse events

Java

Most flexible mode, giving access to the full Java programming language

30 January 2007 16 Lecture 6: Processing

slide-17
SLIDE 17

Basic Mode

size(200, 200); background(255); noStroke(); fill(255, 204, 0); fill(255, 204, 0); rect(30, 20, 50, 50);

30 January 2007 17 Lecture 6: Processing

slide-18
SLIDE 18

Continuous Mode

void setup() { size(200, 200); noStroke(); background(255); fill(0, 102, 153, 204); smooth(); noLoop(); noLoop(); } void draw() { circles(40, 80); circles(90, 70); } void circles(int x, int y) { ellipse(x, y, 50, 50); ellipse(x+20, y+20, 60, 60); }

30 January 2007 18 Lecture 6: Processing

slide-19
SLIDE 19

Continuous Mode

void setup() { size(200, 200); rectMode(CENTER); noStroke(); fill(0, 102, 153, 204); } void draw() { background(255); rect(width-mouseX, height-mouseY, 50, 50); rect(mouseX, mouseY, 50, 50); }

30 January 2007 19 Lecture 6: Processing

slide-20
SLIDE 20

Java Mode

public class MyDemo extends PApplet { void setup() { size(200, 200); rectMode(CENTER); noStroke(); fill(0, 102, 153, 204); fill(0, 102, 153, 204); } void draw() { background(255); rect(width-mouseX, height-mouseY, 50, 50); rect(mouseX, mouseY, 50, 50); } }

30 January 2007 20 Lecture 6: Processing

slide-21
SLIDE 21

Some Basic Setup Statements

// specifies window size size(200, 200); // specifies background color background(102); // disables filling in shapes noFill(); // disables drawing lines noStroke(); // set fill color fill(255,100,100); // set stroke color stroke(100,255,100);

30 January 2007 21 Lecture 6: Processing

slide-22
SLIDE 22

Some Basic Drawing Functions

// draw a point in the middle // width and height store the // window size point(width/2, height/2); // draw a 20x20 rectangle rect(10,10,20,20); rect(10,10,20,20); // draw an ellipse ellipse(50,50,30,30); // draw an irregular shape beginShape(); vertex(60, 40); vertex(160, 10); vertex(170, 150); vertex(60, 150); endShape();

30 January 2007 22 Lecture 6: Processing

slide-23
SLIDE 23

Setup and Draw

void setup() { size(200, 200); stroke(255); frameRate(30); } float y = 100; void draw() { background(0); y = (y+1) % height; line(0, y, width, y); }

30 January 2007 23 Lecture 6: Processing

slide-24
SLIDE 24

noLoop

void setup() { size(200, 200); stroke(255); frameRate(30); noLoop(); } float y = 100; void draw() { background(0); y = (y+1) % height; line(0, y, width, y); }

30 January 2007 24 Lecture 6: Processing

slide-25
SLIDE 25

Loop

void mousePressed() { loop(); }

30 January 2007 25 Lecture 6: Processing

slide-26
SLIDE 26

Redraw

void mousePressed() { redraw(); }

30 January 2007 26 Lecture 6: Processing

slide-27
SLIDE 27

Event Handlers

mouseDragged() mouseMoved() mousePressed() mouseReleased() mouseReleased() ... keyReleased() keyPressed()

30 January 2007 27 Lecture 6: Processing

slide-28
SLIDE 28

Mouse Drawing

void setup() { size(200, 200); background(50); } void draw() { void draw() { stroke(255); if(mousePressed) { line(mouseX, mouseY, pmouseX, pmouseY); } }

30 January 2007 28 Lecture 6: Processing

slide-29
SLIDE 29

Functions

void draw_target(int xloc, int yloc, int size, int num) { float grayvalues = 255/num; float steps = size/num; for(int i=0; i<num; i++) { for(int i=0; i<num; i++) { fill(i*grayvalues); ellipse(xloc, yloc, size-i*steps, size-i*steps); } }

30 January 2007 29 Lecture 6: Processing

slide-30
SLIDE 30

Other Basic Concepts

These behave how you would expect (exactly as they do in Java)

Data types (int, float, boolean) Arrays Arrays Loops Conditionals and Logical Operators Strings Variables and Scoping

30 January 2007 30 Lecture 6: Processing

slide-31
SLIDE 31

Images

size(200, 200); PImage img; img = loadImage("tennis.jpg"); image(img, 0, 0); image(img, 0, 0); image(img, 0, 0, img.width/10, img.height/10);

30 January 2007 31 Lecture 6: Processing

slide-32
SLIDE 32

Color Spaces

noStroke(); colorMode(RGB, 100); for(int i=0; i<100; i++) { for(int j=0; j<100; j++) { stroke(i, j, 0); point(i, j); } } colorMode(HSB, 100); for(int i=0; i<100; i++) { for(int j=0; j<100; j++) { stroke(i, j, 100); point(i, j); } }

30 January 2007 32 Lecture 6: Processing

slide-33
SLIDE 33

Reading Pixel Data

PImage img; size(300,300); noStroke(); img = loadImage("monzy.jpg"); noLoop(); for (int x=0; x<img.width; x+=5) { for (int x=0; x<img.width; x+=5) { for (int y=0; y<img.height; y+=5) { int pixelcolor = img.pixels[x+y*img.width]; fill(pixelcolor); ellipse(x,y,4,4); } }

30 January 2007 33 Lecture 6: Processing

slide-34
SLIDE 34

Loading Video

import processing.video.*; Movie myMovie; void setup() { size(320, 240); myMovie = new Movie(this, "ball.mov"); myMovie.loop(); myMovie.loop(); } void draw(){ // tint(255, 20); image(myMovie, mouseX, mouseY); } void movieEvent(Movie m) { m.read(); }

30 January 2007 34 Lecture 6: Processing

slide-35
SLIDE 35

Capturing Video

import processing.video.*; Capture myCapture; void setup() { size(160, 120); String s = "Logitech QuickCam Pro 4000-WDM"; myCapture = new Capture(this, s, width, myCapture = new Capture(this, s, width, height, 30); } void captureEvent(Capture myCapture) { myCapture.read(); } void draw() { image(myCapture, 0, 0); }

30 January 2007 35 Lecture 6: Processing

slide-36
SLIDE 36

Process Video (Simple)

void draw() { for (int i=0; i<width; i+=5) { for (int j=0; j<height; j+=5) { int pixel = myCapture.pixels[i+width*j]; myCapture.pixels[i+width*j]; fill(pixel); ellipse(i,j,5,5); } } }

30 January 2007 36 Lecture 6: Processing

slide-37
SLIDE 37

Process Video (More Complex)

  • Declare some new global variables:

int numPixels; int blockSize = 10; color myMovieColors[];

  • Initialize variables in setup():

noStroke(); background(0); numPixels = width / blockSize; myMovieColors = new color[numPixels * numPixels]; myMovieColors = new color[numPixels * numPixels];

  • Add to captureEvent:

for(int j=0; j<numPixels; j++) { for(int i=0; i<numPixels; i++) { myMovieColors[j*numPixels + i] = myCapture.get(i*blockSize, j*blockSize); } }

  • Replace draw() event:

for(int j=0; j<numPixels; j++) { for(int i=0; i<numPixels; i++) { fill(myMovieColors[j*numPixels + i]); rect(i*blockSize, j*blockSize, blockSize-1, blockSize-1); } }

30 January 2007 37 Lecture 6: Processing

slide-38
SLIDE 38

Other Examples

30 January 2007 38 Lecture 6: Processing

slide-39
SLIDE 39

Basic Color Tracking

for ( int x=0;x<video.width;x++) { for ( int y=0;y<video.height;y++) { int loc = x + y*video.width; color currentColor = video.pixels[loc]; float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor); float r2 = red(trackColor); float r2 = red(trackColor); float g2 = green(trackColor); float b2 = blue(trackColor); float d = dist(r1,g1,b1,r2,g2,b2); if (d < closestDiff) { closestDiff = d; closestX = x; closestY = y; } } }

30 January 2007 39 Lecture 6: Processing

slide-40
SLIDE 40

Better Tracking with JMyron

30 January 2007 40 Lecture 6: Processing

slide-41
SLIDE 41

JMyron Setup

import JMyron.*; JMyron m; void setup(){ size(320,240); size(320,240); m = new JMyron(); m.start(width,height); }

30 January 2007 41 Lecture 6: Processing

slide-42
SLIDE 42

JMyron Drawing

void draw(){ m.update();//update the camera view int[] img = m.image(); loadPixels(); loadPixels(); for(int i=0;i<width*height;i++) { pixels[i] = img[i]; } updatePixels(); }

30 January 2007 42 Lecture 6: Processing

slide-43
SLIDE 43

JMyron Cleanup

public void stop(){ m.stop(); super.stop(); }

30 January 2007 43 Lecture 6: Processing

slide-44
SLIDE 44

JMyron Color Tracking

Setup the color tracking m.trackColor(255,255,255,200); m.minDensity(100); Draw boxes around the detected regions Draw boxes around the detected regions int[][] b = m.globBoxes(); for(int i=0;i<b.length;i++) { rect(b[i][0],b[i][1], b[i][2], b[i][3]); }

30 January 2007 44 Lecture 6: Processing

slide-45
SLIDE 45

Drawing “Globs”

int list[][][] = m.globPixels(); for(int i=0; i<list.length;i++) { int[][] pixellist = list[i]; if(pixellist!=null) { beginShape(POINTS); beginShape(POINTS); for(int j=0;j<pixellist.length;j++) { vertex(pixellist[j][0], pixellist[j][1]); } endShape(); } }

30 January 2007 45 Lecture 6: Processing

slide-46
SLIDE 46

Other Useful JMyron Functions

Get the average pixel value across a region:

int c = m.average(mouseX-20, mouseY-20, mouseX+20, mouseY+20);

Get the center points of the globs: Get the center points of the globs:

int[][] gcs = m.globCenters();

Get the bounding quads of the globs:

int[][] bqs = m.globQuads(20,200);

30 January 2007 46 Lecture 6: Processing

slide-47
SLIDE 47

Background Subtraction

Set rate of adaptivity: m.adaptivity(10); Take a snapshot of the background for differencing: differencing: m.adapt(); Get the difference image: int[] img = m.differenceImage();

30 January 2007 47 Lecture 6: Processing

slide-48
SLIDE 48

Controlling a Cursor

30 January 2007 48 Lecture 6: Processing

slide-49
SLIDE 49

Exporting an Applet

30 January 2007 49 Lecture 6: Processing

slide-50
SLIDE 50

Signing an Applet

  • Generate a keystore:

$ keytool -genkey -alias signFiles

  • keystore mystore
  • keypass thepassword
  • dname "CN=projname, OU=name,

O=company, L=location, S=state, C=country" -storepass thepassword C=country" -storepass thepassword

  • Export a certificate file (optional):

$ keytool -export -keystore mystore

  • storepass thepassword

–alias signFiles

  • file mycertificate.cer
  • Sign your jar file:

$ jarsigner -keystore mystore

  • storepass thepassword -keypass thepassword
  • signedjar output.jar input.jar signFiles

30 January 2007 50 Lecture 6: Processing

(courtesy of Kevin Cox)

slide-51
SLIDE 51

Summary

Processing provides a fun, easy, visual way to program interactive graphics Built-in computer vision capabilities are somewhat limited, but you can still do many somewhat limited, but you can still do many interesting things (and you could always try doing your own pixel wrangling) Check out the examples and take a look at the various external libraries

30 January 2007 51 Lecture 6: Processing