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?
- Gets the camera frames and turn each frame to gray.
- Applies the Hough Circle Transform to the grayed image.
- Turn each frame to RGB and display the detected circle in a window.
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();
}
- The demo video of this project is available on YouTube: https://www.youtube.com/watch?v=eWxtt1411Xs
- The screenshots;
Dependencies:
- Android Studio
- OpenCV (version 3.1.0)
How to build and run this source?
- Clone project by using Android Studio
- Select and build module CircleDetection
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"
}
Ahmet Özlü
This system is available under the MIT license. See the LICENSE file for more info.