Through study of classical defect recognition algorithm, an improved dynamic threshold was proposed. The algorithm adopted gray scale characteristics over the global and local combination for image detection. Experimental results showed that the algorithm can fast detect all types of defect location and size with accuracy of 98%, and efficiency is 26% higher than traditional threshold algorithm. The algorithm is stable and reliable operation in high speed production environment and can meet requirements of online quality detection.