WEEK 4 WORKSHOP

invert

Live Video Capture & Filters

1) Capture example from processing.org

import processing.video.*;

Capture cam;

void setup() {
  size(640, 480);

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    
    // The camera can be initialized directly using an 
    // element from the array returned by list():
    cam = new Capture(this, cameras[0]);
    cam.start();     
  }      
}

void draw() {
  if (cam.available() == true) {
    cam.read();
  }
  image(cam, 0, 0);
  // The following does the same, and is faster when just drawing the image
  // without any additional resizing, transformations, or tint.
  //set(0, 0, cam);
}

2) Filter example

PImage img;
img = loadImage("apples.jpg");
image(img, 0, 0);
filter(INVERT);

THRESHOLD
Converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. The parameter must be between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.

GRAY
Converts any colors in the image to grayscale equivalents. No parameter is used.

OPAQUE
Sets the alpha channel to entirely opaque. No parameter is used.

INVERT
Sets each pixel to its inverse value. No parameter is used.

POSTERIZE
Limits each channel of the image to the number of colors specified as the parameter. The parameter can be set to values between 2 and 255, but results are most noticeable in the lower ranges.

BLUR
Executes a Guassian blur with the level parameter specifying the extent of the blurring. If no parameter is used, the blur is equivalent to Guassian blur of radius 1. Larger values increase the blur.

ERODE
Reduces the light areas. No parameter is used.

DILATE
Increases the light areas. No parameter is used.

3) Tint() and noTint() example

PImage img;
img = loadImage("laDefense.jpg");
tint(0, 153, 204);  // Tint blue
image(img, 0, 0);
noTint();  // Disable tint
image(img, 50, 0);

 

faceDetection0Fin

Face Detection Library

1) Open Processing go to Sketch -> import library

2) Install openCV for Processing

3) Run the Face Detection sketch

 

//INSTALL openCV library from Sketch > Import Library > Add Library > Type 'opencv' in the search bar

//BELOW WE IMPORT LIBRARIES
import gab.opencv.*;
import processing.video.*;
import java.awt.*;

//WE CREATE TWO OBJECTS video OF TYPE Capture AND myopencv OF TYPE OPENCV
Capture video;
OpenCV myopencv;

void setup() {
  //SETTING UP REGULAR STUFF
  size(640, 480);
  //TELLING video AND myopencv ITS SIZE
  video = new Capture(this, 640/2, 480/2);
  myopencv = new OpenCV(this, 640/2, 480/2);
  //TELLING myopencv TO LOAD FRONT CAMERA (WEBCAM) SO IT CAN START DETECTING
  myopencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  //START THE CAMERA
  video.start();
}

void draw() {
  //MAKING THE CAMERA IMAGE BIGGER
  scale(2);
  //LOADING IMAGES FROM THE VIDEO CAPTURE
  myopencv.loadImage(video);
  //DISPLAYING THE VIDEO ON THE SCREEN
  image(video, 0, 0 );
  //COLOR AND STROKE SETTINGS FOR THE GREEN RECTANGLE
  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  //STORING THE FACES DETECTED SO THAT WE CAN USE THIS INFORMATION LATER
  Rectangle[] faces = myopencv.detect();
  //PRINTING IN THE CONSOLE NUMBER OF FACES DETECTED
  println("Number of Faces Detected:" + faces.length);

  //DRAWING RECTANGLES ON THE FACES SO THAT WE CAN SEE A VISUAL INDICATION THAT IT DETECTED
  for (int i = 0; i < faces.length; i++) {
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}

  //KEEPS CHECKING IF THE CAMERA IS ON, IF IT IS, IT KEEPS READING VIDEO DATA FROM IT
void captureEvent(Capture c) {
  c.read();
}

Resources:
https://processing.org/reference/libraries/video/Capture.html

https://www.processing.org/reference/filter_.html

https://processing.org/reference/tint_.html

https://www.processing.org/reference/noTint_.html

https://github.com/shiffman/Face-It

 

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s