Aiming at the practical problems of low detection accuracy and low detection speed for the detection of power insulators and insulator defects in a complex environmental context, a method is proposed to improve the YOLOv4 algorithm for the detection of power insulator images and insulators with defects. By making a dataset of electric power insulators and insulators with defects, the K-means algorithm is used to cluster the electric power insulator image samples to obtain different sizes of prior box parameters; then a weighting factor is introduced by improving the balanced cross-entropy to increase the contribution degree of the loss function; finally, the depth of the network is deepened by adding convolution layers before and after the spatial pyramidal pooling structure. The experimental results show that the single detection time of the improved model is 3.27S, and the average detection accuracy for insulator defects is improved by 24.36% compared with the original YOLOv4 algorithm. Also the value of the mean average accuracy on the test set by the improved YOLOv4 algorithm is 84.05%, which is 17.83% better than the original YOLOv4 algorithm, fully demonstrating the ability to locate and identify the defects existing in power insulator images well.