Pipe cracks detection based on machine vision is a new and effective technology. However, it requires high quality of the image. Moreover, images with adequate lighting, evident cracks, clean backgrounds are difficult to obtain in practice. This paper proposes an algorithm for pipe cracks detection in natural background. The algorithm performs filtering, background segmentation, edge detection, threshold segmentation, morphological contour extraction and annotation on the image. This paper also proposes an adaptive threshold segmentation method to obtain the clear crack. By comparing the proposed algorithm with the DEE algorithm, the result shows that the proposed algorithm has certain advantages in experiments. The experiment results show that the algorithm proposed can be used in significant pipe cracks detection.