An image processing apparatus comprising: an imaging unit including a lens unit, incorporating a focus lens, and an imaging device and configured to, in capturing of an image of a subject, capture as a captured image a first image of the subject having a first focal range during first exposure time, and capture as a captured image a second image of the subject having a second focal range different from the first focal range during second exposure time; a focal range control unit configured to change a focal position of the first image of the subject captured by said imaging unit within the first focal range of the first image and a focal position of the second image of the subject within the second focal range of the second image by controlling movement of the imaging device or the focus lens in said imaging unit; a reference image generation unit configured to generate a reference image from the first image and the second image captured by said imaging unit; and a distance measurement unit configured to measure a distance from said imaging unit to the subject with a Depth from Defocus distance measuring technique, from a degree of blur in the first image and the second image captured by said imaging unit and using said reference image; wherein said focal range control unit is configured to change the focal position of the image of the subject captured by said imaging unit from a first focal position to a second focal position by moving the imaging device or the focus lens in said imaging unit during the first exposure time, so that said imaging unit captures the first image having the first focal range during the first exposure time, and said focal range control unit is configured to change the focal position of the image of the subject captured by said imaging unit from a third focal position to a fourth focal position by moving the imaging device or the focus lens in said imaging unit during the second exposure time, so that said imaging unit captures the second image having the second focal range during the second exposure time. an imaging unit including a lens unit, incorporating a focus lens, and an imaging device and configured to, in capturing of an image of a subject, capture as a captured image a first image of the subject having a first focal range during first exposure time, and capture as a captured image a second image of the subject having a second focal range different from the first focal range during second exposure time; a focal range control unit configured to change a focal position of the first image of the subject captured by said imaging unit within the first focal range of the first image and a focal position of the second image of the subject within the second focal range of the second image by controlling movement of the imaging device or the focus lens in said imaging unit; a reference image generation unit configured to generate a reference image from the first image and the second image captured by said imaging unit; and a distance measurement unit configured to measure a distance from said imaging unit to the subject with a Depth from Defocus distance measuring technique, from a degree of blur in the first image and the second image captured by said imaging unit and using said reference image; wherein said focal range control unit is configured to change the focal position of the image of the subject captured by said imaging unit from a first focal position to a second focal position by moving the imaging device or the focus lens in said imaging unit during the first exposure time, so that said imaging unit captures the first image having the first focal range during the first exposure time, and said focal range control unit is configured to change the focal position of the image of the subject captured by said imaging unit from a third focal position to a fourth focal position by moving the imaging device or the focus lens in said imaging unit during the second exposure time, so that said imaging unit captures the second image having the second focal range during the second exposure time.