diff --git a/build.gradle b/build.gradle index d995047..4e9ae25 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'ch.bildspur' -version '0.3.1' +version '0.3.2' apply plugin: 'java' diff --git a/examples/FaceDetectorSelfie/FaceDetectorSelfie.pde b/examples/FaceDetectorSelfie/FaceDetectorSelfie.pde new file mode 100644 index 0000000..7ca8b11 --- /dev/null +++ b/examples/FaceDetectorSelfie/FaceDetectorSelfie.pde @@ -0,0 +1,51 @@ +import ch.bildspur.vision.*; +import ch.bildspur.vision.result.*; +import java.util.List; + +PImage testImage; + +DeepVision vision; +ULFGFaceDetectionNetwork network; +List detections; + +public void setup() { + size(640, 480); + colorMode(HSB, 360, 100, 100); + + vision = new DeepVision(this); + testImage = loadImage(sketchPath("data/selfie.jpg")); + + println("creating network..."); + network = vision.createULFGFaceDetectorRFB640(); + network.setConfidenceThreshold(0.2); + + println("loading model..."); + network.setup(); + + //network.setConfidenceThreshold(0.2f); + + println("inferencing..."); + detections = network.run(testImage); + println("done!"); + + for (ObjectDetectionResult detection : detections) { + System.out.println(detection.getClassName() + "\t[" + detection.getConfidence() + "]"); + } + + println("found " + detections.size() + " faces!"); +} + +public void draw() { + background(55); + image(testImage, 0, 0); + + noFill(); + strokeWeight(2f); + + stroke(200, 80, 100); + for (ObjectDetectionResult detection : detections) { + rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight()); + } + + surface.setTitle("Face Recognition Test - Faces: " + detections.size()); +} diff --git a/examples/FaceDetectorSelfie/data/selfie.jpg b/examples/FaceDetectorSelfie/data/selfie.jpg new file mode 100644 index 0000000..71ffe74 Binary files /dev/null and b/examples/FaceDetectorSelfie/data/selfie.jpg differ diff --git a/examples/HumanPoseWebcam/HumanPoseWebcam.pde b/examples/HumanPoseWebcam/HumanPoseWebcam.pde index 51669f0..cf32818 100644 --- a/examples/HumanPoseWebcam/HumanPoseWebcam.pde +++ b/examples/HumanPoseWebcam/HumanPoseWebcam.pde @@ -11,6 +11,8 @@ HumanPoseResult result; Capture cam; +float threshold = 0.5; + void setup() { size(640, 480, FX2D); @@ -81,6 +83,9 @@ private void drawHuman(HumanPoseResult human) { int i = 0; fill(0); for (KeyPointResult point : human.getKeyPoints()) { + if(point.getProbability() < threshold) + continue; + ellipse(point.getX(), point.getY(), 10, 10); text(i, point.getX() + 5, point.getY()); i++; @@ -92,6 +97,9 @@ private void connect(KeyPointResult... keyPoints) { KeyPointResult a = keyPoints[i]; KeyPointResult b = keyPoints[i + 1]; + if(a.getProbability() < threshold || b.getProbability() < threshold) + continue; + line(a.getX(), a.getY(), b.getX(), b.getY()); } } diff --git a/examples/MNISTDetector/MNISTDetector.pde b/examples/MNISTDetector/MNISTDetector.pde new file mode 100644 index 0000000..3c3208f --- /dev/null +++ b/examples/MNISTDetector/MNISTDetector.pde @@ -0,0 +1,93 @@ +import ch.bildspur.vision.*; +import ch.bildspur.vision.result.*; + +DeepVision vision; +MNISTClassificationNetwork network; + +ClassificationResult result; +long inferenceTime = 0; +PImage canvas = new PImage(28, 28, RGB); + +boolean mouseDrawing = false; +float factor = 560 / 28; + +public void setup() { + size(560, 560, FX2D); + colorMode(HSB, 360, 100, 100); + + vision = new DeepVision(this); + + println("creating network..."); + network = vision.createMNISTClassifier(); + + println("loading model..."); + network.setup(); + + clearCanvas(); + println("ready!"); +} + +public void draw() { + background(55); + + if (mouseDrawing) { + int x = round(mouseX / factor); + int y = round(mouseY / factor); + + canvas.set(x, y, color(255)); + canvas.updatePixels(); + } + + //image(canvas, 0, 0, width, height); + for (int y = 0; y < canvas.width; y++) { + for (int x = 0; x < canvas.width; x++) { + color c = canvas.get(x, y); + fill(c); + noStroke(); + rect(x * factor, y * factor, factor, factor); + } + } + + // display info + fill(140, 80, 100); + textSize(16); + text("space: run inference / c: clear canvas", 10, 20); + + if (result != null) { + text("Detected '" + result.getClassName() + "' with " + result.getConfidence() + "%", 10, 50); + } + + surface.setTitle("MNIST Detector"); +} + +void mousePressed() { + mouseDrawing = true; +} + +void mouseReleased() { + mouseDrawing = false; +} + +void keyPressed() { + if (key == ' ') { + println("inferencing..."); + int start = millis(); + result = network.run(canvas); + inferenceTime = millis() - start; + } + + if (key == 'c' || key == 'C') { + println("clearing canvas..."); + clearCanvas(); + result = null; + } +} + +void clearCanvas() { + for (int y = 0; y < canvas.width; y++) { + for (int x = 0; x < canvas.width; x++) { + canvas.set(x, y, color(0)); + } + } + canvas.updatePixels(); +} diff --git a/examples/RealSensePoseCapture/RealSensePoseCapture.pde b/examples/RealSensePoseCapture/RealSensePoseCapture.pde index e3d8b55..924e3b5 100644 --- a/examples/RealSensePoseCapture/RealSensePoseCapture.pde +++ b/examples/RealSensePoseCapture/RealSensePoseCapture.pde @@ -1,5 +1,5 @@ import ch.bildspur.vision.DeepVision; -import ch.bildspur.vision.SingleHumanPoseEstimationNetwork; +import ch.bildspur.vision.SingleHumanPoseNetwork; import ch.bildspur.vision.result.HumanPoseResult; import ch.bildspur.vision.result.KeyPointResult; @@ -9,7 +9,7 @@ RealSenseCamera camera = new RealSenseCamera(this); DeepVision vision = new DeepVision(this); -SingleHumanPoseEstimationNetwork pose; +SingleHumanPoseNetwork pose; HumanPoseResult result; void setup() diff --git a/examples/RealSenseYoloDetector/RealSenseYoloDetector.pde b/examples/RealSenseYoloDetector/RealSenseYoloDetector.pde index cae3556..d2e0432 100644 --- a/examples/RealSenseYoloDetector/RealSenseYoloDetector.pde +++ b/examples/RealSenseYoloDetector/RealSenseYoloDetector.pde @@ -53,7 +53,7 @@ void draw() strokeWeight(2f); for (ObjectDetectionResult detection : result) { - stroke(round(360.0f * (float) detection.getClassId() / net.getNames().size()), 75, 100); + stroke(round(360.0f * (float) detection.getClassId() / net.getClassNames().size()), 75, 100); rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight()); textSize(15); diff --git a/examples/SingleHumanPoseEstimation/SingleHumanPoseEstimation.pde b/examples/SingleHumanPoseEstimation/SingleHumanPoseEstimation.pde index 9f77522..f8f5a7e 100644 --- a/examples/SingleHumanPoseEstimation/SingleHumanPoseEstimation.pde +++ b/examples/SingleHumanPoseEstimation/SingleHumanPoseEstimation.pde @@ -5,9 +5,9 @@ import ch.bildspur.vision.result.KeyPointResult; PImage testImage; -DeepVision vision = new DeepVision(this); +DeepVision vision; -SingleHumanPoseEstimationNetwork pose; +SingleHumanPoseNetwork pose; HumanPoseResult result; PImage image; @@ -16,10 +16,10 @@ void setup() { size(480, 640, FX2D); colorMode(HSB, 360, 100, 100); - testImage = loadImage(sketchPath("data/pose.jpg")); println("creating network..."); + vision = new DeepVision(this); pose = vision.createSingleHumanPoseEstimation(); println("loading model..."); diff --git a/examples/YOLODetectObjects/YOLODetectObjects.pde b/examples/YOLODetectObjects/YOLODetectObjects.pde index 2021a02..2b1de03 100644 --- a/examples/YOLODetectObjects/YOLODetectObjects.pde +++ b/examples/YOLODetectObjects/YOLODetectObjects.pde @@ -16,10 +16,14 @@ public void setup() { image = loadImage("hk.jpg"); println("creating model..."); - yolo = deepVision.createYOLOv3Tiny(); + yolo = deepVision.createYOLOv3(); println("loading yolo model..."); yolo.setup(); + + println("inferencing..."); + yolo.setConfidenceThreshold(0.3f); + detections = yolo.run(image); } public void draw() { @@ -27,14 +31,11 @@ public void draw() { image(image, 0, 0); - yolo.setConfidenceThreshold(0.2f); - detections = yolo.run(image); - noFill(); strokeWeight(2f); for (ObjectDetectionResult detection : detections) { - stroke((int)(360.0 / yolo.getNames().size() * detection.getClassId()), 80, 100); + stroke((int)(360.0 / yolo.getClassNames().size() * detection.getClassId()), 80, 100); rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight()); } diff --git a/examples/YoloWecamExample/YoloWecamExample.pde b/examples/YoloWecamExample/YoloWecamExample.pde index 736a354..fd732ed 100644 --- a/examples/YoloWecamExample/YoloWecamExample.pde +++ b/examples/YoloWecamExample/YoloWecamExample.pde @@ -25,7 +25,8 @@ public void setup() { println("loading yolo model..."); yolo.setup(); - cam = new Capture(this); + String[] cams = Capture.list(); + cam = new Capture(this, cams[0]); cam.start(); } @@ -47,7 +48,7 @@ public void draw() { strokeWeight(2f); for (ObjectDetectionResult detection : detections) { - stroke((int)(360.0 / yolo.getNames().size() * detection.getClassId()), 80, 100); + stroke((int)(360.0 / yolo.getClassNames().size() * detection.getClassId()), 80, 100); rect(detection.getX(), detection.getY(), detection.getWidth(), detection.getHeight()); } diff --git a/library.properties b/library.properties index cd86501..d8131c3 100644 --- a/library.properties +++ b/library.properties @@ -4,7 +4,7 @@ authors=[Florian Bruggisser](https://broox.ch) url=https://github.com/cansik/deep-vision-processing sentence=Deep computer-vision algorithms for Processing paragraph=Run deep neural networks on images in Processing. -version=003010 -prettyVersion=0.3.1 +version=003020 +prettyVersion=0.3.2 minRevision=0 maxRevision=0 diff --git a/release.sh b/release.sh index 55c6fa4..1f41fbd 100755 --- a/release.sh +++ b/release.sh @@ -45,6 +45,11 @@ cp "build/libs/$ARCHIVE_NAME-complete.jar" "$OUTPUT/library/$ARCHIVE_NAME.jar" # cp -r native "$OUTPUT/library/" cp -r "build/docs/javadoc" "$OUTPUT/reference" +# clean networks from examples +cd "examples" +rm -rf **/networks +cd .. + cp -r "examples" "$OUTPUT/" cp library.properties "$OUTPUT/" cp -r readme "$OUTPUT/" diff --git a/src/main/java/ch/bildspur/vision/MNISTClassificationNetwork.java b/src/main/java/ch/bildspur/vision/MNISTClassificationNetwork.java index ed59407..d628ca4 100644 --- a/src/main/java/ch/bildspur/vision/MNISTClassificationNetwork.java +++ b/src/main/java/ch/bildspur/vision/MNISTClassificationNetwork.java @@ -67,7 +67,8 @@ public ClassificationResult run(Mat frame) { for (int i = 0; i < out.cols(); i++) { float probability = data.get(i); - System.out.println("# " + i + ": " + probability + "%"); + // todo: fix probability issue + // System.out.println("# " + i + ": " + probability + "%"); if (probability > maxProbability) { maxProbability = probability; diff --git a/src/test/java/ch/bildspur/vision/test/FaceRecognitionTest.java b/src/test/java/ch/bildspur/vision/test/FaceRecognitionTest.java index ef37540..b9d4baf 100644 --- a/src/test/java/ch/bildspur/vision/test/FaceRecognitionTest.java +++ b/src/test/java/ch/bildspur/vision/test/FaceRecognitionTest.java @@ -32,7 +32,7 @@ public void setup() { testImage = loadImage(sketchPath("data/office.jpg")); println("creating network..."); - network = vision.createULFGFaceDetectorSlim640(); + network = vision.createULFGFaceDetectorRFB640(); println("loading model..."); network.setup();