  Relative Sunspot Number is one of the major parameters for the study of
long-term solar activity. The automatic calculation of the Relative Sunspot
Number is more stable and accurate as compared to manual methods. In this
paper, we propose an algorithm that can detect sunspots and divide them into
groups, to automatically calculate the Relative Sunspot Number. Mathematical
Morphology was adopted to detect sunspots then group them. The dataset used
were the continuum images from SDO/HMI. The process was carried out on the
overall HMI data available on the timespan from January 2022 to May 2023 with a
time cadence of one day. The experimental results indicated that the method
achieved high accuracy of 85.3\%. It was well fitted with the international
Relative Sunspot Number provided by Solar Influences Data Analysis Center
(SIDC) (CC=0.91). We calculated the conversion factor K value of SDO/HMI for
calculating the Relative Sunspots Number(K=1.03).
