Polarization-based pencil surface defect detection and eraser length measurement system and method
Patent Information
- Application Number
- CN202611165345.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-03
- Publication Date
- 2026-09-29
AI Technical Summary
[0003]然而,在实际检测过程中,由于铅笔杆漆面和金属箍具有极高的镜面反射特性,当常规光源照射时,其表面产生的强烈镜面反射光会直接进入工业相机,导致图像中缺陷所在区域出现大面积过曝,一些关键特征被高光掩盖而完全丢失,使得后续算法无法稳定提取有效信息,进而造成严重的漏检和误检
本发明通过设置于光源出光侧的起偏器和设置于相机镜头前方的检偏器并令二者偏振方向正交,采集铅笔的偏振消反光图像并进行预处理,从而从成像源头有效滤除了铅笔漆面与金属箍产生的强烈镜面反射光干扰,解决了因高光过曝导致缺陷特征丢失的问题和橡皮头长度测量过程中橡皮头区域提取困难的问题。将预处理后的图像输入单阶段目标检测模型,通过候选框生成、置信度过滤及非极大值抑制去重实现表面缺陷的高效识别,然后舍去候选框面积小于预设阈值的框,通过修改阈值大小实现检测灵敏度调节,通过将候选框中心点坐标与预设的铅笔位置与像素坐标的映射关系进行匹配,准确确定每一缺陷所属的铅笔,并根据预设的橡皮区域提取图像,经二值化、动态阈值边缘提取、形态学运算、提取多特征融合结合支持向量机SVM分类测量区域及旋转直线法获得最小外接矩形,计算上下边界线像素距离并乘以预标定的像素-毫米比例系数换算为实际物理长度,本发明在同一张消反光图像上同步完成了表面缺陷检测与长度测量,无需增设额外工位或相机,同时保证了亚毫米级测量精度,基于缺陷-铅笔对应关系表和橡皮头实际物理长度,采用三队列管理机制通过队列移位和逐元素逻辑与运算实现连续帧的状态累积,输出稳定可靠的最终判定结果,从而满足了铅笔工业化连续生产中高效、稳定、全项质检的实际需求。
Smart Images

