Due to the limitations of welding complexity and machining error, traditional manual teaching and offline programming are not intelligent enough and have weak adaptability to workpiece. At present, the 2D perception visual welding guidance programming method is commonly used which cannot accurately locate and model the complicated 3D spatial curve welding seam. The 2D perception method can hardly meet the requirements of welding process. In this paper, a welding seam perception method based on a line structure light sensor was proposed, which optimizes the generation of the weld seam trajectory, and builds a highly adaptable intelligent guidance programming system for welding robots. Firstly, 3D modeling perception of welding parts is realized through eye-in-hand system of robot, which solves the problem that offline programming system cannot be applied when the welding model is not precise enough or partly miss. Secondly, aiming at solving extraction problem of common types of 3D space curve welding seam, corresponding types of weld extraction algorithms are proposed according to the characteristics of different types of welds under the general process of weld extraction. These methods not only can directly extract the weld from the ordered point cloud with high precision and resolution, but also are less affected by the welding environment, which solve the problem of low perception accuracy of complex curved welds in 3D space. Then, on the basis of welding seam extraction, NURBS curves are used to realize the optimal generation of weld trajectory. Finally, the feasibility and effectiveness of all the methods proposed in this paper are verified by a large number of experiments.