Jump to content
Brian Enos's Forums... Maku mozo!

Machine vision to sort by headstamp


Recommended Posts

16 minutes ago, Malarky112 said:

I joined as well, I searched earlier this week for a group like that and never found anything, so much appreaciated.

 

Just read thru this thread on headstamp sorting.  I only shoot 9 minor but still sort by headstamp for consistency and its my least favorite chore.  Love reading all your ideas, even if I can't really contribute.

I shoot 9 minor as well but would be nice to cull out the garbage head stamps. I also just like to tinker so after I make the 550 case feeder I'm hoping the sorter will be ready to demo.

Link to post
Share on other sites
  • Replies 123
  • Created
  • Last Reply

Top Posters In This Topic

I've been making some pretty good progress in Fusion360 with a design i like for the sorting.  Inspired by this skittle sorter using gravity to do all the work.  Should be pretty quick if it works right.

https://www.youtube.com/watch?v=wL0VvoQ6kww

 

My plan is to have each gate as a module that you 3d print and assemble and then stack as many on top of each other as headstamps as you want to sort.  Each module having a port coming off of it that you can put a tube on that leads to a bucket.  Practically the number of calibers you can sort would be limited by height if it works right.

 

It'll be another 2-3 weeks before my 3d printer is set up so i can print these out and see how they need to be fixed/improved, because you know it never works right the first time.  I'm sure all the dimensions are wrong brass will jam up, get stuck and will need to be tweaked.

 

I've been working conceptually on the code side of things, have some pretty solid ideas,  but i need to get a good dataset ready for training testing.  The circle light i ordered off of amazon arrived today and it won't work as well ad i'd hoped (too big and not concentrating enough light on the head stamp), so exchanging it for another one.  The more variables that can be eliminated/controlled the better the accuracy will be and the easier it will be to train.

Link to post
Share on other sites
Posted (edited)

More progress has been made.  Made slight tweaks to the mechanical  design a little, might be time consuming to print everything vs using the same concept and making it out of more traditional materials n less time, but i'm sticking with it since I don't have the tools right now to actually do otherwise.. 

 

I made the design as a parametric model with most of the key dimensions being variables in fusion360, so it'll be easy to resize for different calibers by plugging in numbers with minimal cleanup to the model.

 

I hope to have the printer ready and set up by the end of next week to start testing prints that weekend.

 

As far as the code goes, i didn't re-use the existing code that jakgut made and wrote my own.  His is probably superior to mine, however as i'm learning ML I found it easier to take that route than try to edit his.  However I did decide to start with a similar design to his using tensoflow and the keras api.  I did a test model with 3 types of brass, FC, FCNT and WIN.  Winchester was 100% successfully identified,  FC was 100% successfuly identified, however FCNT was sometimes miscategorized as FC.  Hopefully I'll be able to put a little more time into it and make some more progress this weekend.  I'm going to start simple and redo the images I took because once i started working with them i realized that I made some mistakes in taking them.

 

I'm currently running the test code in google colab so I have no idea how it will actually perform on a raspi.

 

Once i have a working prototype i'll post the code and the fusion360 files for the community.

Edited by FingerBlaster
Link to post
Share on other sites

Hope ya'll aren't getting mad that I'm spamming updates, pretty excited about this.

 

I retook all the images yesterday, about 900 images in total.  Worked on the code yesterday and this morning and got a result that I would call a success.

 

It's not perfect, but it works good enough with a low error rate.  Everything above 88% certainty was correctly categorized.  I still had some, but very few, miscategorizations, but they were also assigned a low certainty.   Anything below some certainty threshold, i'm thinking 95%, will get thrown to the reject bin.  I threw it a bunch of headstamps it had not been trained on and it would have failed the certainty test on all of them (under 60%) and put them in the unknown bin.

 

It will need further fine tuning, and I think i know some next steps to improve accuracy.  But i'm mostly done with this part of the code for now.  Once i get the device built, I can easily take a LOT more photos, retrain the model, and probably get some better results.

 

