With the development of the digital projection technology, the three-dimensional (3D) measurement technology based on fringe projection is being widely used in many fields. However, in most application environments, there are various periodic light sources in most application environments, which cause interference to the imaging process of grating projection. Nonlinear errors are introduced in the phase extraction process, thus affecting the accuracy of 3D reconstruction. To solve this problem, the interference factors of the ambient light source are analyzed in the time domain, and the light source model is established by collecting and analyzing the images affected by the periodic ambient light. For this reason, a high-precision phase compensation algorithm is proposed. Experiments illustrate that the proposed algorithm can effectively suppress the phase nonlinear error caused by the environmental light sources.