Template matching has many applications in signal processing, image processing, pattern recognition, and video compressing. It can find a desired template in the large reference image by sliding the template window in a pixel-by-pixel basis, computing the degree of similarity between them, and searching position with the largest similarity measurement. It is computationally expensive to search for every possible position of the template window within the larger reference image. When a rotation exists between the template and the reference image, the conventional template matching algorithm described above is no t practical for real-time processing. In this paper, a fast algorithm is proposed to match the rotated template, which consists of two steps: firstly, the possible rotation angle is detected based on the principle orientation, and then the optimal matching position is searched by matching the edge map. Experimental results on a variety of real images have shown the efficacy of the proposed method.