This invention discloses a machine vision-based method for measuring the trajectory of an electromagnetic needle selector. The method includes: acquiring a continuous image sequence of the needle selector during operation using a high-speed industrial camera; adaptively cropping the Region of Interest (ROI) using sparse optical flow fusion and image differencing; performing Otsu thresholding, connected component extraction, minimum bounding rectangle fitting, and gray-level centroid calculation on each needle selector region within the ROI to extract feature points of multiple needle selectors; constructing an inter-frame feature matching and trajectory reconstruction algorithm to continuously identify and sort the temporal trajectory of each needle selector; and finally outputting a complete and smooth multi-target motion trajectory. Compared to traditional single-point measurement methods, this method has advantages such as non-contact operation, high concurrency, and high precision, and is suitable for applications such as electromagnetic needle selector status assessment, fault detection, and performance analysis.