For the sake of realizing the safety detection of natural gas and petroleum pipeline welds, this paper designs a ferromagnetic pipeline weld magnetic flux leakage detector based on the calculation of the magnetic circuit of the detection probe, with the magnetization direction perpendicular to the traveling direction. The traditional pipeline magnetic flux leakage detection device uses a detection system mode in which the magnetization direction is parallel to the direction of travel. However, due to the structural characteristics of the weld, the traditional detection system mode is not applicable. Since the weld magnetic flux leakage detector needs to travel along the direction of the weld, the detector designed in this paper rotates the magnetizer 90 degrees along the direction of the weld seam so that the magnetization direction is perpendicular to the direction of travel, breaking through the technical barrier that make traditional magnetic flux leakage detection devices unsuitable for weld detection. The detection device includes a magnetizing structure, a data sampling device, and a driving and traveling device. The magnetic flux leakage signal collected by the detector is converted into a digital image in the form of a grayscale matrix. Using mathematical morphology and chain code algorithms in image processing technology, a pipeline weld defect inversion software system is developed, and a preliminary quantitative analysis of pipeline weld defects is achieved. The application of this technology enables the inspection and protection of oil and gas pipeline welds throughout their life cycle, broadens the scope of existing inspection objects, and is of great safety significance for ensuring national public security.