Skip to content

Real time circle detection and tracking by Hough Circle Transform with OpenCV on Android OS.

License

Notifications You must be signed in to change notification settings

ahmetozlu/real_time_circle_detection_android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Real Time Circle Detection and Tracking for Android

This repository focuses on real time circle detection with OpenCV on Android OS. Please contact if you need professional object detection & tracking & counting projects on Android devices with the super high accuracy!


What does this program do?

  1. Gets the camera frames and turn each frame to gray.
  2. Applies the Hough Circle Transform to the grayed image.
  3. Turn each frame to RGB and display the detected circle in a window.

Theory

Hough Circle Transform was used for circle detection in this project. It works in a roughly analogous way to the Hough Line Transform.

The flow diagram of this application;

OnCameraFrame method which is located at MainActivity.java;

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        Mat input = inputFrame.gray();
        Mat circles = new Mat();
        Imgproc.blur(input, input, new Size(7, 7), new Point(2, 2));
        Imgproc.HoughCircles(input, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 100, 100, 90, 0, 1000);

        Log.i(TAG, String.valueOf("size: " + circles.cols()) + ", " + String.valueOf(circles.rows()));

        if (circles.cols() > 0) {
            for (int x=0; x < Math.min(circles.cols(), 5); x++ ) {
                double circleVec[] = circles.get(0, x);

                if (circleVec == null) {
                    break;
                }

                Point center = new Point((int) circleVec[0], (int) circleVec[1]);
                int radius = (int) circleVec[2];

                Imgproc.circle(input, center, 3, new Scalar(255, 255, 255), 5);
                Imgproc.circle(input, center, radius, new Scalar(255, 255, 255), 2);
            }
        }

        circles.release();
        input.release();
        return inputFrame.rgba();
}

Project Demo

Installation

Dependencies:

How to build and run this source?

  1. Clone project by using Android Studio
  2. Select and build module CircleDetection

Citation

If you use this code for your publications, please cite it as:

@ONLINE{vdtc,
    author = "Ahmet Özlü",
    title  = "Real Time Circle Detection and Tracking for Android OS",
    year   = "2017",
    url    = "https://github.com/ahmetozlu/real_time_circle_detection_android"
}

Author

Ahmet Özlü

License

This system is available under the MIT license. See the LICENSE file for more info.

Releases

No releases published

Packages

No packages published

Languages