Hardware Reference
In-Depth Information
Here's a sketch that
uses the video library
to paint a live image from the webcam
to the screen. Run it and you'll see
yourself (or your cat).
Try It
/**
Image capture and upload
Context: Processing
*/
import processing.video.*; // import the video library
Capture myCam; // the camera
void setup() {
size(640, 480); // set the size of the window
// For a list of cameras on your computer, use this line:
println(Capture.list());
// use the default camera for capture at 30 fps:
myCam = new Capture(this, width, height, 30);
}
void draw() {
// if there's data from the camera:
if (myCam.available()) {
myCam.read(); // read the camera image
set(0, 0, myCam); // draw the camera image to the screen
}
}
8
Add these lines after the set()
command in the draw() method to
draw a timestamp on the screen (new
lines are shown in blue).
void draw() {
// if there's data from the camera:
if (myCam.available()) {
myCam.read(); // read the camera image
set(0, 0, myCam); // draw the camera image to the screen
// get the time as a string:
String timeStamp = nf(hour(), 2) + ":" + nf(minute(), 2)
+ ":" + nf(second(), 2) + " " + nf(day(), 2) + "-"
+ nf(month(), 2) + "-" + nf(year(), 4);
// draw a dropshadow for the time text:
fill(15);
text(timeStamp, 11, height - 19);
// draw the main time text:
fill(255);
text(timeStamp, 10, height - 20);
}
}
 
Search WWH ::




Custom Search