Intelligent recognition of Martian surface terrain is of great significance to autonomous exploration of Mars rovers. Feature extraction methods for Martian terrain images are currently mainly divided into two categories: traditional shallow visual feature extraction and deep feature extraction based on supervised learning. Loss of image information and the need for a large amount of labeled data are key issues to be addressed. A method for Martian terrain feature recognition based on unsupervised contrastive learning is proposed. By establishing an image dictionary dataset, two sets of neural networks, "query" and "encoding", are used to compare a single image with other images in the "dictionary" dataset, and the network is trained using the similarity functional as the loss function, thereby realizing feature recognition of Martian terrain images. The proposed method also has the ability to recognize new types of terrain images outside the training dataset, and has outstanding superiority in subsequent recognition and classification. Computer simulation verification shows that the recognition accuracy of the proposed method is and the 85.4%recognition accuracy of new types of terrain images is 84.5%.