There is still a lot of work to do from a coding perspective, controlling the electronics, getting all the timings right, and a graphical user interface.

 

I was running some numbers on the performance I can expect.  using google colab with gpu acceleration i'm classifying each image in .04 second.  I will need to convert everything to TFlite and see how it runs on a pi.  My hope is .25 sec per image.  If not i'll order a jetson and try that with gpu acceleration.  I'm not there yet.

 

The maximum speed of the mechanical sorting mechanism will be proportional to the number of output bins desired.  I think with 8 output gates, we could do 3-4 pieces per second, almost double that speed if we shrink the main chute lenght to only handle pistol brass, or have less output gates.  

 

 

Link to post
Share on other sites

spamming?  because I am sitting here in stunned silence?

 

your posts take a bit to digest.

 

some thoughts...  build to your satisfaction first.

If you are thinking about those who may follow you,

 

some details I will need re re-read to gather.

 

If you are asking about number of decision gates for brass.

how difficult is it to build them? are they linear?

 

in general I'd think sort to 4 buckets.

once you have this, I'd think 8 and 12 and 16 are logical upgrade modules

 

if the computer is less than a pi and a camera is a USB type that is affordable.

 

I am curious how you are gunna feed 4 cases a second.

 

believe me I am watching...

 

miranda

 

 

Link to post
Share on other sites
Posted (edited)

Oh yes, first and foremost i'm building this for me, but i'm trying to be mindful of what others may want as well as what "future me" may want.  I'm posting publicly because i'm interested in feedback, especially from people with more know how than I have on what may be good and bad ideas, or things i didn't consider.  Also using these posts a journal of sorts helps me to organize my thoughts.

 

I just ordered all the electronics equipment I'll need to get started on this including another pi and Enough motors and servos and controllers to manage 4 output gates.  About $200 in cost, plus the usb camera i'm currently using which was about $80.  The first arducam didn't cut it once i started designing it and figured out a test jig, i went with something with a manual adjustable zoom lens.

 

There will be ways of cutting some cost in the future, but i went for ease of assembly, modularity, and some parts being a little overkill vs cost savings that will result in more work and possibly poor results.  And i really think that someone with good mechanical skills could even do most if not all of this without a 3d printer.  Nothing i'm printing is really that special and i could envision the design working with a little know how around a shop some backyard fabrication

 

The output gate design is totally modular,  they just stack on top of each other with a simple slip fit and a 2 screws.  Picture each gate module as the center section of a peace symbol.  I'm going to start with 2modules .  which should allow me to classify 4 types of brass, plus if no gates fire the brass falls straight down into a 5th bin for "unknown brass".

 

Right now i'm going to start off using a dillon case feeder, That will certainly be a bottle neck that to addressed in the future, and will definitely be the limiting factor in speed despite what the mechanism may be capable of.  I haven't given it much thought yet as it's not a high priority.

 

I was thinking about the project last night and decided my next steps should be to work on the training module.  I'm going to have 2 different training modes.  Supervised and unsupervised.   After I get that done and get stuff printed and assembled i'll work on the servo and gate timing and if everything works get some training going with more types off brass.

 

Supervised: You dump unsorted brass into the case feeder, and as each piece of brass is loaded to have it's picture taken you assign what it is.

 

Unsupervised: you presort brass and drop a couple hundred cases of the same head-stamp in the collator and we just tell it that every peice of brass it sees in this cycle is X.

 

I'm not sure how many photos will really be required to get a good training model.  That's something i'll have to mess with.

 

That's all for now

Edited by FingerBlaster
Link to post
Share on other sites
  • 2 weeks later...
Posted (edited)

Throwing up a quick update.  I got the first prototype of the sorting apparatus printed Monday.  The tolerances and 1 key dimension were off, i had some issues with bridging, will probably need to print with supports or or maybe alter the design to negate the bridging issues. Either way,despite the fact that it needs some refinement, I'm on the right track.  Frankly for a first print prototype I'm really happy with how it came out.  Hopefully i'll have some time to update the design this weekend and try again.

Edited by FingerBlaster
Link to post
Share on other sites

I've printed 2 more iterations of the sorting module.  So the 3rd one assembled and worked after adding in 3d printed supports!  There are still a couple issues i've identified that I will have to work on, but it's functional.

 

Next step is the module that interfaces with a case feeder and both controls the flow of brass and allows to take a picture.  I have the first version printed, that on my table top seems to work, i need to get some material from the hardware store.  For now Im going to use a series of wires/pins to control the flow of brass, but i'm kind of tempted to try something similar to the jaws on a Forster coax to grab the brass behind the rim for the final stage where it takes the picture.

Link to post
Share on other sites

Will the wires/pins be run off servos? You said Raspberry pi so tensorflow and python?  Using the pi camera or a usb endoscope?  I'm sure quite a few folks here would be willing to help test/ gather data and can print your test setup if you want to start a google drive to share your files. 

Link to post
Share on other sites
Posted (edited)

Yes, the wires/pins are moved by servos. 

 

The gates for the sorting mechanism are run off of cheap DC 130 style hobby motors.  I'm not sure how the hobby motors will hold out long term since they need voltage applied to keep closed (closed means no brass is going out of the gate), aka they're stalling out and generating heat...  Right now (v3) they only swing up to about 80 degrees so they want to fall open at rest (to divert brass into the output tube), so and need more voltage than i'd like (about 50% pwm) to keep them closed..  The next iteration of the sorting assembly will allow them to swing more towards 100 Degrees (past 90), so they should need no voltage to keep closed, but i would still apply like 10% pwm for good measure.  I don't want to use here servos on the gates, to keep costs lower, plus this is simpler to implement.  You Just press fit the shaft of the DC motor in the door.  Probably use a dab of glue for good measure on final assembly.  I"ve tested this with 223 and 9mm so far and it worked fine Playing around with some basic code snippets to make it go left door or right door.  It should be fine for .45, but i haven't tested any yet.

 

additional components so far are a pi 4 with a heatsink, a servo sheild, and a dc motor sheild from adafruit wired up using ribbon cables. 

 

Once i clean up a few more things i'll post the files, the code right now is nowhere near done, all i have is a working TF model, and some simple snippets i wrote to test the servo and motor control.

 

Here's a picture of the various iterations, but you can see the nesting idea to expand it pretty easily to as many output gates as you want to print....The benefit over the hasgrok design is you don't have to wait for a pipe to swing around, the downside is, it's is a lot of 3d printer time to print all these parts.    The version on the bottom with the mounted motor is the most recent.  The 3d printer supports were still on the bottom part when i took the pic.

 

The idea is to cable clamp some flexible tubing on the end of these output tubes.

 

Edited by FingerBlaster
screen shot didn't work
Link to post
Share on other sites

apparently I can't screen shot, trying again 

 

12 hours ago, assnolax said:

Will the wires/pins be run off servos? You said Raspberry pi so tensorflow and python?  Using the pi camera or a usb endoscope?  I'm sure quite a few folks here would be willing to help test/ gather data and can print your test setup if you want to start a google drive to share your files. 

 Also i didn't answer your camera question.  And endoscope could be a good idea, but right now i'm using a usbcam i got off amazon with a variable zoom lens and a manual focus that seems to work well.  Trying to zoom in on that headstamp as much as possible and make sure it's crisp/clear.

 

20210321_220941.jpg

Link to post
Share on other sites

I'll volunteer as a 3d printer/tester if you need.

 

I have an Ender pro, and print a lot of stuff.  I'd be happy to help out in printing different versions or parts if you need.

 

This is an AMAZING project!  Fingerblaster are you posting this anywhere else?

 

