A new approach to extraction of affine invariant features of contour image and matching strategy is proposed for shape recognition. Firstly, the centroid distance and azimuth angle of each boundary point are computed. Then, with a prior-defined angle interval, all the points in the neighbor region of the sample point are considered to calculate the average distance for eliminating noise. After that, the centroid distance ratios (CDRs) of any two opposite contour points to the barycenter are achieved as the representation of the shape, which will be invariant to affine transformation. Since the angles of contour points will change non-linearly among affine related images, the CDRs should be resampled and combined sequentially to build one-by-one matching pairs of the corresponding points. The core issue is how to determine the angle positions for sampling, which can be regarded as an optimization problem of path planning. An ant colony optimization (ACO)-based path planning model with some constraints is presented to address this problem. Finally, the Euclidean distance is adopted to evaluate the similarity of shape features in different images. The experimental results demonstrate the efficiency of the proposed method in shape recognition with translation, scaling, rotation and distortion.