Figure CN122836065A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision inspection technology, specifically a polarization-based pencil surface defect detection and eraser length measurement system and method. Background Technology
[0002] In the industrialized continuous production of pencils, the quality of the surface coating, defects in the metal band assembly, and the length of the eraser tip are core indicators determining product quality. The industry generally requires 100% online full inspection. To address this need, existing technologies attempt to use machine vision solutions. The inspection method typically involves setting up an industrial camera and a conventional ring or strip light source above the production line. A transmission mechanism moves the pencil to the inspection station, triggering the camera to capture an image of the pencil. The image is then analyzed using image processing algorithms to determine if defects exist.
[0003] However, in actual testing, due to the highly specular reflective properties of the pencil's paint and metal band, the intense specular reflection from these surfaces directly enters the industrial camera when illuminated by conventional light sources. This causes large areas of overexposure in the image where defects are located, and some key features are completely lost due to the highlights. This makes it impossible for subsequent algorithms to reliably extract effective information, resulting in serious missed and false detections. Moreover, as a slender body of revolution, the detection of surface defects in a pencil needs to cover the circumferential curved surface, while the measurement of the eraser tip length focuses on the axial end. Existing inspection systems often require separate multi-station setups and multiple cameras for these two different types of inspection tasks. This not only leads to redundant and complex overall equipment structures and high hardware costs but also significantly increases the difficulty of installation, debugging, and maintenance. Therefore, the existing inspection method cannot accurately identify multiple types of surface defects and measure the eraser tip assembly length simultaneously at a single station while suppressing high reflectivity interference. It cannot meet the actual production needs of efficient, stable, and comprehensive quality inspection in the pencil industry. Summary of the Invention
[0004] The purpose of this invention is to provide a polarization-based system and method for detecting surface defects in pencils and measuring the length of erasers, in order to solve the above-mentioned problems.
[0005] The technical solution of this invention is: A polarization-based method for detecting surface defects in pencils and measuring eraser length includes the following steps: The polarization-de-reflection image of the pencil is acquired by a polarizer set on the light-emitting side of the light source and an analyzer set in front of the camera lens. The polarization directions of the polarizer and the analyzer are orthogonal. The acquired image is then normalized and preprocessed using tensor reconstruction. The preprocessed image is input into a single-stage object detection model to obtain multiple candidate boxes containing confidence scores and location coordinates. Candidate boxes with confidence scores below a preset threshold are discarded, and non-maximum suppression is performed based on the intersection-union ratio to remove duplicates. The area of the candidate box is compared with the set value, and candidate boxes that are too small are ignored to control the detection sensitivity. The center point coordinates of the candidate boxes retained after deduplication are matched with the preset mapping relationship between pencil position and pixel coordinates to determine the pencil to which each defect belongs and generate a defect-pencil correspondence table. The rubber region image is extracted based on the preset rubber region. After binarization, dynamic threshold edge extraction, morphological operation, and calculation of 10-dimensional features such as contour area, perimeter, aspect ratio, roundness, rectangularity, convexity, solidity, equivalent diameter, inertia ratio, and average gray level, the support vector machine algorithm is used to distinguish three states: normal rubber, unqualified rubber, and empty space. Then, only for the normal rubber region, the minimum bounding rectangle of the rubber region is obtained by the rotation line method. The pixel distance between the upper and lower boundary lines is calculated and converted into the actual physical length of the rubber head according to the pre-calibrated pixel-to-millimeter ratio coefficient. Based on the defect-pencil correspondence table and the actual physical length of the eraser tip, a three-queue management mechanism is used to cumulatively determine the overall quality status of the pencil. The three-queue management mechanism achieves continuous frame state accumulation through queue shifting and element-by-element logical AND operation, and outputs the final determination result.
[0006] Furthermore, each candidate box includes center coordinates, width and height, confidence score, and category ID. The single-stage object detection model is designed for pencil defects and includes a unique feature extraction network specifically for pencil defects. This network is based on the YOLO series backbone network and introduces three key modules: a dilated convolutional feature extraction module, a HWD information-preserving downsampling module, and a dual-scale feature decoupling and recoupling module. To improve multi-scale detection performance, a dilated convolutional feature extraction module is introduced, which expands the receptive field without increasing the number of parameters by stacking multiple dilated convolutional layers. To preserve small-scale features, an HWD information-preserving downsampling module is introduced to replace the traditional pooling layer, avoiding information loss during downsampling and retaining complete information while downsampling, making it suitable for detecting minute defects that are sensitive to details. To address the issue of scale aliasing and false detections caused by background interference in the feature pyramid, a dual-scale feature decoupling learning scale decoupling activation map is introduced. This decomposes each layer of the feature pyramid into small-scale and large-scale feature subspaces, activating only the foreground region to obtain a foreground / background subspace. Finally, a feature recoupling module aligns and weights the same-scale features from different levels, resulting in an enhanced scale-specific feature representation. This final feature is then fed into the detector for defect detection. These three modules work together to improve the network's ability to detect pencil defects. The preset number of candidate boxes output is 25,200; the preset threshold is 0.25.
[0007] Furthermore, an image of a pencil is acquired, and a mapping relationship between the pencil position and pixel coordinates is established based on the pixel position to obtain a position mapping dictionary.
[0008] Furthermore, when extracting the eraser tip region contour, high and low thresholds are dynamically calculated based on the statistical gradient of the binary image to extract the eraser contour edge. Opening and closing operations are then performed sequentially on the eraser contour image to remove noise and fill holes. By calculating 10-dimensional features—contour area, perimeter, aspect ratio, roundness, rectangularity, convexity, solidity, equivalent diameter, inertia ratio, and average grayscale—a support vector machine algorithm is used to distinguish between normal erasers, defective erasers, and empty areas. Because the metal band region is easily mistakenly extracted when the pencil is missing an eraser tip, a multi-feature fusion combined with the support vector machine (SVM) method is used to distinguish between the true eraser region and the mistakenly extracted metal band region.
[0009] Furthermore, during the physical length measurement of the rubber, the state of the objects to be measured at the workstation is first distinguished, including three types of working conditions: normal rubber, unqualified rubber, and empty space. According to the production process requirements, only normal rubber needs to enter the subsequent dimensional measurement process, unqualified rubber is directly rejected, and empty space is not processed. The state distinction method adopts a multi-feature fusion combined with the Support Vector Machine (SVM) algorithm. The SVM classifier is trained with 10 features. Geometric features include area, perimeter, aspect ratio, roundness, rectangularity, convexity, solidity, equivalent diameter, and inertia ratio. Gray-scale features include average gray-scale. When obtaining the minimum bounding rectangle using the rotating straight line method, the first contact point is found by scanning from left to right, and the rotating straight line is used to find the best-fit left boundary; the first contact point is found by scanning from right to left, and the rotating straight line is used to find the best-fit right boundary; the first contact line is found as the upper boundary by scanning from top to bottom; the first contact line is found as the lower boundary by scanning from bottom to top; the intersection points of the four detected boundary lines are calculated to obtain the vertices of the quadrilateral, and they are sorted in a clockwise direction.
[0010] Furthermore, the three-queue management mechanism includes a current frame queue, a previous frame queue, and a temporary queue. After defect detection and rubber tip measurement are completed for a frame image, the judgment result is stored in the temporary queue. Then, the previous frame queue is shifted forward and a qualified flag is added to the end of the queue. Then, the corresponding elements of the previous frame queue and the temporary queue are subjected to an element-by-element logical AND operation, and the result is stored in the current frame queue. Finally, the current frame queue is copied to the previous frame queue to update the quality queue for the next calculation.
[0011] Furthermore, when determining the conformity of the eraser tip length, it is determined whether the measured actual physical length of the eraser tip is within the preset threshold range. If it is within the threshold range, it is determined to be conforming. Furthermore, it also includes model updates, which include the following steps: acquiring anti-reflective images of the new model pencils, preprocessing the images of the new model pencils and constructing a dataset of the new model pencils, and incrementally training the single-stage target detection model based on the dataset of the new model pencils to adapt to the defect detection requirements of the new model pencils.
[0012] Furthermore, it also includes semi-supervised model training, which employs a teacher-student model architecture for semi-supervised incremental learning. The teacher model and the student model have the same single-stage object detection network structure, and their parameters are updated periodically by the student model. The training method includes the following steps: A mixed training dataset was constructed by collecting a small number of labeled images and a large number of unlabeled images. The teacher model, trained on pre-labeled data, is used to predict unlabeled images and generate pseudo-label candidates. The pseudo-label candidates are screened and divided into multiple groups according to defect category and defect scale. For each group, a Bayesian-Gaussian mixture model is used to fit the confidence distribution and automatically determine the optimal confidence threshold for that group. Pseudo-labels with confidence scores higher than the threshold are retained as high-quality pseudo-labels. The student model was trained using both labeled data and filtered, high-quality pseudo-labeled data. Regularly update the teacher model and iteratively optimize the quality of pseudo-labels.
[0013] High quality is objectively determined by whether the confidence level is greater than the adaptive threshold of the corresponding category-scale grouping.
[0014] The teacher model refers to a benchmark single-stage object detection model that has been pre-trained on labeled datasets and has the ability to detect pencil defects. Its core function is to perform inference and prediction on unlabeled images, output defect candidate boxes, categories and confidence results, thereby generating initial pseudo-labels and providing additional supervision signals for student models.
[0015] During iterative training, the parameters of the teacher model are updated periodically using the exponential moving average of the student model parameters. As the performance of the student model improves, the quality of pseudo-label generation is optimized in sync. The semi-supervised training process is a process of pseudo-label generation - student model training - teacher model update.
[0016] The semi-supervised model training employs a dual adaptive threshold method for pseudo-label selection and a scale-aware dynamic label allocation method for label allocation strategy.
[0017] The steps of the dual adaptive pseudo-label thresholding method are as follows: First, groups are formed by defect category, and then further grouped by target scale within each category; the optimal confidence threshold is calculated for each category-scale combination; the confidence distribution is fitted using a Bayesian-Gaussian mixture model to automatically determine the threshold for each group; for groups with insufficient samples, the default threshold is used in conjunction with the buffer to accumulate samples until sufficient samples are available before the threshold is automatically determined.
[0018] The scale-aware dynamic label assignment method is as follows: Calculate the area of each ground truth objective and dynamically adjust the weights of IoU and NWD based on the area size; For small targets, the NWD distance is emphasized, while for large targets, the IoU is emphasized; the sigmoid function is used to achieve a smooth transition between IoU weights and NWD weights; positive and negative samples are assigned based on the classification cost function and the mixed location cost function.
[0019] A semi-supervised model training method is proposed to improve model detection performance when labeled data is limited. It includes a dual adaptive pseudo-label thresholding module that considers both class and size imbalances, adaptively calculating the optimal pseudo-label selection threshold for each class-scale combination; and a scale-aware label allocation module that includes cost functions for classification cost and mixed location cost. The classification cost represents the matching degree between confidence and localization quality, while the mixed location cost introduces normalized Wasserstein distance (NWD) to measure the matching degree between small-sized defect candidate boxes and ground truth boxes. The IOU and NWD weights are dynamically adjusted according to the target size to achieve a balanced allocation of supervisory information for defects of different sizes.
[0020] A pencil surface defect detection and eraser tip length measurement system based on polarization-induced antireflection, comprising the following steps: A polarization-induced anti-reflection image acquisition device includes an industrial camera, an analyzer disposed in front of the lens of the industrial camera, a strip polarization light source assembly, and a polarizer disposed on the light-emitting side of the strip polarization light source assembly; the polarization directions of the polarizer and the analyzer are orthogonal. A transmission device is used to drive the pencil to move continuously; the transmission device includes a photoelectric triggering component, which is used to send a trigger signal to the industrial camera when the pencil moves to a predetermined position, so as to trigger the industrial camera to acquire an anti-reflective image; The defect detection module has its input end connected to the output end of the industrial camera. The defect detection module is configured to: identify the type and location of defects on the pencil surface based on the anti-reflective image, and determine the pencil to which each defect belongs according to the preset mapping relationship between pencil position and pixel coordinates, and generate a defect-pencil correspondence table. The rubber tip length measurement module has its input end connected to the output end of the industrial camera. The rubber tip length measurement module is configured to: extract the outline of the rubber tip region based on the same anti-reflective image, calculate the pixel length of the rubber tip in the image, and convert it into the actual physical length of the rubber tip according to the pre-calibrated pixel-millimeter ratio coefficient. The quality judgment module has a first input terminal connected to the output terminal of the defect detection module and a second input terminal connected to the output terminal of the eraser length measurement module. The quality judgment module is configured to: based on the defect-pencil correspondence table and the actual physical length of the eraser, use a three-queue management mechanism to cumulatively judge the overall quality status of the pencil and output the final judgment result.
[0021] Furthermore, the polarization anti-reflective image acquisition device also includes a black light-absorbing plate, which is arranged on the side of the pencil facing away from the camera to absorb stray light transmitted or scattered.
[0022] Compared with the prior art, the beneficial effects of the present invention are: This invention uses a polarizer positioned on the light-emitting side of the light source and an analyzer positioned in front of the camera lens, with their polarization directions orthogonal, to acquire a polarized anti-reflective image of a pencil. This image is then preprocessed to effectively filter out strong specular reflections from the pencil's paint and metal band at the imaging source. This solves the problems of lost defect features due to overexposure and difficulty in extracting the eraser region during eraser length measurement. The preprocessed image is input into a single-stage target detection model. Through candidate box generation, confidence filtering, and non-maximum suppression for deduplication, efficient identification of surface defects is achieved. Candidate boxes with areas smaller than a preset threshold are discarded. The detection sensitivity is adjusted by modifying the threshold. By matching the coordinates of the candidate box center point with the preset mapping relationship between pencil position and pixel coordinates, the pencil to which each defect belongs is accurately determined. The image is then extracted based on the preset eraser region, and subjected to binarization, dynamic threshold edge extraction, morphological operations, multi-feature extraction and fusion combined with Support Vector Machine (SVM) classification, and rotational line method to obtain the measurement region. The invention obtains the minimum bounding rectangle, calculates the pixel distance between the upper and lower boundary lines, and multiplies it by a pre-calibrated pixel-to-millimeter ratio coefficient to convert it into the actual physical length. This invention simultaneously completes surface defect detection and length measurement on the same anti-reflective image without the need for additional workstations or cameras, while ensuring sub-millimeter-level measurement accuracy. Based on the defect-pencil correspondence table and the actual physical length of the eraser tip, a three-queue management mechanism is adopted to achieve continuous frame state accumulation through queue shifting and element-by-element logical AND operation, outputting a stable and reliable final judgment result, thereby meeting the actual needs of efficient, stable, and comprehensive quality inspection in the continuous industrial production of pencils. Attached Figure Description
[0023] Figure 1This is a flowchart of the method of the present invention.
[0024] Figure 2 This is a schematic diagram of the three-queue management mechanism of the present invention.
[0025] Figure 3 This is a schematic diagram of the test pencil model used in this invention.
[0026] Figure 4 This is a schematic diagram illustrating the calculation of the rubber tip tilt angle and length according to the present invention.
[0027] Figure 5 This is a diagram of the feature extraction network structure of the single-stage detection model for pencil defects in this invention.
[0028] Figure 6 This is a schematic diagram of the structure of the polarization-de-reflection image acquisition device of the present invention.
[0029] Among them, 1. polarizer, 2. light source output side, 3. camera, 4. analyzer. Detailed Implementation
[0030] The following is combined with Figures 1 to 6 The specific embodiments of the present invention will be described in detail below.
[0031] Example like Figure 1 As shown, a polarization-based method for detecting surface defects in pencils and measuring eraser length includes the following steps: like Figure 6 As shown, a polarized anti-reflective image of a pencil is acquired using a polarizer 1 positioned on the light-emitting side 2 of the light source and an analyzer 4 positioned in front of the lens of the camera 3. The polarization directions of the polarizer 1 and the analyzer 4 are orthogonal. During acquisition, the analyzer 4 in front of the lens is rotated to acquire an image of the pencil's smallest polariton under polarized light source illumination, thereby eliminating strong reflections from the pencil's paint and metal band. The acquired image pixel values are normalized to the range [0, 1], and the data is reconstructed into a 4D tensor format with dimensions [1, 3, 960, 1280], completing the preprocessing. The acquired image is then normalized and subjected to tensor reconstruction preprocessing.
[0032] The preprocessed image is input into a single-stage object detection model to obtain multiple candidate boxes containing confidence scores and location coordinates. Candidate boxes with confidence scores below a preset threshold are discarded, and non-maximum suppression is performed based on the intersection-union ratio to remove duplicates. The area of the candidate box is compared with the set value, and candidate boxes that are too small are ignored to control the detection sensitivity. Specifically, the preprocessed image is input into a single-stage object detection model, directly yielding 25,200 candidate boxes. Each candidate box includes center coordinates (x, y), width and height (w, h), confidence score, and class ID. Detection boxes with a confidence score below 0.25 are discarded. The remaining candidate boxes are then converted from center coordinate format to corner coordinate format (x1, y1, x2, y2) using the following formula:
[0033] ; Based on the transformed candidate bounding box coordinates, a deduplication operation is performed on the candidate bounding boxes for each category. First, all candidate bounding boxes for each category are sorted in descending order of confidence. Then, the candidate bounding box B1 with the highest confidence is selected as the baseline. Next, all bounding boxes with an Intersection over Union (IOU) exceeding a predetermined threshold with B1 are removed, eliminating overly similar candidate bounding boxes. Then, the candidate bounding box B2 with the second highest confidence is selected as the baseline, and the above process is repeated until all candidate bounding boxes have been used as baselines. The Intersection over Union (IOU) of bounding boxes b1 and b2 is calculated as follows:
[0034] ; Here, Aera() represents the area of a candidate box.
[0035] The center point coordinates of the candidate boxes retained after deduplication are matched with the preset mapping relationship between pencil position and pixel coordinates to determine the pencil to which each defect belongs, and a defect-pencil correspondence table is generated. The mapping relationship is pre-established in the following way: First, a pencil image is acquired, and the mapping relationship between pencil position and pixel coordinates is established according to the pixel position to obtain a position mapping dictionary.
[0036] Specifically, firstly, the rubber region image is extracted based on the preset rubber region. The extracted image is then binarized. Based on the binary image, high and low thresholds are dynamically calculated using statistical image gradients to obtain clear rubber contour edges. Opening and closing operations are sequentially performed on the rubber contour image to remove noise and fill holes. Then, a multi-dimensional feature input to a support vector machine (SVM) is used to distinguish between normal rubber regions, defective rubber regions, and empty spaces. Specifically, by calculating 10-dimensional features—contour area, perimeter, aspect ratio, roundness, rectangularity, convexity, solidity, equivalent diameter, inertia ratio, and average grayscale—the SVM algorithm distinguishes between normal rubber, defective rubber, and empty spaces. Finally, the minimum bounding rectangle of the rubber region is obtained using a rotational straight line method, applied only to the rubber region. The rotating line method specifically includes: scanning from left to right to find the first contact point, rotating the line to find the best-fit left boundary; scanning from right to left to find the first contact point, rotating the line to find the best-fit right boundary; scanning from top to bottom to find the first contact line as the upper boundary; scanning from bottom to top to find the first contact line as the lower boundary; calculating the intersection points based on the four detected boundary lines to obtain the vertices of the quadrilateral, and sorting them in a clockwise direction.
[0037] Taking the left boundary as an example, the rotation equation is: ; Where X, y represent the coordinates of a point on the line. The x-coordinate of the first column containing white pixels. The average Y-coordinate is used as the center of rotation. The offset chosen in the y-direction when rotating a straight line. Indicates the rotation angle.
[0038] like Figure 4 As shown, the pixel distance between the upper and lower boundary lines is calculated based on the geometric features of the quadrilateral. : ; in, These are the top left, top right, bottom left, and bottom right vertices of the quadrilateral, respectively. According to the proportionality coefficient... Calculate the physical length of the eraser tip, calculate the tilt angle of each side, and analyze the overall tilt trend of the eraser tip. The formula for calculating the physical length is:
[0039] ; Where α represents pixel equivalent, that is, the physical length corresponding to one pixel.
[0040] The formula for calculating the tilt angle of the eraser tip is: .
[0041] in, This represents the difference in the y-coordinates of the top-left and bottom-left vertices of the quadrilateral in the eraser region. This represents the difference in x-coordinates between the top-left and bottom-left vertices of the quadrilateral in the rubber region.
[0042] like Figure 2 As shown, based on the defect-pencil correspondence table and the actual physical length of the eraser tip, a three-queue management mechanism is used to cumulatively determine the overall quality status of the pencils. The three-queue management mechanism includes a current frame queue, a previous frame queue, and a temporary queue. During system initialization, all elements in all queues are set to a qualified state. After defect detection and eraser tip measurement are completed in a frame, the determination results of each pencil are sequentially stored in the temporary queue. Then, a shift operation is performed on the previous frame queue, removing one element from the head and adding a qualified state to the tail. Next, an element-by-element logical AND operation is performed between the shifted previous frame queue and the corresponding elements in the temporary queue, and the result is stored in the current frame queue. Finally, the current frame queue is copied to a new previous frame queue, and the temporary queue is cleared for storing the determination results of the next frame. This queue shifting and element-by-element logical AND operation achieves continuous frame state accumulation, effectively filtering single-frame noise interference and outputting the final determination result. When determining the passability of the eraser tip length, it is judged whether the actual physical length of the eraser tip measured is within the preset threshold range. If it is within the threshold range, it is judged as passable; if it exceeds the threshold range, it is further checked whether there is a pencil at that position. If there is a pencil, it is judged as failable; if there is no pencil, it is judged as passable by default.
[0043] like Figure 5As shown, a single-stage target detection model specifically for pencil defects is proposed, comprising a dedicated feature extraction network with three key components: a dilated convolutional feature extraction module, an HWD (High-Level Dynamics and Data-Preserving Downsampling) module, and a dual-scale feature decoupling and recoupling module. The dilated convolutional feature extraction module includes: stacked dilated convolutional layers with dilation rates of 2, 4, and 8 to extract multi-scale receptive field features; a connection layer to fuse features from different receptive fields; and an HWD downsampling layer to perform information-preserving downsampling on the fused features with a stride of 2; the dilated convolutional feature extraction module consists of four stacked layers. Furthermore, feature maps of different scales are extracted from the output of each dilated convolutional feature extraction module and input into the dual-scale feature decoupling and recoupling module. The dual-scale feature structure module learns a scale-decoupled activation map for each feature layer, decomposing the features into small-scale and large-scale subspaces. The activation maps are generated using 1×1 convolutions and the Softmax function, and supervised training is performed using soft labels based on bounding box scales. Then, feature activation is achieved through element-wise multiplication to preserve effective features of the foreground region and suppress background interference; features of the same scale at different levels are aligned and weighted and fused to obtain enhanced scale-specific feature representations.
[0044] In some embodiments, the model update also includes the following steps: acquiring anti-reflective images of the new model pencils, preprocessing the images of the new model pencils and constructing a dataset of the new model pencils, and incrementally training the single-stage target detection model based on the dataset of the new model pencils to adapt to the defect detection requirements of the new model pencils.
[0045] Because pencil defects vary greatly in size, with a large number of tiny defects, the quality of label assignment is crucial for detecting these minor defects when training a defect detection model. Existing methods often use the Intersection over Union (IOU) as an indicator to assign candidate boxes to labels, but IOU is sensitive to the offset of small-sized candidate boxes. Using IOU for label assignment leads to a large number of valid small defect candidate boxes being classified as background; furthermore, the accompanying scale imbalance results in larger defects being assigned more labels than smaller defects, leading to insufficient supervision information for small defects. The network then tends to optimize for larger-scale targets, resulting in poor detection performance for small defects.
[0046] Moreover, in pencil defect detection, acquiring labeled data is costly, while a large amount of unlabeled data remains underutilized. Semi-supervised learning can effectively reduce labeling costs by utilizing unlabeled data, but existing semi-supervised object detection methods face the following challenges when applied to pencil defect detection:
[0047] The frequency of occurrence of different defect types varies significantly. Among all pencil defects, broken paint at the tip accounts for about 61%, broken eraser accounts for about 20.5%, and broken metal band accounts for about 18.5%, making it difficult to uniformly set the false label threshold. The scale difference between small target defects (such as minor damage) and large target defects (such as large-area damage) is huge. Among all pencil defects, small-sized defects account for about 74.8%, while medium and large-sized defects account for about 25.2%. Existing methods are not effective in screening for false labels and assigning labels to small targets. The coexistence of class imbalance and scale imbalance further exacerbates the difficulty of semi-supervised training.
[0048] The above data are all from statistics derived from a self-built pencil dataset. Therefore, a semi-supervised model training method is needed that addresses the characteristics of industrial defect detection, effectively tackling the dual imbalance of class and scale, and improving pseudo-label quality and model detection performance.
[0049] The model update in this embodiment first includes a dual adaptive pseudo-label threshold, comprising the following steps: The teacher model predicts on unlabeled images and generates candidate pseudo-labels; Group by category; group candidate pseudo-labels by category. Within each category, defects are grouped by scale, and the predicted defects are classified into small and large defects based on their area. Defects with an area less than 0.16% of the image area are considered small defects, while those with an area greater than 0.16% are considered large defects.
[0050] Based on category-size grouping, all candidate pseudo-labels were divided into 6 groups: "pen tip paint damage - small size", "pen tip paint damage - large size", "eraser damage - small size", "eraser damage - large size", "metal band damage - small size", and "metal band damage - large size". Within each group, a Bayesian Gaussian mixture model was used to fit the confidence scores of the candidate pseudo-labels, and the boundary point between the two Gaussian distributions was found as the optimal threshold for that group.
[0051] If the number of candidate pseudo-labels for a combination is less than the threshold (set to 20), the global default threshold (set to 0.5) is used, along with a cumulative statistical strategy. After accumulating a sufficient number of candidate pseudo-labels, a Bayesian-Gaussian mixture model is fitted to adapt to the sparse defect scenario.
[0052] Pseudo-label screening is performed by using the pseudo-label confidence threshold for each group to filter candidate pseudo-labels within each group and retaining candidate pseudo-labels with a confidence level higher than the threshold.
[0053] Model updates also include a scale-aware label assignment strategy for network training, the steps of which are as follows: First, for each predicted bounding box pi and each ground truth bounding box gj, calculate the matching cost: .
[0054] in, For the classification cost function, The cost is a mixed location cost, where λ1 and λ2 are the weights of the classification cost and the location cost, respectively. The calculation method is as follows:
[0055] .
[0056] in, This represents the confidence score of the output box. represents the IOU between the output box and the truth box, and CE is the cross-entropy function. The cost of mixed locations is calculated as follows:
[0057] .
[0058] Where IOU represents the intersection-union ratio of the output box and the truth box. The weighting coefficients are dynamically calculated based on the scale of the truth box. NWD represents the normalized Wasserstein distance between the output box and the truth box. is the numerical stability constant. The calculation method is as follows:
[0059] .
[0060] Where area represents the area of the truth box, threshold is the scale threshold, and temperature is the adjustment factor. NWD represents the normalized Wasserstein distance between the output box and the truth box, calculated as follows:
[0061] .
[0062] Where C is a constant, . These are the x and y coordinates of the center points of the output box and the truth box, respectively. These are the width and height of the output box and the truth box, respectively.
[0063] Then, positive samples are selected. For each ground truth box gj, the top K predicted boxes with the lowest cost are assigned as positive samples based on the total cost.
[0064] A system for detecting surface defects in pencils and measuring eraser tip length based on polarization-induced antireflection, characterized in that it comprises: The polarization-induced anti-reflection image acquisition device includes a camera 3, an analyzer 4 disposed in front of the lens of the camera 3, a strip polarization light source assembly, and a polarizer 1 disposed on the light-emitting side of the strip polarization light source assembly; the polarization directions of the polarizer 1 and the analyzer 4 are orthogonal, and the camera 3 is an industrial camera. A transmission device is used to drive the pencil in continuous motion. The transmission device includes a pencil conveyor chain, a variable frequency drive motor, and a photoelectric triggering component. The photoelectric triggering component includes a fiber optic positioning sensor, which sends a trigger signal to camera 3 when it detects that the pencil has moved to a predetermined position, thereby triggering camera 3 to acquire an anti-reflective image;
[0065] The defect detection module is connected to the output of camera 3 at its input end. The defect detection module is configured to: identify the type and location of defects on the pencil surface based on the anti-reflective image, and determine the pencil to which each defect belongs according to the preset mapping relationship between pencil position and pixel coordinates, and generate a defect-pencil correspondence table. The eraser tip length measurement module has its input end connected to the output end of the camera 3. The eraser tip length measurement module is configured to: extract the outline of the eraser tip region based on the same anti-reflective image, calculate the pixel length of the eraser tip in the image, and convert it into the actual physical length of the eraser tip according to the pre-calibrated pixel-millimeter ratio coefficient. The quality judgment module has its first input terminal connected to the output terminal of the defect detection module and its second input terminal connected to the output terminal of the eraser length measurement module. The quality judgment module is configured to: based on the defect-pencil correspondence table and the actual physical length of the eraser, use a three-queue management mechanism to cumulatively judge the overall quality status of the pencil and output the final judgment result.
[0066] The polarization anti-reflection image acquisition device also includes a black light-absorbing plate, which is placed on the side of the pencil facing away from the camera 3 to absorb stray light transmitted or scattered.
[0067] To verify the effectiveness of this method, an experimental system was built, consisting of a camera (3), a fixed-focus lens, a polarizer (1), an analyzer (4), a strip polarizing light source assembly, a black light-absorbing plate, a transmission device, and pencils of various colors. Purple, blue, and orange hexagonal pencils were tested. For each of the three defect types, five tests were performed, and the precision and recall were calculated. The average precision for a single defect was 93.84%, the average recall was 97.36%, and the average false negative rate was 2.63%. The results are summarized in Table 1. Tables 2-5 show the defect detection and eraser length measurement results for these three types of pencils using this system. Furthermore, to verify the applicability of the method to different types of pencils, yellow hexagonal, red triangular, and colored round pencils were also selected for appearance defect detection tests, and the results are summarized in Table 6. Various types of pencils are shown in Table 6. Figure 3 As shown.
[0068] Table 1 Average Defect Detection Results Table 2 Deformation Test of Metal Hoop Table 3 Paint Damage Test Table 4 Rubber Damage Detection Table 5. Comprehensive Defect Detection Accuracy Test Table 6 Applicability Test Results To test the accuracy of the eraser tip length measurement, 18 samples were selected for testing. The measurements were taken using vernier calipers as the true values, and the error between the software's measurement results and the true values was calculated. The average error was [missing value]. The test results meet the requirements and are summarized in Table 7.
[0069] Table 7. Measurement Results of Eraser Tip Length The above-disclosed embodiments are merely preferred embodiments of the present invention. However, the embodiments of the present invention are not limited thereto, and any variations that can be conceived by those skilled in the art should fall within the protection scope of the present invention.
Claims
1. A method for detecting surface defects in pencils and measuring eraser length based on polarization, characterized in that, Includes the following steps: The polarization-de-reflection image of the pencil is acquired by a polarizer set on the light-emitting side of the light source and an analyzer set in front of the camera lens. The polarization directions of the polarizer and the analyzer are orthogonal. The acquired image is then normalized and preprocessed using tensor reconstruction. The preprocessed image is input into a single-stage object detection model to obtain multiple candidate boxes containing confidence scores and location coordinates. Candidate boxes with confidence scores below a preset threshold are discarded, and non-maximum suppression is performed based on the intersection-union ratio to remove duplicates. The area of the candidate box is compared with a set value, and candidate boxes that are too small are ignored. The center point coordinates of the candidate boxes retained after deduplication are matched with the preset mapping relationship between pencil position and pixel coordinates to determine the pencil to which each defect belongs and generate a defect-pencil correspondence table. The rubber region image is extracted based on the preset rubber region. After binarization, dynamic threshold edge extraction, morphological operation, extraction of multi-dimensional features and combined with the support vector machine (SVM) algorithm, three states are distinguished: normal rubber, unqualified rubber, and empty space. Then, only for the normal rubber region, the minimum bounding rectangle of the rubber region is obtained by the rotation line method. The pixel distance between the upper and lower boundary lines is calculated and converted into the actual physical length of the rubber head according to the pre-calibrated pixel-to-millimeter ratio coefficient. Based on the defect-pencil correspondence table and the actual physical length of the eraser tip, a three-queue management mechanism is used to cumulatively determine the overall quality status of the pencil. The three-queue management mechanism achieves continuous frame state accumulation through queue shifting and element-by-element logical AND operation, and outputs the final determination result.
2. The method for detecting pencil surface defects and measuring eraser length based on polarization according to claim 1, characterized in that, Each candidate box includes center coordinates, width and height, confidence score, and category ID; the preset number of candidate boxes output by the single-stage object detection model is 25,200; the preset threshold is 0.
25.
3. The method for detecting pencil surface defects and measuring eraser length based on polarization according to claim 1, characterized in that, A pencil image is acquired, and a mapping relationship between the pencil position and pixel coordinates is established based on the pixel position to obtain a position mapping dictionary. The position mapping dictionary is used to match the center point coordinates of the candidate box to the corresponding pencil.
4. The method for detecting surface defects in pencils and measuring eraser length based on polarization according to claim 1, characterized in that, When measuring the physical length of the rubber, the state of the objects to be measured at the workstation is first distinguished, including three types of working conditions: normal rubber, unqualified rubber, and empty space. According to the production process requirements, only normal rubber needs to enter the subsequent size measurement process, unqualified rubber is directly rejected, and empty space is not processed. The state distinction method adopts a multi-feature fusion combined with the support vector machine (SVM) algorithm. The SVM classifier is trained with 10 features. Geometric features include area, perimeter, aspect ratio, roundness, rectangularity, convexity, solidity, equivalent diameter, and inertia ratio. Gray-scale features include average gray-scale. When obtaining the minimum bounding rectangle using the rotating straight line method, the first contact point is found by scanning from left to right, and the rotating straight line is used to find the best-fit left boundary; the first contact point is found by scanning from right to left, and the rotating straight line is used to find the best-fit right boundary; the first contact line is found as the upper boundary by scanning from top to bottom; the first contact line is found as the lower boundary by scanning from bottom to top; the intersection points of the four detected boundary lines are calculated to obtain the vertices of the quadrilateral, and they are sorted in a clockwise direction.
5. The method for detecting pencil surface defects and measuring eraser length based on polarization according to claim 1, characterized in that, The three-queue management mechanism includes the current frame queue, the previous frame queue, and the temporary queue. After a frame of image completes defect detection and rubber tip measurement, the judgment result is stored in the temporary queue. Then, the previous frame queue is shifted forward and a qualified flag is added to the end of the queue. Then, the corresponding elements of the previous frame queue and the temporary queue are subjected to an element-by-element logical AND operation, and the result is stored in the current frame queue. Finally, the current frame queue is copied to the previous frame queue.
6. The method for detecting surface defects in pencils and measuring eraser length based on polarization according to claim 1, characterized in that, When determining the passability of the eraser tip length, it is judged whether the actual physical length of the eraser tip measured is within the preset threshold range. If it is within the threshold range, it is judged as passable; if it exceeds the threshold range, it is further checked whether there is a pencil at that position. If there is a pencil, it is judged as failable; if there is no pencil, it is judged as passable by default.
7. The method for detecting surface defects in pencils and measuring eraser length based on polarization according to claim 1, characterized in that, It also includes a single-stage object detection model specifically for pencil defects. This single-stage object detection model comprises three core components: a dilated convolutional feature extraction module, a High-Width Dynamics (HWD) information-preserving downsampling module, and a dual-scale feature decoupling and recoupling module. It employs dilated convolution combined with the HWD information-preserving downsampling module to achieve feature extraction that preserves information. Then, dual-scale feature decoupling is used to learn a scale-decoupled activation map for each feature layer, decomposing the features into two subspaces: a small-scale subspace and a large-scale subspace. To resolve feature confusion, features of the same scale at different levels are aligned and fused to obtain a scale-specific feature map, which is then fed into the detector for defect detection.
8. The method for detecting pencil surface defects and measuring eraser length based on polarization according to claim 1, characterized in that, It also includes model updates, which include the following steps: acquiring anti-reflective images of the new model pencils, preprocessing the images of the new model pencils and constructing a dataset of the new model pencils, and incrementally training the single-stage target detection model based on the dataset of the new model pencils to adapt to the defect detection requirements of the new model pencils.
9. The method for detecting pencil surface defects and measuring eraser length based on polarization according to claim 1, characterized in that, It also includes semi-supervised model training, which employs a teacher-student model architecture for semi-supervised incremental learning. The teacher model and the student model have the same single-stage object detection network structure, and their parameters are updated periodically by the student model. The training method includes the following steps: A mixed training dataset was constructed by collecting a small number of labeled images and a large number of unlabeled images. The teacher model, trained on pre-labeled data, is used to predict unlabeled images and generate pseudo-label candidates. The pseudo-label candidates are screened and divided into multiple groups according to defect category and defect scale. For each group, a Bayesian-Gaussian mixture model is used to fit the confidence distribution and automatically determine the optimal confidence threshold for that group. Pseudo-labels with confidence scores higher than the threshold are retained as high-quality pseudo-labels. The student model was trained using both labeled data and filtered, high-quality pseudo-labeled data. Regularly update the teacher model and iteratively optimize the quality of pseudo-labels; During training, a custom hybrid location cost function and location constraint cost function are used for dynamic label assignment to optimize the label assignment of small targets and assign more supervision information to small defects.
10. A system for detecting surface defects in pencils and measuring eraser tip length based on polarization-induced antireflection, characterized in that, include: A polarization-induced anti-reflection image acquisition device includes an industrial camera, an analyzer disposed in front of the lens of the industrial camera, a strip polarization light source assembly, and a polarizer disposed on the light-emitting side of the strip polarization light source assembly; the polarization directions of the polarizer and the analyzer are orthogonal. A transmission device is used to drive the pencil to move continuously; the transmission device includes a photoelectric triggering component, which is used to send a trigger signal to the industrial camera when the pencil moves to a predetermined position, so as to trigger the industrial camera to acquire an anti-reflective image; The defect detection module has its input end connected to the output end of the industrial camera. The defect detection module is configured to: identify the type and location of defects on the pencil surface based on the anti-reflective image, and determine the pencil to which each defect belongs according to the preset mapping relationship between pencil position and pixel coordinates, and generate a defect-pencil correspondence table. The rubber tip length measurement module has its input end connected to the output end of the industrial camera. The rubber tip length measurement module is configured to: extract the outline of the rubber tip region based on the same anti-reflective image, calculate the pixel length of the rubber tip in the image, and convert it into the actual physical length of the rubber tip according to the pre-calibrated pixel-millimeter ratio coefficient. The quality judgment module has a first input terminal connected to the output terminal of the defect detection module and a second input terminal connected to the output terminal of the eraser length measurement module. The quality judgment module is configured to: based on the defect-pencil correspondence table and the actual physical length of the eraser, use a three-queue management mechanism to cumulatively judge the overall quality status of the pencil and output the final judgment result.