Two-dimensional finite element mesh generation algorithm for electromagnetic field calculation is proposed in this paper to improve the efficiency and accuracy of electromagnetic calculation. An image boundary extraction algorithm is developed to map the image on the geometric domain. Identification algorithm for the location of nodes in polygon area is proposed to determine the state of the node. To promote the average quality of the mesh and the efficiency of mesh generation, a novel force-based mesh smoothing algorithm is proposed. One test case and a typical electromagnetic calculation are used to testify the effectiveness and efficiency of the proposed algorithm. The results demonstrate that the proposed algorithm can produce a high-quality mesh with less iteration.