Huge variety of medicine cures diseases. But unlabeled pills sometimes confuse people, even causing adverse drug events. This paper introduces a high accuracy automatic pill recognition method based on pill imprint which is a main discriminative factor between different pills. To describe the imprint information clearly, we propose a Two-step Sampling Distance Sets (TSDS) descriptor based on Distance Sets (DS) using a two-step sampling strategy. The two-step sampling strategy applies a resampling according to imprint segmentation, which divides an imprint into separated strokes, fragments and noise points. The TSDS is able to take control over the selection of feature points, aiming to cut down the noise points and unwished fragments generated by imprint extraction which will cause disturbance on recognition. In the aspect of the imprint extraction, we preprocess the pill image by dynamic contrast adjustment to cope with the exposure problem. Modified Stroke Width Transform (MSWT) is used to extract the imprint by detecting the coherent strokes on the pill. Finally, several experimental results have shown 86.01%, rank-1 matching accuracy, and 93.64%, within top 5 ranks, when classifying pills into 2500 categories.