chen0040 / java-ssd-object-detection

Image SSD object detection in Java using Tensorrflow

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

java-ssd-object-detection

Image SSD object detection in pure Java using Tensorrflow

This project is a derivation from the tensorflow object detection codes but makes it easy to integrate with other java application

Install

To install, add the following dependency to your POM file:

<dependency>
  <groupId>com.github.chen0040</groupId>
  <artifactId>java-ssd-object-detection</artifactId>
  <version>1.0.1</version>
</dependency>

Usage

The sample codes below shows how to detect objects in an image using the ObjectDetector class:

import com.github.chen0040.objdetect.models.DetectedObj;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;

public class ObjectDetectorDemo {
    public static void main(String[] args) throws Exception {
        ObjectDetector detector = new ObjectDetector();

        detector.loadModel();

        BufferedImage img = ImageIO.read(new File("images/test.jpg"));

        List<DetectedObj> result = detector.detectObjects(img);

        System.out.println("There are " + result.size() + " objects detected");
        for(int i=0; i < result.size(); ++i){
            System.out.println("# " + (i + 1) + ": " + result.get(i));
        }
        
        BufferedImage img2 = detector.drawDetectedObjects(img);
        ImageIO.write(img2, "PNG", new File("images/test_output.png"));
    }
}

Below shows the result of the test_output.png generated:

test_output.png

About

Image SSD object detection in Java using Tensorrflow

License:MIT License


Languages

Language:Java 88.9%Language:Shell 6.3%Language:Batchfile 4.8%