Structured-light profilometry is a powerful tool to reconstruct the three-dimensional (3D) profile of an object. Accurate profile acquisition is often hindered by not only the nonlinear response (i.e., gamma effect) of electronic devices but also the projection-imaging distortion of lens used in the system. In this paper, a flexible 3D profile reconstruction method based on a nonlinear iterative optimization is proposed to correct the errors caused by the lens distortion. It can be easily extended to measurements for which a more complex projection-imaging distortion model is required. Experimental work shows that the root-mean-square (RMS) error is reduced by eight times and highly accurate results with errors of less than 1‰ can be achieved by the proposed method.