Last active
December 10, 2015 16:58
-
-
Save joshuajnoble/4464025 to your computer and use it in GitHub Desktop.
Simple processing app for creating a training file w/bounding boxes && descriptors for training RTrees, SVMs, etc in OpenCV or conceivably any CV-framework.
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
int currentIndex; | |
boolean hasBB; | |
PImage currentImage; | |
// we'll have a look in the data folder | |
String absolutePath = "path/to/images"; | |
java.io.File folder = new java.io.File(absolutePath); | |
ArrayList<String> bbOutput; | |
String currentBBInfo; | |
String[] filenames; | |
int[] startVec = new int[2]; | |
int[] endVec = new int[2]; | |
// let's set a filter (which returns true if file's extension is .jpg) | |
java.io.FilenameFilter jpgFilter = new java.io.FilenameFilter() { | |
boolean accept(File dir, String name) { | |
return name.toLowerCase().endsWith(".jpg"); | |
} | |
}; | |
void setup() | |
{ | |
bbOutput = new ArrayList<String>(); | |
currentBBInfo = ""; | |
size(1280, 1024, OPENGL); | |
// list the files in the data folder, passing the filter as parameter | |
filenames = folder.list(jpgFilter); | |
if(filenames != null) { | |
// get and display the number of jpg files | |
println(filenames.length + " jpg files in specified directory"); | |
} else { | |
println(" no folder found "); | |
exit(); | |
} | |
currentIndex = 0; | |
PImage img = loadImage(absolutePath+"/"+filenames[currentIndex]); | |
currentImage = createImage(1280, 1024, RGB); | |
// make sure we clear memory | |
currentImage.loadPixels(); | |
currentImage.copy(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height); | |
currentImage.updatePixels(); | |
} | |
void draw() | |
{ | |
background(0); | |
fill(255, 255, 255); | |
image(currentImage, 0, 0); | |
noFill(); | |
stroke(0, 255, 0); | |
rect(startVec[0], startVec[1], endVec[0] - startVec[0], endVec[1] - startVec[1]); | |
fill(0, 255, 0); | |
text(currentBBInfo, 40, 40); | |
//ellipse(startVec[0], startVec[1], 10, 10); | |
//ellipse(endVec[0], endVec[1], 10, 10); | |
} | |
void mousePressed() | |
{ | |
startVec[0] = mouseX; | |
startVec[1] = mouseY; | |
} | |
void mouseDragged() | |
{ | |
endVec[0] = mouseX; | |
endVec[1] = mouseY; | |
} | |
void mouseReleased() | |
{ | |
endVec[0] = mouseX; | |
endVec[1] = mouseY; | |
} | |
void keyPressed() | |
{ | |
switch(key) | |
{ | |
// categories here | |
} | |
if( key == ENTER) { | |
if(currentIndex < filenames.length-1) | |
{ | |
String finalString = filenames[currentIndex] + " " + startVec[0]+"," + startVec[1]+ "," +endVec[0] +","+endVec[1]+" "+currentBBInfo; | |
currentBBInfo = ""; | |
bbOutput.add(finalString); | |
endVec[0] = 0; | |
endVec[1] = 0; | |
startVec[0] = 0; | |
startVec[1] = 0; | |
currentIndex++; | |
// this is all to make sure that we clear memory properly | |
System.gc(); | |
PImage img = loadImage(absolutePath+"/"+filenames[currentIndex]); | |
currentImage.loadPixels(); | |
currentImage.copy(img, 0, 0, img.width, img.height, 0, 0, img.width, img.height); | |
currentImage.updatePixels(); | |
} | |
if(currentIndex == filenames.length-1) | |
{ | |
String[] bbout = new String[bbOutput.size()]; | |
bbOutput.toArray(bbout); // java casting meh | |
saveStrings("training.txt", bbout); | |
} | |
} | |
if(key == ESC) | |
{ | |
String[] bbout = new String[bbOutput.size()]; | |
bbOutput.toArray(bbout); // java casting meh | |
saveStrings("training.txt", bbout); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment