Created
October 8, 2012 01:23
-
-
Save atduskgreg/3850251 to your computer and use it in GitHub Desktop.
Sketch for capturing sample images for machine learning image recognition applications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This sketch uses the processing video library to capture a series | |
of still images meant to be used as training images for various | |
machine learning techniques. | |
Instructions: | |
- Change the 'fileprefix' variable to match the object you | |
are capturing. | |
(this will make it easy for you to extract the images later with split()) | |
- Start the sketch. | |
- Hold one of your objects so it is visible inside of the red box. | |
- Hit the spacebar to capture an image; | |
- Repeat with the object at different distances and positions. | |
- Quit the sketch and change the fileprefix variable based on your next object | |
- Repeat the capturing steps for all of your objects. | |
*/ | |
import processing.video.*; | |
Capture video; | |
int rectW = 300; | |
int rectH = 300; | |
PImage croppedImage, currentImage; | |
int n = 0; | |
// CHANGEME: | |
String fileprefix = "myThing"; | |
void setup() { | |
size(640, 480); | |
video = new Capture(this, 640, 480); | |
video.start(); | |
croppedImage = createImage(rectW, rectH, RGB); | |
currentImage = createImage(width, height, RGB); | |
} | |
void captureEvent(Capture c) { | |
c.read(); | |
} | |
void draw() { | |
image(video, 0, 0); | |
noFill(); | |
stroke(255, 0, 0); | |
strokeWeight(5); | |
rect(width - rectW - (width - rectW)/2, height - rectH - (height - rectH)/2, rectW, rectH); | |
} | |
void keyPressed() { | |
currentImage.pixels = video.pixels; | |
currentImage.updatePixels(); | |
croppedImage.copy(currentImage, width - rectW - (width - rectW)/2 + 3, height - rectH - (height - rectH)/2 + 3, rectW - 6, rectH - 6, 0, 0, rectW, rectH); | |
croppedImage.updatePixels(); | |
croppedImage.save(fileprefix+"-"+n+".png"); | |
n++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment