How do I quickly count pieces? I have LEGO pieces divided into partitions in something like a tackle box, each of which indicates how many pieces are supposed to be in that partition.  With few exceptions, each partition only holds one type of part, like this:



One slot might have, say, 5 axles, and another might have 82 friction pegs.

How can I quickly verify if there are the right number of pieces?

I've been thinking that if I went a partition at a time, I could take all the pieces out, spread them over a surface, shine them under a webcam, and have a computer or phone spit out a count for me.  Perhaps there is a mechanical way to do this, or maybe using a (really accurate?) scale would do it.

Any recommendations?
Tackle boxes are very common for storing Lego, I use them myself. Unfortunately I've not found or seen a good way to count the pieces that are in them. The easy way is to take everything out of them, which I suspect is what you're trying to avoid. 

One trick with that is to get a piece of cardboard (or plywood) twice the size of the tackle box, cut a hole in the centre, place it over the tackle box with the hole over a compartment, then invert it with your hand under the hole! With a little wiggling you'll end up with only the pieces from that compartment in your hand. Or, if you lose your grip, everything all over the floor. But when you have a lot of compartments or a lot of pieces, that method is much faster than picking pieces out of compartments by hand. Especially small tiles.

Using a counting scale is a very common way to count small items like this. Lego weigh parts, bags and sets repeatedly during manufacture as part of their quality control process - that's one big reason why so few sets have missing pieces.

The problem you have is that while it's easy to weigh the whole tackle box, that doesn't give you much information about what exactly is missing. I suspect that the uncertainty in the weight (from the variable weight of grime and water on the box) will be about the same as the weight of the smaller pieces.

Doing a search for "image analysis counting" I found this NIH paper that suggests that it's possible to do what you're looking for. I suspect the main problem will be getting images that show the entirity of each well in the tackle box, but you may find that just taking a photo from as far away as possible works. Then you have to set up and calibrate the software. I doubt it will work with irregular pieces or where you can't see every item, though. But it's worth trying just to reduce the overall effort.

Worth doing if you're going to be counting the contents a lot of times. Or you're interested in the problem.