In the scene of pig thermal infrared temperature measurement, the temperature of the ear root is closest to the body temperature of the pig. In order to address the problem of inaccurate positioning of the ear root area in the thermal infrared image of the pig under motion due to changes in the pig's head posture and single pixel information, based on the research of automatic inspection and temperature measurement robots, it is proposed to establish an ear root area detection model through visible light images, and map the detection results of the model to the thermal infrared image with the same contour information after registration, achieve accurate localization of the pig ear root area in the thermal infrared image. This algorithm achieves the detection of key points in pig heads in visible light images by improving the YOLOv8 network. By analyzing the position information of key points in pig heads through light shadow projection and dynamic coordinate system adjustment methods, the pig head posture and adjustment angle are obtained. The visible light image of the pig's head after angle adjustment is redivided into ear root regions to correct the impact of pig movement on ear root region division. By using AKAZE and GMA algorithms to extract and register features from heterogeneous images, visible and thermal infrared images with the same contour and scale information are obtained. Finally, the detection results of the ear root region in the visible light image are mapped to the thermal infrared image. Through testing on 2650 datasets, the accuracy of key point and category detection was 99%, the number of key point detection model parameters decreased by 41%, and the registration error was only 1.6%. The accuracy of ear root localization in heterogeneous images reached over 99%, making it easy to achieve accurate temperature measurement.