I have made a filament width measuring instrument using TSL1401CL (this is an inexpensive optical linear sensor array).
I think there was also a commercial product.
Something like this:
Since In my project, I attached a lens to improve the resolution, it took some time to adjust the optical device, but finally got the resolution was about 0.02 mm.
EDIT:
If you are interested, you can also buy the TSL1401R sensor itself at a low price.
Since it is a DIP package, it can also be used on a breadboard.
It can be used at 5V and can be easily interfaced with Arduino.
If you don't use optics, just pinch it between two rollers and measure the spacing.
It provides a more reliable measurement.
You can hack measurements from many cheap Chinese digital calipers.