In order to achieve a better recovery precision, this paper introduces an algorithm for shape from focus based on zero-phase filer. The principles and design of this filter were explained. To filter the evaluation function of window sequence image by a zero-phase filter, it can keep the position of each dimensional data point unchanged while eliminating noise, so as to get a more accurate focusing position. The peak value position of the evaluation function is got by computing the extreme of the least square quadratic curve. At last using the cubic surface interpolation, all the depth of the measurement object is obtained. The experiment shows that the method of this paper is better than the traditional method at flatness.