For the problem of lens distortion in computer vision, a robust correction method is proposed. The proposed method optimizes the distortion measurement defined by the imaging properties of space lines to correct distortion. Particle swarm optimization algorithms are used, and the comparison is analyzed between the traditional optimization algorithm, standard particle swarm algorithm and other improved particle swarm algorithms based on different strategies. Experimental results show that the opposition-based particle swarm algorithm with a mutation operator has strong robustness, the performance of particle swarm algorithms is better than the traditional algorithm in the low-level noise situation, and different degrees of lens distortion verify the effectiveness of this method.