Abstract:Hericium erinaceus is a traditional edible and medicinal fungus with high nutritional and economic value, and its commercial circulation requires rapid, objective, and stable quality evaluation. However, manual sensory grading is easily affected by evaluator experience, illumination conditions, and fatigue, which leads to low efficiency and inconsistent judgment results in large-scale production scenarios. Aiming to address these problems, an intelligent quality detection method for H. erinaceus based on machine vision and deep learning was proposed. Firstly, images of normal and defective samples were collected under practical acquisition conditions, and preprocessing operations were used to reduce background interference and improve the visibility of surface texture features. A multi-scale optimized watershed segmentation algorithm was then constructed to extract the target region accurately, suppress over-segmentation in complex backgrounds, and provide reliable input for subsequent feature learning. On this basis, image enhancement and data augmentation strategies were introduced to enrich sample diversity, alleviate the influence of limited datasets, and strengthen the generalization ability of the model. In the classification stage, a Swin Transformer Tiny network was adopted to combine local window attention with shifted window attention, so that both fine-grained local texture information and broader contextual relationships can be effectively captured. The model was used to discriminate between normal and defective H. erinaceus samples, and its performance was compared with several mainstream deep learning models under the same experimental conditions. Experimental results showed that the proposed method achieved a classification accuracy of 94. 3% on real-world collected images, outperforming ResNet-18, EfficientNet, DilateFormer, and MambaVision by 3. 5, 2. 2, 1. 5, and 1. 2 percentage points, respectively. The results indicated that the combination of accurate segmentation and attention-based feature extraction can improve the reliability of H. erinaceus quality detection. The proposed system demonstrated strong engineering practicability and deployment potential, providing a feasible technical route for intelligent quality inspection of structurally complex edible fungi and supporting the standardization and intelligent development of the edible and medicinal fungus industry.