In a digital stripe projection structured light system, the nonlinear phase error is generated by the gamma effect of both the projector, camera, and other electronic devices. One of the existing nonlinear correction methods is active correction by projecting ideal fringes as far as possible, and the other is passive compensation after capturing aberrant fringes. The former has higher accuracy but needs to capture a large number of fringe patterns, while the latter does not need many fringe patterns, but is not only greatly affected by random noise and out-of-focus effects, but also has poor accuracy. In this paper, an optimal algorithm for eliminating nonlinear error based on global statistical phase feature function (GSPF) is proposed. The phase distribution can be estimated from the difference between the global cumulative distribution function and the normalized cumulative distribution function. For an ideal fringe pattern without nonlinear error and a fringe pattern with nonlinear error, the region wrapped by the x-axis normalized cumulative distribution function is much smaller than the region wrapped by the x-axis global cumulative distribution function, and the larger the nonlinear error is, the larger the difference between the two is. Therefore, the global statistical phase feature function can be used for nonlinear error correction. Then the optimal nonlinear error correction is performed based on the minimum difference between the compensated phase entropy and the ideal phase entropy. The method does not require too many steps of phase-shifting, and only three fringe patterns are needed to realize accurate and robust correction. Experimental results show that the method is fast, highly accurate and robust. Using this technique, high accuracy measurements can be achieved with the traditional three-step phase-shifting algorithm.