In order to solve the automatic counting problem of steels, this paper has proposed a image recognition method based on mathematical morphology. It captured the tiling steels image by CCD firstly. Then, the image is sent to computer and preprocessed by using denoising operation and binary segmentation et al.. Finally, the binary image was thinned using hit and miss transform which based on morphology, and the number of steels was obtained. Experimental results showed that this method is convenient and can enhance the accuracy of the steels automatic counting.