Skip to content

Instantly share code, notes, and snippets.

@hak8or
Created April 27, 2015 00:00
Show Gist options
  • Save hak8or/bf757a596f29cbb0dc15 to your computer and use it in GitHub Desktop.
Save hak8or/bf757a596f29cbb0dc15 to your computer and use it in GitHub Desktop.
Copy on right for blue channel mucking everything up.
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();
// Display the video image on the processing window.
set(0, 0, webcam_frame);
// Store the current frame.
opencv.loadImage(webcam_frame);
// Get only blue stuff;
opencv.getB();
// Save the b channel informaiton.
PImage b_channel = opencv.getSnapshot();
// Load that again but as input.
opencv.loadImage(b_channel);
// opencv.useGray();
// opencv.threshold(80);
// Do a diff between the old and new image frames.
// opencv.diff(webcam_frame);
image(b_channel, capture_x, 0);
}
// 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();
}
@hak8or
Copy link
Author

hak8or commented Apr 27, 2015

Line 52 being uncommented makes the value b_channel on line 58 gray, pah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment