1. A method for calibration of an imaging device that includes a sensor and optics for forming an image on the sensor, the method comprising: making a first image quality measurement, based on an output of the sensor, while imaging a first target at a first distance from the device and varying an offset between the optics and the sensor; making a second image quality measurement, based on the output of the sensor, while imaging a second target at a second distance from the device, which is different from the first distance, and varying the offset between the optics and the sensor; and setting a working point of the optics relative to the sensor responsively to the first and second image quality measurements.