A distance measuring apparatus according to the present invention includes an image input unit configured to input a plurality of viewpoint images obtained by capturing a subject from different viewpoints, an obtaining unit configured to obtain, regarding each of a plurality of distances of interest, a piece of calibration data corresponding to each of the plurality of distances of interest from a plurality of pieces of calibration data for matching two-dimensional coordinates of the viewpoint images and three-dimensional coordinates in a real space, an image correcting unit configured to correct, for each of the distances of interest, the plurality of viewpoint images based on each of the pieces of calibration data, a parallax calculation unit configured to calculate, for each of the distances of interest, a parallax between the plurality of corrected viewpoint images, a comparing unit configured to compare the corrected viewpoint images over the plurality of distances of interest to specify a piece of optimum calibration data from the plurality of pieces of calibration data, a distance calculation unit configured to calculate a subject distance based on the parallax, and an output unit configured to output, as a distance measurement result, the subject distance calculated from the parallax between the corrected viewpoint images with the piece of optimum calibration data.
展开▼