The changes of the seafloor environment caused by natural disasters and human activities greatly shorten the life span of the subsea optical cable. It is urgent to carry out routine inspection and maintenance for subsea cables. In this paper, an automatic inspection system to address these problems is proposed where the localization and inspection mission is conducted by an autonomous underwater vehicle (AUV) carrying with a tri-axial electromagnetic sensor. Firstly, the framework of the inspection system is presented, and the function of each subsystem is introduced briefly. Secondly, the inspection algorithms are designed which include localization algorithm, online path planning and path following control algorithms. A dedicated particle swarm optimization (PSO) algorithm is adopted to localize the subsea optical cable. In addition, the swath path is planned online so that the AUV can detect the cable in the repeatedly crossing manner. With the planned of swath path, the cable detection is elaborately constructed as a classic path following control problem, such that the AUV can track the planned path and inspect the optical cable automatically. Finally, the numerical simulation results are provided to validate the effectiveness and feasibility of the automatic inspection system.