A method for measuring a distance between an object and an optical sensor, comprising:
- capturing an image of a visible distance region via temporally coordinated control of an illumination device and the optical sensor, wherein a spatial position of the visible distance region in an observation region of the optical sensor is specified by the temporally coordinated control;
- determining in the captured image:
- a start image line as a beginning of the visible distance region,
- an end image line as an end of the visible distance region, and
- a base point image line as an image line with a shortest distance to the start image line in which the object can be detected;
- and
- ascertaining the distance between the object and the optical sensor as the sum of:
- the beginning of the visible distance region and the product of:
- a distance region width and the ratio of:
- a base point distance to a distance region image width, wherein the distance region width is from the end of the visible distance region to the beginning of the visible distance region, wherein the base point distance is from the base point image line to the start image line, and wherein the distance region image width is from end image line to the start image line.