The color-ring resistor is one of the most commonly used electronic components in Printed Circuit Board (PCB). It is featured by sequential color rings, which often brings assembling errors, however. Manual detection of color-ring resistors has low efficiency and high false detection rate. Traditional image-based automatic detection methods have difficulties in dealing with PCB images under various illuminations, imaging distance and views. To solve this problem, an automatic detection and localization method for PCB color-ring resistor is proposed based on Convolution Neural Network (CNN). Firstly, the encoder-decoder CNN model is established and trained using weighted cross-entropy loss function. With CNN, color-ring resistors are segmented from PCB images with complex illumination and scenes. Secondly, each color-ring resistor is localized using minimum area bounding rectangle, and its position is adjusted to the vertical direction by affine transformation. Finally, the localization of color rings on the resistor is achieved by Gaussian template matching. The proposed method is tested and verified by 1270 PCB images, and the result is compared with that of the traditional method (method based on geometric contour, and method based on template matching). It is shown that the proposed method has obvious advantages in performance indices, including recall rate, precision, and intersection of unions, which can meet the requirements of practical applications.