In the realms of affordability for most people, the Schneider Componon (-S) 50mm lens, mounted backwards will give you excellent results, in a small form factor at a reasonable price.
To get better results is certainly possible, but you will be paying 10x as much.
The 50 will work from Regular8 up to 35mm and is very sharp, with great colour rendition. I typically run it at f4-f7 or so, once you get past f11 we find we get softness due to diffraction softening.
As for a machine vision camera, I'd recommend one of the Point Grey Research USB3 or Gig-E cameras. We tested nearly 100 cameras and the PGR ones have less noise and better dynamic range than other manufacturers, even when the sensor was identical. They seem to put a lot of effort into the electronics design, to keep the noise low. The PGR cameras had siginificantly better results than the Imaging Source cameras for example, and we can only put this down to better design on the electronics side.
Also the internal processing seems to be better on the PGR cameras. The trigger is also more reliable than most other brands we tested. In other words, they just worked and gave good results, whereas the others had image quality and other issues (some had ghosting, tearing, dropped frames, more noise, interference problems, heat issues etc.) or were just flaky for use where dropping a frame is a big problem.
They have an affordable line with the Chameleon and Blackfly range, and larger sensors and resolution in the more expensive Grasshopper range.
Make sure you pick up the interface/trigger cable and tripod mount-plate when ordering the cameras as you will most certainly want those.
There are cheap webcams, and cheap sensors out there, but most are more hassle than they are worth, and you end up spending more as you buy one, then end up buying something else, and then a third when you hit it's limitations and so on.
Look for at least 3.4 micron pixel size if you want decent response in the dark areas, ideally 5 micron or larger. Anything under 3 microns will give poor dynamic range, regardless of what the marketing material might say, the pixels are just not large enough to capture enough photons.