Help trying to find the size of coins


#1

I have a work that I need to get a picture of coins, threshold it, find the individual blobs and then count them to find the value of the money I have on it. I am pretty new to this and have no idea how to even get the size of the various coins.

I have a simple example made with a binary picture of multiple coins, black and white, I can find it’s edges but I do not know a way to measure them.

import gab.opencv.*;

PImage img, canny;
OpenCV opencv;

void setup()
{
  size(1054,313);
  img = loadImage("bolas.png");
  opencv= new OpenCV(this,img);
  opencv.findCannyEdges(20,75);
  canny = opencv.getSnapshot();
}
void draw()
{
  scale(0.5);
  image(img,0,0);
  image(canny, img.width, 0);
}

Any help would be greatly appreciated.


#2

Were you able to resolve this issue?

Correct approaches depend a lot on your inputs. Do you have a fixed camera, and is it an overhead shot or is it at an angle (perspective) on the surface – do you need to warp the perspective? May the coins overlap or be obscured by something?

Or are you just processing a specific image? In either case, can you give an example of what your input image looks like?

One approach is to get each blob, then measure the bounding box of each blob and use it to decide which coin (and therefor what value). Are you using US coins, e.g. quarter nickel dime penny? Not all coin systems differ in value based on size in the same indicators – for some thickness layers are important, for some cutouts in the silhouette.

In addition to OpenCV, BoofCV is an option.

I’d also suggest installing BlobDetection and running the bd_image example to get started quickly. Just make the size() line static to get it running in Processing 3.x.