Current binary defocus technology mainly focuses on fringe generation suitable for specific frequencies without considering fringe adaptability for defocus-degree variation, which decreases the measuring accuracy for this scenario. To achieve a high-quality measurement, we propose a robust binary fringe generation method to minimize the phase error caused by changes in defocus and the random error in measurement. In the method, we establish a complete phase error model and construct a novel objective function, to the best of our knowledge, to optimize the binarization threshold of each pixel. Through derivation of the threshold gradient calculation formula, we quickly obtain optimal binary fringes that can adapt to different fringe pitches and various degrees of defocus. The experimental results verify that the proposed method can generate robust binary fringes adaptive to different fringe pitches and defocus degree variation, and thus achieve high-quality 3D measurements.