ABSTRACT Current machine vision methods for surface measurement rely excessively on feature design to quantify surface morphology and build predictive models, but metric design suffers from human intervention, and data acquisition is heavily dependent on light source environment and shooting angle. This paper uses the Swin-Transformer model to evaluate and classify roughness directly on colour images of milled samples acquired in a convertible image environment. The images used in the experiment are taken in a completely dark environment and in an environment disturbed by light sources, such as LED energy-saving lamps during the day. By using two kinds of lenses and combining custom light sources and ordinary light sources, respectively, and for different angles, it deeply simulates the environment of online inspection of industrial production. The roughness classification results prove that the method has very good robustness to light source environment and shooting angle, avoiding the artificial design and extraction of image features. The accuracy of the validation set of samples can reach 98.94%, while the accuracy of the test set can reach 97.54%. To wrap it up, the method provides an optimised strategy for visual roughness measurement in industrial production.