A new template matching algorithm was proposed to solve the problem of tracking targets with attitudes changing violently. It applied k-means algorithm to make multiple clustering based on the optimal number of clusters which was calculated with pattern classification criteria. The features vector for matching tracking by combining the entropy vector with the distance vector, both of which were calculated according to the clustering result. It adopted a simple similarity criterion to realize matching, while used a multimode updating algorithm to update real-time reference template. Experimental results certificate the new algorithm is able to calculate the number of clusters adaptively. Additionally, the new algorithm is able to track geometrically changing targets precisely and stably.