Enumerate all files in the data folder of Processing

There are lots of ways to enumerate all the files inside the data folder of Processing sketch. Here are 2 of them. The first one uses the Java DirectoryStream class. The second one uses the static function walkFileTree from the Files class.
 
Example with DirectoryStream

try {
    DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(dataPath(""))); 
    for (Path file : stream) {
      println(file.getFileName());
    }
  } 
  catch (IOException e) {
    e.printStackTrace();
}

Example with Files.walkFileTree

try {
    Files.walkFileTree(Paths.get(dataPath("")), new SimpleFileVisitor<Path>() {
      @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
        println(file.getFileName());
        return FileVisitResult.CONTINUE;
      }
    }
    );
  } 
  catch (IOException e) {
    e.printStackTrace();
}

 

Looping through a List in Processing

Here is a piece of demonstration code to use various ways to loop through a List or ArrayList in Processing, i.e. Java. The first two examples use for loop and the third one uses the while loop.
 
We initialize the ArrayList with random integers.

ArrayList<Integer> iList = new ArrayList<Integer>();
iList.add(floor(random(10)));
iList.add(floor(random(10)));
iList.add(floor(random(10)));

The first method is the traditional way to loop with an index.

for (int i=0; i<iList.size(); i++) {
    println(iList.get(i));
}

The second method also uses the for loop, but with alternate syntax.

for (int i : iList) {
    println(i);
}

The third method uses the Iterator through the ArrayList.

Iterator<Integer> it = iList.iterator();
while (it.hasNext()) {
    int i = it.next();
    println(i);
}

OpenCV 3.1 release Java build

It is the Java build of the new OpenCV 3.1 release. The zipped file contains the Java build for the 64 bit versions of Linux, Mac OSX and Windows. It is available for download at

OpenCV 3.1.0 Java build (64 bit)

Again, you can copy the individual files to your Processing code folder to play with the experiments in this website.

Processing 3.0 Video library in Ubuntu

I installed the new Processing 3.0 and its video library in Ubuntu and found that the Movie class could not display the digital video. It only played the audio track. The Capture class worked well. Afters some Google researches about the gstreamer package, I concluded that it can be the missing gstreamer0.10-ffmpeg module. By installing it again as described here, the Movie class worked fine.

 

Chinese calligraphy in Processing

The following video is from my research project to integrate the writing of Chinese calligraphy, especially the script style with the fighting scenes in Chinese martial art films.
 

OpenCV and Processing 20

It is a little side tracked from the previous posts. The example demonstrated the use of Kalman Filter in OpenCV with Processing.