UPDATE 2017-09-07: The camera works great even without additional lens, just by shortening the lens holder by about 8mm. Otherwise to much light is blocked of the nozzle at the focal point. I ordered a few more budget USB cameras to see if this is reproducible with others. Stay tuned.
At the moment I'm using a USB microscope, temporarily fixed to the build plate for nozzle offset calibration (more details). It works, but what I really want is a camera permanently attached to the printer to make it easier to check and verify the current offsets and collect data about the long term stability and repeatability of the tool switching system.
The microscope is pretty difficult to integrate, so far I found now way without major downside. First issue is the form factor, it is cylinder about 120mm long and 12mm diameter. Attaching it upright to the build plate would significantly reduce the usable space in Z. Second, the short focal length makes it easy to run the nozzle into the microscope if used horizontally with a mirror (what I'm doing now), as the tip of the nozzle needs to moved below the top of the microscope case. Third the price, it is pretty expensive compared to a simple USB camera and maybe hard to procure as well.
Thankfully, the internet is full of "USB camera to microscope conversion" guides. And what looks promising is using a simple webcam (640x480) and a lens with a short focal distance, harvested from a green laser pointer.
The estimated resolution of 3.1 µm/pixel is slightly better than what I got with the USB microscope (about 5µm/pixel). The estimation is based on the diameter of the circle (pixel) and that it is a 0.4mm nozzle.
The focal distance is about 6-7 mm, enough to keep 2-3 mm safety distance between the camera and the nozzle.
The plan is to keep the camera module in a upwards looking direction permanently attached to the build plate. X and Y offsets are still optically calibrated and Z could be done by eg. touching a micro switch with the nozzle once x and y offsets are known (to ensure the nozzle will hit the switch).
The only downside is the harvested lens, the specs are unknown to me. I ordered a set of smartphone camera lenses (zoom, fish eye, macro and wide field), maybe one of these is usable as well.
For reference, a picture of the camera.