Updates for video capture examples, new keywords.txt

This commit is contained in:
Casey Reas
2013-03-05 12:53:13 -08:00
parent 6b5eb6ae55
commit 1ee4d922e3
16 changed files with 122 additions and 58 deletions

View File

@@ -29,11 +29,15 @@ float fontSize = 1.5;
void setup() {
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
// Start capturing the images from the camera
video.start();
int count = video.width * video.height;
println(count);
//println(count);
font = loadFont("UniversLTStd-Light-48.vlw");

View File

@@ -15,9 +15,15 @@ Capture video;
void setup() {
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
video = new Capture(this, width, height);
// Start capturing the images from the camera
video.start();
numPixels = video.width * video.height;
// Create array to store the background image
backgroundPixels = new int[numPixels];
@@ -36,11 +42,11 @@ void draw() {
// of the background in that spot
color currColor = video.pixels[i];
color bkgdColor = backgroundPixels[i];
// Extract the red, green, and blue components of the current pixel<EFBFBD>s color
// Extract the red, green, and blue components of the current pixel's color
int currR = (currColor >> 16) & 0xFF;
int currG = (currColor >> 8) & 0xFF;
int currB = currColor & 0xFF;
// Extract the red, green, and blue components of the background pixel<EFBFBD>s color
// Extract the red, green, and blue components of the background pixel's color
int bkgdR = (bkgdColor >> 16) & 0xFF;
int bkgdG = (bkgdColor >> 8) & 0xFF;
int bkgdB = bkgdColor & 0xFF;
@@ -61,7 +67,7 @@ void draw() {
}
// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frame<EFBFBD>s pixels into it.
// buffer, by copying each of the current frame's pixels into it.
void keyPressed() {
video.loadPixels();
arraycopy(video.pixels, backgroundPixels);

View File

@@ -17,9 +17,14 @@ Capture video;
void setup() {
size(640, 480, P2D); // Change size to 320 x 240 if too slow at 640 x 480
strokeWeight(5);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
video.start();
// Start capturing the images from the camera
video.start();
numPixels = video.width * video.height;
noCursor();
smooth();

View File

@@ -19,13 +19,14 @@ int[] bright;
// How many pixels to skip in either direction
int increment = 5;
void setup() {
size(800, 600, P2D);
noCursor();
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
// Start capturing the images from the camera
video.start();
int count = (video.width * video.height) / (increment * increment);

View File

@@ -14,9 +14,14 @@ Capture video;
void setup() {
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
video.start();
// Start capturing the images from the camera
video.start();
numPixels = video.width * video.height;
// Create an array to store the previously captured frame
previousFrame = new int[numPixels];

View File

@@ -20,10 +20,12 @@ int[] scoot;
void setup() {
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
video.start();
// Also try with other video sizes
// Start capturing the images from the camera
video.start();
column = 0;
columnCount = width / video.width;

View File

@@ -2,8 +2,8 @@
* Getting Started with Capture.
*
* Reading and displaying an image from an attached Capture device.
*/
*/
import processing.video.*;
Capture cam;
@@ -12,21 +12,26 @@ void setup() {
size(640, 480, P2D);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
}
else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an element
// from the array returned by list():
cam = new Capture(this, cameras[0]);
cam.start();
}
// Or, the settings can be defined based on the text in the list
//cam = new Capture(this, 640, 480, "Built-in iSight", 30);
// Start capturing the images from the camera
cam.start();
}
}
void draw() {
@@ -34,7 +39,9 @@ void draw() {
cam.read();
}
image(cam, 0, 0);
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
// The following does the same as the above image() line, but
// is faster when just drawing the image without any additional
// resizing, transformations, or tint.
//set(0, 0, cam);
}
}

View File

@@ -37,8 +37,13 @@ boolean blobby = false;
void setup() {
size(640, 480, P3D);
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
video.start();
// Start capturing the images from the camera
video.start();
count = video.width * video.height;
sphereDetail(60);
@@ -63,8 +68,10 @@ void setup() {
void draw() {
background(0);
if (!blobby) lights();
if (!blobby) {
lights();
}
pushMatrix();
translate(width/2, height/2);
scale(min(width, height) / 10.0);

View File

@@ -18,9 +18,12 @@ int buffer[];
void setup() {
size(600, 400, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 320, 240);
video.start();
// Start capturing the images from the camera
video.start();
maxRows = height * 2;
buffer = new int[width * maxRows];

View File

@@ -23,9 +23,12 @@ void setup() {
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
video.start();
// Start capturing the images from the camera
video.start();
background(0);
}
@@ -35,9 +38,6 @@ void draw() {
if (video.available()) {
video.read();
video.loadPixels();
// Not bothering to clear background
// background(0);
// Begin loop for columns
for (int i = 0; i < cols; i++) {

View File

@@ -23,9 +23,12 @@ void setup() {
colorMode(RGB, 255, 255, 255, 100);
rectMode(CENTER);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
video.start();
// Start capturing the images from the camera
video.start();
background(0);
}

View File

@@ -21,9 +21,13 @@ void setup() {
// size must be set to video.width*video.height*2 in both directions
size(600, 600, P2D);
// Uses the default video input, see the reference if this causes an error
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, 160, 120);
video.start();
// Start capturing the images from the camera
video.start();
videoCount = video.width * video.height;
pixelCount = width*height;
@@ -70,6 +74,8 @@ void draw() {
updatePixels();
currentAngle++;
if (currentAngle == angleCount) currentAngle = 0;
if (currentAngle == angleCount) {
currentAngle = 0;
}
}
}

View File

@@ -7,6 +7,8 @@
* consider using the image copy() function rather than the
* direct pixel-accessing approach I have used here.
*/
import processing.video.*;
Capture video;
@@ -17,9 +19,12 @@ int drawPositionX;
void setup() {
size(600, 240, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 320, 240);
video.start();
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this,320, 240);
// Start capturing the images from the camera
video.start();
videoSliceX = video.width / 2;
drawPositionX = width - 1;

View File

@@ -24,8 +24,13 @@ int currentX = 0;
void setup() {
size(640, 480);
video = new Capture(this, width, height, 30);
video.start();
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
// Start capturing the images from the camera
video.start();
}
void captureEvent(Capture c) {

View File

@@ -16,42 +16,47 @@ ArrayList frames = new ArrayList();
void setup() {
size(640, 480);
video = new Capture(this, width, height, 30);
video.start();
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
// Start capturing the images from the camera
video.start();
}
void captureEvent(Capture camera) {
camera.read();
//copy the current video frame into an image, so it can be stored in the buffer
// Copy the current video frame into an image, so it can be stored in the buffer
PImage img = createImage(width, height, RGB);
video.loadPixels();
arrayCopy(video.pixels, img.pixels);
frames.add(img);
//once there are enough frames, remove the oldest one when adding a new one
// Once there are enough frames, remove the oldest one when adding a new one
if (frames.size() > height/4) {
frames.remove(0);
}
}
void draw() {
//set the image counter to 0
// Set the image counter to 0
int currentImage = 0;
loadPixels();
//begin a loop for displaying pixel rows of 4 pixels height
// Begin a loop for displaying pixel rows of 4 pixels height
for (int y = 0; y < video.height; y+=4) {
//go through the frame buffer and pick an image, starting with the oldest one
// Go through the frame buffer and pick an image, starting with the oldest one
if (currentImage < frames.size()) {
PImage img = (PImage)frames.get(currentImage);
if (img != null) {
img.loadPixels();
//put 4 rows of pixels on the screen
// Put 4 rows of pixels on the screen
for (int x = 0; x < video.width; x++) {
pixels[x + y * width] = img.pixels[x + y * video.width];
pixels[x + (y + 1) * width] = img.pixels[x + (y + 1) * video.width];
@@ -60,7 +65,7 @@ void draw() {
}
}
//increase the image counter
// Increase the image counter
currentImage++;
} else {
@@ -70,7 +75,7 @@ void draw() {
updatePixels();
//for recording an image sequence
// For recording an image sequence
//saveFrame("frame-####.jpg");
}