Skip to content

Real Time Circle Detection and Tracking by Hough Circle Transform for Android OS with OpenCV

License

Notifications You must be signed in to change notification settings

YeShenWork/real_time_circle_detection_android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Real Time Circle Detection and Tracking for Android OS

This repository focuses on real time circle detection with OpenCV for Android OS.


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

38 13 54

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.

About

Real Time Circle Detection and Tracking by Hough Circle Transform for Android OS with OpenCV

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%