Giter Site home page Giter Site logo

objectdetection's Introduction

ObjectDetection

Android SDK object detection with Tensorflow Lite.

Features

  • Object detection with given Tensorflow Lite model

  • Uses Koin for dependency injection

  • Modular structure with builder pattern

  • Notify user with events

  • Video Capture, Object Detection and Camera Preview

It is aimed to provide creating a custom Android SDK/Framework for implementing a custom camera view with advanced functionalities.

The main goal of this SDK is to provide developers with a customizable camera view that handles camera permission management internally and supports two modes: object detection and video capture, with an option to combine both functionalities.

demo-image

demo-preview.mp4
demo-video.mp4

Installation

Dont forget to ad Jitpack to root build.gradle

dependencyResolutionManagement {

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

repositories {

mavenCentral()

maven { url 'https://jitpack.io' }
	}
}

Add to project build.gradle

dependencies {
implementation("org.tensorflow:tensorflow-lite-gpu:2.3.0")
implementation("org.tensorflow:tensorflow-lite-support:0.1.0")
implementation("org.tensorflow:tensorflow-lite-metadata:0.1.0")
implementation ("io.insert-koin:koin-android:3.5.6")
implementation ("com.github.root14:ObjectDetection:1.0")
}

Usage

There are two types of usage styles

With CustomView

You can use media buttons with customView.

val detectionSurface = findViewById<DetectionSurface>(R.id.detectionSurface)

DetectionSdk.init(this, object : DetectionSdkLogger {  
    override fun eventCallback(events: Events) {  
        if (events == Events.INIT_SUCCESS) {  
            val objectDetector =  
                ObjectDetector.Builder().withDetectionSurface(detectionSurface)  
                    .enableMediaButtons(true).build()  
  
            objectDetector.bindToSurface()  
        }   
    }  
})
XML file should look like that
<com.root14.detectionsdk.view.DetectionSurface  
  android:id="@+id/detectionSurface"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent" />

With Views

val textureView = findViewById<TextureView>(R.id.textureView)
val detectionLabel = findViewById<ImageView>(R.id.detectionLabel)

DetectionSdk.init(this, object : DetectionSdkLogger {  
    override fun eventCallback(events: Events) {  
        if (events == Events.INIT_SUCCESS) {  
	        val objectDetector =
	            ObjectDetector.Builder().withTextureView(textureView).addDetectionLabel(detectionLabel)
	                .addContext(this).build()

	        objectDetector.bindToSurface() 
        }   
    }  
})

When an object is found, DetectionLabel draws a rectangle around it.

XML file should look like that

        <TextureView
            android:id="@+id/textureView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <ImageView
            android:id="@+id/detectionLabel"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000" />
    </androidx.constraintlayout.widget.ConstraintLayout>

If you want to handle events, basically

when (events) {  
    Events.START_RECORD -> Log.d("detection-sdk", "start  recording.")  
    Events.PAUSE_RECORD -> Log.d("detection-sdk", "pause  recording.")  
    Events.RESUME_RECORD -> Log.d("detection-sdk", "resume  recording.")  
    Events.STOP_RECORD -> Log.d("detection-sdk", "stop  recording.")  
    Events.INIT_SUCCESS -> Log.d("detection-sdk", "init successfully")  
    Events.INIT_FAIL -> Log.d("detection-sdk", "init  fail.")  
}

Compatibility

minSdk version is 30.

Known Issues

When video recording is finished, sometimes it may take time(may minutes) for the video to be displayed on the device.

objectdetection's People

Contributors

root14 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.