Link to post
Share on other sites
Posted (edited)
On 3/24/2021 at 6:02 PM, rmantoo said:

I'll volunteer as a 3d printer/tester if you need.

 

I have an Ender pro, and print a lot of stuff.  I'd be happy to help out in printing different versions or parts if you need.

 

This is an AMAZING project!  Fingerblaster are you posting this anywhere else?

 

 

I haven't posted this anywhere else yet.  Once i get a prototype working i'll make a post on arfcom and a few other popular places.  I also need to come up with a name for it.  

 

Didn't make any progress this week, too busy with life, but going to put another day into it this weekend.  My goal is to get the module that takes brass from the case feeder and presents it 1 by 1 to the camera timed properly.  Get the camera mounted, and work on the code a bit for image capture and classification.

 

 

 

 

On 3/24/2021 at 6:20 PM, CClassForLife said:

I wonder how accurate sorting by mass is. That way, you can have some sort of pre-sort prior to the vision models.

 

I don't know, that's a good question, but i have another project I want to do to sort bullets by weight.  I was thinking of utilizing my mr bullet feeder and a 3d printable robotic arm in combination with my lab scale that has a serial output.

Edited by FingerBlaster
Link to post
Share on other sites

Made very little progress this weekend, got everything assembled, mounted and starting to try and figure out the timing of the brass control. I didn't get very far, but i was able to get it to control the flow of brass, just not very well.  I was also getting some unpredictable behavior from the servos that I have to look into.  At times they would just randomly rotate to extreme angles and destroy the bailing wire i was using.

 

Unfortunately I spent most of the weekend with one of my cat's at the veterinary emergency hospital, still not sure what's going on with her. 

Link to post
Share on other sites
Posted (edited)

I think i figured out my random servo movement issue.  Servos i'm using need 5V logic, but the controller i'm using outputs 3.3V logic.  Going to order new servos that use 3.3V logic input.

 

I changed the design of assembly that interfaces with the casefeeder.  The entire assembly will be caliber specific instead of trying to make it universal.  Right now the focus is 9mm, since i have buckets full of it.  This is easier for now to design and get to a prototype i'm ready to share, eventually i'll try to do something more universal, i have a couple ideas. 

 

I also had too many issues with getting the servos and wire at the right angle, so I 3d modeled a mounting plate for the servos to align them properly with the tube, instead of just freestyling it withy plywood...  First test seemed to work great, until the whole thing grenaded because the servos moved WAYYY further than designed and broke all the 3d printed mounts.

 

I'm going to try a super small LED light ring,one of the small a neopixel type devices.  Might be too small, but going to try the one that's about 1.5" OD and 1" ID.

Edited by FingerBlaster
Link to post
Share on other sites
Posted (edited)

One more update for today, this is the current iteration of assembly that interfaces with the case feeder, just finished the print and assembled it to take a pic, but i'm hesitant to run it until i fix the servo issue.  Going to either use a converter to step up the logic signal to 5v or get new servos.  Hoping that takes care of the issue.

 

Made a few small changes from the last version of this i printed, but the last version worked on the bench until 2 of the servos went haywire and snapped their mounts.  I was able to continuously feed brass into it, and have it spit it out 1 peice at a time.  Once i fix the servo issue, i think it's ready to mount up along with a camera and start taking pictures.

 

I'm not sure if the 18ga galvanized steel bailing wire i'm using is the best tool for the job, but it seems to be working and was readily available at home depot.

20210404_223723 (2).jpg

20210404_224710 (2).jpg

Edited by FingerBlaster
Link to post
Share on other sites
Posted (edited)

Worked around the issue of the servos going nuts and breaking all the mounts, still working on the timing, running it pretty slow right now for testing purposes.  

4 hours ago, assnolax said:

Looks good.  Does that gate mount at an angle so the cases don't drop and hit the camera or how are you planning to take the pictures? 

Right now the plan is to mount the gate at an angle to take the pics, then have a deflector to have the brass go straight down.  I am concerned if the brass is going at an angle that things will run a little bit slower than if the brass was straight vertical.  Taking pictures that aren't perpendicular to the brass probably won't be a huge issue, but i'll have to test it eventually

 

 

 

Edited by FingerBlaster
Link to post
Share on other sites

I’m glad to see your still after it.  I don’t really know a lot about the code side of things for the project but did gather all the components to put this one together to learn something but of course haven’t.

 

https://coral.ai/projects/teachable-machine/#project-summary


Would be interested knowing how you setup the image capture/classification on yours?

Link to post
Share on other sites
6 hours ago, jmorris said:

I’m glad to see your still after it.  I don’t really know a lot about the code side of things for the project but did gather all the components to put this one together to learn something but of course haven’t.

 

https://coral.ai/projects/teachable-machine/#project-summary


Would be interested knowing how you setup the image capture/classification on yours?

 

So right now this is all conceptual.  I have some core components I've tried that worked on a bench as isolated trials.  For Image capture, i'm using a usb web cam and the plan is to use opencv to capture a cropped image.  I just need to pop over to the hardware store to grab a 1/4-20 machine screw to mount the camera so i can start capturing images.

 

I have 2 ideas on how to do image classification right now. 

  1. Train a neural net using the tensorflow python library
  2. use opencv to do a polar unwrap (ie, unwrap the text on the headstamp so it's in a straightish line) and then use OCR to identify the text on the headstamp.

The tensorflow idea is my top choice.  It'll be more computationally taxing, but it has more potential.  identify nickel plated brass? and  small vs large primer 45.  I do have a working basic tensorflow model that had a promising accuracy rate during my trial.

Link to post
Share on other sites
Posted (edited)

put a little work in on the sorting mechanism.  Still not done.  I ran it a little harder today and ran into a few small issues,  Going to make a few dimensional tweaks and hope that they're sufficient, some of my tolerance are too tight for what my 3d printer can produce, and i'm not providing the motor shaft enough surface area to interface with the flappy door and the door popped off..

 

Here are 2 videos

 

Showing how the flappy doors work

 

 

 

 

 

 

 

putting in 3 pieces of brass, 1 to go left, one to go straight down, and one to go right.

 

 

 

 

Edited by FingerBlaster
Link to post
Share on other sites

FingerBlaster,

 

Just registered to let you know this is one of the most awesome things I have eever seen someone do! Are you planing to throw a build plan for this sorter out, so everyone can build one? How can a standard bloke like me help you out? 

One thought I had for your problem of having to angle the chute to take the photos: Why not yust put one of your flappy doors right at the start uner the case and open it every time the camera took a picture to divert the case away from the cam and then close again to give view to the next case?

 

Best Regards

Link to post
Share on other sites
5 minutes ago, Hansimania said:

FingerBlaster,

 

Just registered to let you know this is one of the most awesome things I have eever seen someone do! Are you planing to throw a build plan for this sorter out, so everyone can build one? How can a standard bloke like me help you out? 

One thought I had for your problem of having to angle the chute to take the photos: Why not yust put one of your flappy doors right at the start uner the case and open it every time the camera took a picture to divert the case away from the cam and then close again to give view to the next case?

 

Best Regards

 

Thanks!  My first time taking on anything like this and learning multiple skills as I go.

 

I'll include a basic walk through of setting it up once i get it working.  Once I get a working prototype, all the source code and cad files will be shared.   Once i put it out there, anyone can do with it as they wish. Hopefully some will help to improve the design and provide feedback back to me.  I'm more than happy to collaborate with others.  I really have no idea what i'm doing, and there are plenty of people out there much smarter than me that probably have great ideas.  To start though I really want to get a fully working prototype before i start sharing cad files and source code.  Just as a personal goal to get this going.

 

That's not a bad idea at all, thank you.  It hadn't crossed my mind, and it was right in front of my nose!  

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...