Focus variation takes advantage of the limited depth of focus of the lenses and the contrast of the surface in the sharp area of the image. The height information required for a 3D image is obtained by varying the focus position. The optical beam path uses a white light source (LED) and two beam splitters which image the light from the white LED into the focal plane and back onto the camera. In addition, a ring light illuminates flank angles larger than 80°. For the calculation of the measuring data, the contrast curve from the captured images is used in immediate proximity to each other (e.g., 5×5 adjacent pixels). This produces a contrast curve along the focus curve for each pixel and thus the corresponding height information for the measuring point through a Gaussian fit.