User Tools

Site Tools


processing:video_capture

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
processing:video_capture [2013/04/12 03:13] mithatprocessing:video_capture [2013/04/12 18:46] mithat
Line 184: Line 184:
   filter(GRAY);  // Render image() in B&W.   filter(GRAY);  // Render image() in B&W.
 } }
 +</file>
 +
 +This version walks through each pixel in the reduced image and renders the value of that pixel as NxN blocks. (N is called OUTPUT_SCALE in the code below.)
 +
 +<file java capture_reduce_res-2.pde>
 +/** Reduce resolution of captured image. Display results in blocks.
 + * @author Mithat Konar
 + */
 +
 +import processing.video.*;
 +
 +// === Program constants === //
 +// Rendering parameters:
 +// number of cells the rendered image should be in each direction:
 +final int REDUCED_WIDTH = 32;
 +final int REDUCED_HEIGHT = 24;
 +
 +// Canvas parameters:
 +// number of times you want REDUCED image blown up:
 +final int OUTPUT_SCALE = 10;
 +// frame rate of rendered output:
 +final int CANVAS_FPS = 8;
 +
 +// Video capture parameters
 +// (adjust as neeeded for your platform's available capture options):
 +final int CAM_WIDTH = 320;
 +final int CAM_HEIGHT = 240;
 +final int CAM_FPS = 15;
 +
 +// === Global variables ===//
 +Capture cam;  // The video capture device.
 +PImage img;   // Buffer image.
 +
 +// === GO! === //
 +void setup() {
 +  frameRate(CANVAS_FPS);
 +  size(REDUCED_WIDTH*OUTPUT_SCALE, REDUCED_HEIGHT*OUTPUT_SCALE);
 +
 +  if (Capture.list().length == 0) {
 +    println("There are no cameras available for capture.");
 +    exit();
 +  }
 +
 +  // Instantiate a buffer image used for subsampling, etc.
 +  img = createImage(REDUCED_WIDTH, REDUCED_HEIGHT, RGB);
 +
 +  // Instantiate a new Capture object, requesting the specs:
 +  cam = new Capture(this, CAM_WIDTH, CAM_HEIGHT, CAM_FPS);
 +  cam.start();  // In Processing 2.0, you need to start the capture device
 +}
 +
 +void draw() {
 +  // Grab a frame
 +  if (cam.available() == true) {
 +    cam.read();
 +  }
 +
 +  // Using a buffer because
 +  // cam.resize(REDUCED_WIDTH, REDUCED_HEIGHT);
 +  // doesn't work :-(
 +  img.copy(cam, 0, 0, CAM_WIDTH, CAM_HEIGHT, 0, 0, REDUCED_WIDTH, REDUCED_HEIGHT);
 +  img.loadPixels();
 +
 +  // For each column in img:
 +  for (int col = 0; col < REDUCED_WIDTH; col++) {
 +    // For each row in img:
 +    for (int row = 0; row < REDUCED_HEIGHT; row++) {
 +      // Get color from pixel at col, row
 +      color c = img.pixels[col + row*img.width];
 +      fill(c);
 +      stroke(c);
 +      rect(col*OUTPUT_SCALE, row*OUTPUT_SCALE, OUTPUT_SCALE, OUTPUT_SCALE);
 +    }
 +  }
 +}
 +
 </file> </file>
  
processing/video_capture.txt · Last modified: 2013/08/23 04:10 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki