I'm trying to make an app in Android Studio using OpenCV that basically looks at an image of a group of dots and extracts all of the bright dots and then counts them. The dot shape is not consistent, but the color of the dots should be white with a black background.
I start by uploading an image like this:
I then take the the bitmap of the image and convert it to gray scale. Then I check that the gray values are within a a range and return a bitmap of binary values. The returned image looks like this:
I've unsuccessfully tried a few different methods to count these dots including using Imgproc.findContours and following along tutorials such as this one but I am not looking for a particular shape. It is mostly just a grouping of 1 to 50 pixels at a time with rgb values 225, 255, 255 and irregular shapes. How can these individual shapes be counted?
Here is my image processing portion of the code, the countNonZero portion is just to give me an idea of how many white pixels there are, which is 179 for this particular image
public void convertToGray(View v){
int whitePix;
Mat Rgba = new Mat();
Mat grayMat = new Mat();
Mat dots = new Mat();
BitmapFactory.Options o = new BitmapFactory.Options();
o.inDither=false;
o.inSampleSize=4;
int width = imageBitmap.getWidth();
int height = imageBitmap.getHeight();
grayBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.RGB_565);
//bitmap to MAT
Utils.bitmapToMat(imageBitmap,Rgba);
Imgproc.cvtColor(Rgba,Rgba,Imgproc.COLOR_RGB2GRAY);
Core.inRange(Rgba,scalarLow,scalarHigh,grayMat);
whitePix = Core.countNonZero(grayMat);
Utils.matToBitmap(grayMat,grayBitmap);
MediaStore.Images.Media.insertImage(getApplicationContext().getContentResolver(), grayBitmap, "Result", "Descrip");
mImageView.setImageBitmap(grayBitmap);
}
This function is called when a button is clicked after an image has been uploaded to the app.