This paper aims to achieve the accurate detection of ball grid array (BGA) solder joints. To this end, the author presented an adaptive template matching method for BGA solder joints based on shape detection. First, the region of interest (ROI) was selected from the X-ray image of the printed circuit board (PCB). Then, an edge template was generated through ROI extraction and threshold segmentation, and the direction vector f the edge template was taken as the prior knowledge. After that, the global traversal search was performed on the image pyramid in the top-down manner, aiming to obtain the potential matching targets. Finally, the edges were adjusted by the least squares method to yield the optimal matching results. The proposed method was proved robust, rapid and accurate through an experiment. The research findings shed new light on the BGA solder joint detection and extraction in various conditions.