Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Step 1. Import the video library
- import processing.video.*;
- // Step 2. Declare a Capture object
- Capture cam;
- //Step 2b. Declare a PImage to hold the mirrored web cam image
- PImage img;
- void setup() {
- size(640, 480);
- // Step 3. Initialize Capture object via Constructor
- cam = new Capture(this, width, height);
- cam.start();
- // Step 3b. Initialize 'mirror' image
- img = createImage(width, height, RGB);
- }
- // An event for when a new frame is available
- void captureEvent(Capture cam) {
- // Step 4. Read the image from the camera.
- cam.read();
- }
- void draw() {
- // Step 4b. flip the image so it mirrors the users
- flipImage();
- // Step 5. Draw the (flipped) image.
- image(img,0,0);
- }
- void flipImage() {
- img = createImage(width, height, RGB);
- img.loadPixels();
- cam.loadPixels();
- for (int y = 0; y<height; y++) {
- for (int x = 0; x<width; x++) {
- img.pixels[y*width+x] = cam.pixels[y*width+(width-1-x)];
- }
- }
- img.updatePixels();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement