Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- // Send the request for webcam to start dumping frames.
- webcam_frame.start();
- // Disable looping in draw.
- noLoop();
- }
- // Dumps the webcam frames.
- void draw() {
- // Store the current frame.
- opencv.loadImage(webcam_frame);
- // Get the next frame.
- webcam_frame.read();
- // 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);
- image(opencv.getSnapshot(), capture_x, 0);
- }
- // 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();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement