Close

"AutoCoin" or: What even is a coin, anyway?

A project log for LadyBug BEEFY: 3D printer motorized microscope

Got printer? Connect to the motors with a Pi, plonk in a cheap scope, and do 2D and 3D scans!

ahron-wayneAhron Wayne 12/31/2020 at 00:372 Comments

I started this post 6 weeks ago. At that time I said "I've been working on this for the past week", wrote a bunch of stuff which is currently below my current text, and which I will proceed to delete because almost none of it is relevant anymore. You don't want to hear about all the problems I faced doing this, right? Or maybe you do, because that's hackaday. So I'll just share one thing, the thing this post is titled for, and then you can skip to the video which organizes the results in an attractive way and definitely does not misrepresent how much spaghetti it took to do this.

Ahem: 

How do you determine what is, or isn't, a coin? Color? Luster? Brightness? Some specific pattern of features that you match against a database? Whatever it was, if I wanted to automatically scan coins (don't ask), I was going to have to figure out what was a coin and what was just my scanner stage. 

To show you how pointless this problem is, one of these pictures is my blurry scanner stage and the other is a blurry nickel.

Oh, because they look so different. Maybe it is indeed possible with some unknown set of features to find your coins this way, and believe me,  I tried. I even tried using a neural network with the extremely advanced method of replacing the label "grass" with "coin" and "dandelion" with "not coin". 52% success rate. 

Until I realized that I was looking at the problem all wrong. Instead of trying to identify something distinguishing about (blurry) coins, I realized I could just focus on the build plate... and then anything I saw that was out-of-focus was a pretty good candidate for scanning. 

The good news is this works for all objects, not just coins. The bad news is, I don't get to unnecessarily throw neural networks at a problem.

Anyway, there were plenty of other issues and fixes, like implementing a better autofocus, making a circle outline search routine, utilizing a circle packing library, detecting false positives, slowing the old homing procedure down, figuring out stacking (kind of), converting a grid scan into one that follows a more efficient circle shape, file sorting, and other fun stuff.

Alright. With that out of the way, here's a video. 

Edit: Check out this awesome photorealistic 3D animation showing how I figure out the outline of the coin!  

Discussions

Paul McClay wrote 01/29/2021 at 08:47 point

That looks very slick.

For the lap around the coin edge - the caption said something like 'just for fun' - does that mean the search for the edge was already done?

  Are you sure? yes | no

Ahron Wayne wrote 01/30/2021 at 20:26 point

Thanks! Not as slick as your videos, of course. I barely know how to click on the "use default transitions" button on Premiere pro... ;) 

Right. At first I wanted to use edge detection to determine the curvature of the coin to find the coin's center and radius. This would have both failed on polygonal coins and required three functions: One to find a coin at all, one to determine when you were at the edge, and another to find the curvature and stuff from that edge  I had problems getting a clean result with coins having edge type patterns on the inside and their true edges being ridged and what not.. 

Instead, the procedure is (picture added above): 

1: Take large steps throughout the build plate to find a place that's not in focus. This is a coin or other object.  You don't actually know where in the coin you are at this point. 

2: Go right in small steps until you come across something in focus; this is a right edge of the coin. 

3: Go back to the place in step 1 and then go left until you find a left edge of the coin. Halfway between this point and the point found in step two is the middle of the coin in the X axis! 

4: Go to that middle point and repeat steps 2 and 3 but going up and down. When you go to the halfway point this time, you will be in the true center of the coin and know the radius. Just add a bit of margin for irregular shaped coins!

And then go around the circle just for fun, or as a sanity check for the user who is watching. I'm sure you can do something with machine vision to use this as a second check, too, but steps 1-4 works pretty good as long as the coins doesn't have, like, a hole in it (shhh!) 

  Are you sure? yes | no