Coder Social home page Coder Social logo

androidobjectdetection's Introduction

Android Object Detection - OpenCV and YOLO

Real time object detection Android application using OpenCV 4.1 and YOLO.

Author: Matteo Medioli

YOLO: https://pjreddie.com/darknet/yolo/

1.Import OpenCV 4.1 Module in AndroidStudio 3.4.1

  1. Dowload OpenCV SDK from https://sourceforge.net/projects/opencvlibrary/files/4.1.0/opencv-4.1.0-android-sdk.zip/download
  2. Clone this project.
  3. Open Android Studio and import this project.
  4. Build project.
  5. From AndroidStudio top-menù select New -> Import Module and select your path to OpenCV sdk folder (i.e /where_opencv_saved/OpenCV-android-sdk/sdk) and rename module as OpenCV.
  6. After load OpenCV module, re-build project.

2.Add OpenCV dependecies to your application

After OpenCV module import:

  1. From AndroidStudio top-menù select File -> Project Structure
  2. Navigate to Dependencies and click on app. On the right panel there's a plus button + for add Dependency. Click on it and choose Module Dependecy.
  3. Select OpenCV module loaded before.
  4. Click Ok and Apply changes.
  5. Build project.

3.How detection works: CameraActivity.java

This activity is the core of application and it implements org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2. It has 2 main private instance variable: a net (org.opencv.dnn.Net) and a cameraView (org.opencv.android.CameraBridgeViewBase). Basically has three main features:

a) Load Network

Load convolutional net from *.cfg and *.weights files and read labels name (COCO Dataset) in assets folder when calls onCameraViewStarted() using Dnn.readNetFromDarknet(String path_cfg, String path_weights).
NOTE: this repo doesn't contain weights file. You have to download it from YOLO site.

b) Detection from camera preview

Iteratively generate a frame from CameraBridgeViewBase preview and analize it as an image. Real time detection and the frames flow generation is managed by onCameraFrame(CvCameraViewFrame inputFrame). Preview frame is translate in a Mat matrix and set as input for Dnn.blobFromImage(frame, scaleFactor, frame_size, mean, true, false) to preprocess frames. Note that frame_size is 416x416 for YOLO Model (you can find input dimension in *.cfg file). We can change the size by adding or subtracting by a factor of 32. Reducing the framesize increases the performance but worsens the accuracy. The detection phase is implemented by net.forward(List<Mat> results, List<String> outNames) that runs forward pass to compute output of layer with name outName. In results the method writes all detections in preview frame as Mat objects. Theese Mat instances contain all information such as positions and labels of detected objects.

c) Draw bounding-box and labelling

Performing Non Maximum Suppression by YOLO, in List<Mat> results are stored all coordinates of optimal bounding boxes (the first 4 numbers are [center_x, center_y, width, height], followed by all class probabilities). classId is the corresponding index for label of detection in COCO Dataset list className.

TO DO

  • Full screen JavaCameraView portrait mode
  • Speed up JavaCameraView
  • Add model chioce

androidobjectdetection's People

Contributors

matteomedioli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

androidobjectdetection's Issues

not support cameras

hi,I have a problem when I install the app on my phone and It goes wrong: "It seems that your device does not support camera(or It is locked)",What can be done about it? thank you.

Only Welcome view

Hi,
Your repo is the only one which shows the way to apply YOLO-v3 model for the object detection.
I downloaded yolov3-tiny.weights from the Darknet site and put it on the assets.
Also I imported the OpenCV 4.1.0 SDK as a module and specified its dependency in app.
The welcome page is shown for a while but the application seems to be terminated.
My test phone is Huawei mate s (HUAWEI LYA-L29 with GPU).
I specified API as 29.
Will you kindly give me some advice to solve this issue?
Thenk you

Black Screen

I followed your example in my own application step by step but I got black screen in camera. The onFrame method is called and the net.forward is called too but the rest does not execute. Then I cloned your repo and installed it but it is still the same.
Any ideas or clues to how to proceed?

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.