Skip to content

Instantly share code, notes, and snippets.

@hak8or
Created April 26, 2015 22:54
Show Gist options
  • Save hak8or/0309fa8932d72a5799b7 to your computer and use it in GitHub Desktop.
Save hak8or/0309fa8932d72a5799b7 to your computer and use it in GitHub Desktop.
Blue color channel
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
Capture webcam_frame;
OpenCV opencv;
// Capture resolution of webcam.
int capture_x = 960;
int capture_y = 720;
void setup() {
// Dump list of webcams capabilities.
get_webcam_capabilities();
// Make viewport size.
size(capture_x * 2, capture_y);
// Resolution + fps requested from webcam.
webcam_frame = new Capture(this, capture_x, capture_y, 15);
// Opencv wrapper.
opencv = new OpenCV(this, capture_x, capture_y);
opencv.useColor(HSB);
// Send the request for webcam to start dumping frames.
webcam_frame.start();
// Disable looping in draw.
noLoop();
}
// Dumps the webcam frames.
void draw() {
// Get the next frame.
webcam_frame.read();
// Store the current frame.
opencv.loadImage(webcam_frame);
// Get only blue stuff;
opencv.getB();
// Do a diff between the old and new image frames.
// opencv.diff(webcam_frame);
// Display the video image on the processing window.
set(0, 0, webcam_frame);
// tint(0,0,255);
image(opencv.getSnapshot(), capture_x, 0);
// noTint();
}
// Unused since PImage doesn't seem to properly hold
// the old camera image.
PImage get_diff(PImage image_A, PImage image_B){
opencv.loadImage(image_A);
opencv.diff(image_B);
return opencv.getSnapshot();
}
// Dump list of webcams capabilities.
void get_webcam_capabilities(){
// Read all camera params.
String[] cameras = Capture.list();
// Dump all params to terminal.
println("Available cameras:");
for (int i = 0; i < cameras.length; i++)
println(cameras[i]);
}
// Called everytime a new camera frame is avalible.
void captureEvent(Capture webcam) {
println("Capture event fired");
// Redraw the GUI.
redraw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment