A new Shack-Hartmann(S-H) spot detection algorithm was proposed in this paper for finding the location coordinates of S-H reference wavefront spot in dependent of lenslet shapes, rotational alignment error of lenslet, reference laser beam shape. It consists of five main processing module: 1) Parameter setting, 2) Noise measurement & compensation, 3) Segmentation, 4) Coarse localization, 5) Fine localization. Through some simulated experiments, the proposed algorithm showed that it could robustly detect a variety of S-H spot patterns e.g. rectangular shape, triangular shape, sandglass shape, X-shape, center-void shape, rotated rectangular shape. The detection precision of the proposed algorithm was measured with the root squared sum of the estimated coordinates difference with values less than 10-4 pixel till signal to noise ratio S/N=3. It is firstly intended for application of infrared S-H sensor but can be adopted in visible S-H sensor.