This is my first demo run of the dnn (deep neural network) module in OpenCV 3.4.2 with Processing, using my CVImage library. The module can input pre-trained models from Caffe, Tensorflow, Darknet, and Torch. In this example, I used the Tensorflow model Inception v2 SSD COCO from here. I also obtained the label map file from the Tensorflow GitHub. The following 3 files are in the data folder of the Processing sketch.
frozen_inference_graph.pb
ssd_inception_v2_coco_2017_11_17.pbtxt
mscoco_label_map.pbtxt
The source code is in my GitHub repository of this website here.
After the release of OpenCV 3.4.2, I have prepared the pre-built version of the Java libraries for OSX, Ubuntu, and Windows 8.1 platforms (64 bits). In this release, there is more extensive support for the Java binding. I also packaged the library as the Processing library – CVImage. Please refer to latest book for details. In addition to the optflow contributed library, it also includes additional contributed libraries, such as bgsegm, face, and tracking.
In the former post, I have tested using the jCodec 0.1.5 and 0.2.0 to save the Processing screen into an MP4 file. The latest version of jCodec 0.2.3 has, however, changed its functions for the AWT based applications. Here is the new code for Processing to use jCodec 0.2.3 to save any BufferedImage to an external MP4 file.
To use the code, you need to download from the jCodec website the following two jar files and put them into the code folder of your Processing sketch.
jcodec-0.2.3.jar
jcodec-javase-0.2.3.jar
The following code will write a frame of your Processing screen into the MP4 file for every mouse pressed action.
Here is the first test of using Charts from JavaFX in Processing. In the recent version of Processing, we are able to use FX2D renderer. The following is a simple pie chart example.
importjavafx.scene.canvas.Canvas;importjavafx.scene.Scene;//import javafx.stage.Stage;importjavafx.scene.layout.StackPane;importjavafx.collections.ObservableList;importjavafx.collections.FXCollections;importjavafx.scene.chart.*;importjavafx.geometry.Side;void setup(){
size(640, 480, FX2D);
background(255);
noLoop();}void draw(){
pieChart();}void pieChart(){Canvas canvas =(Canvas)this.getSurface().getNative();
Scene scene = canvas.getScene();// Stage st = (Stage) s.getWindow();
StackPane pane =(StackPane) scene.getRoot();
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(new PieChart.Data("Fat Bear", 10),
new PieChart.Data("Pooh San", 20),
new PieChart.Data("Pig", 8),
new PieChart.Data("Rabbit", 15),
new PieChart.Data("Chicken", 2));
PieChart chart =new PieChart(pieChartData);
chart.setTitle("Animals");
chart.setLegendSide(Side.RIGHT);
pane.getChildren().add(chart);}
import javafx.scene.canvas.Canvas;
import javafx.scene.Scene;
//import javafx.stage.Stage;
import javafx.scene.layout.StackPane;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import javafx.scene.chart.*;
import javafx.geometry.Side;
void setup() {
size(640, 480, FX2D);
background(255);
noLoop();
}
void draw() {
pieChart();
}
void pieChart() {
Canvas canvas = (Canvas) this.getSurface().getNative();
Scene scene = canvas.getScene();
// Stage st = (Stage) s.getWindow();
StackPane pane = (StackPane) scene.getRoot();
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Fat Bear", 10),
new PieChart.Data("Pooh San", 20),
new PieChart.Data("Pig", 8),
new PieChart.Data("Rabbit", 15),
new PieChart.Data("Chicken", 2));
PieChart chart = new PieChart(pieChartData);
chart.setTitle("Animals");
chart.setLegendSide(Side.RIGHT);
pane.getChildren().add(chart);
}
The new release of OpenCV 3.3 is out now. I again prepare the Java build for the CVImage Processing library use. It also includes the optflow extra module for motion history applications. Here is the list of the 3 OpenCV releases.
The book Pro Processing for Images and Computer Vision with OpenCV will be released soon. It will include the detailed build instructions in multiple platforms.
The Java binding for the Google Deep Learning library, TensorFlow is now available. The binary library files for version 1.1.0-rc1 are also available for download here. Below is the code for the Hello World program included in the distribution that I modified for Processing.
importorg.tensorflow.Graph;importorg.tensorflow.Session;importorg.tensorflow.Tensor;importorg.tensorflow.TensorFlow;
Graph g1;
Output o1;
Output o2;
Output o3;
PFont font;String res;void setup(){
size(640, 480);
noLoop();}void draw(){
background(0);
Graph g =new Graph();String value ="Hello from "+ TensorFlow.version();
Tensor t =null;try{
t = Tensor.create(value.getBytes("UTF-8"));}catch(Exception e){
println(e.getMessage());}
g.opBuilder("Const", "MyConst")
.setAttr("dtype", t.dataType())
.setAttr("value", t)
.build();
Session s =new Session(g);
Tensor output =null;try{
output = s.runner()
.fetch("MyConst")
.run()
.get(0);
println(newString(output.bytesValue(), "UTF-8"));}catch(Exception e){
println(e.getMessage());}}