Currently I'm developing android app to detect circles in camera view. I'm new to OpenCV and right now I'm trying to detect circles in Image not Camera for starters. I have written this code:
Bitmap photo = BitmapFactory.decodeResource(getResources(),
R.drawable.circle);
Toast.makeText(getBaseContext(), "It works!", Toast.LENGTH_LONG).show();
Mat imgSource = new Mat(), imgCirclesOut = new Mat();
Utils.bitmapToMat(photo , imgSource);
Imgproc.cvtColor(imgSource, imgSource, Imgproc.COLOR_BGR2GRAY);
Imgproc.GaussianBlur( imgSource, imgSource, new Size(9, 9), 2, 2 );
Imgproc.HoughCircles( imgSource, imgCirclesOut, Imgproc.CV_HOUGH_GRADIENT, 1, imgSource.rows()/8, 200, 100, 0, 0 );
float circle[] = new float[3];
for (int i = 0; i < imgCirclesOut.cols(); i++)
{
imgCirclesOut.get(0, i, circle);
org.opencv.core.Point center = new org.opencv.core.Point();
center.x = circle[0];
center.y = circle[1];
Core.circle(imgSource, center, (int) circle[2], new Scalar(0,0,255), 5);
}
Bitmap bmp = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(imgSource, bmp);
image.setImageBitmap(bmp);
That works when I press a button. According to all questions, tutorials and such that I checked this should work and detect my circle, but all it does is only process my image to grayscale. Here's how it looks in my app:


Help.