Automatic Detection and Classification System for Surface Defects in Thermos Cups Based on Image Recognition
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-21
- Publication Date
- 2026-08-14
AI Technical Summary
由于常规方案的卷积核仅能在固定的矩形像素窗口内计算局部灰度差值,无法感知圆柱面的空间曲率信息,使得网络在特征提取阶段无法区分当前像素灰度的突变是由保温杯表面的真实物理凹陷或划痕引起,还是由圆柱面曲率导致的光线反射角度改变引起,即存在几何畸变与光学伪影混叠导致卷积神经网络无法区分真实物理缺陷与光学伪影的技术问题
[0018]1.本发明通过极坐标几何展开单元依据预标定的保温杯圆柱半径参数将原始图像序列映射至极坐标系并拼接生成标准化平面纹理图,消除了圆柱面曲率引起的几何透视畸变,还原了缺陷在二维平面内的真实空间分布形态。在此基础上,动态光照掩码生成单元在标准化平面纹理图内提取像素邻域灰度梯度方向与幅值构建表面反射率分布模型并输出动态光照掩码,跨域注意力分类网络通过纹理特征提取支路与掩码特征提取支路分别输出空间缺陷特征图与光照分布特征向量,交叉注意力层将光照分布特征向量作为抑制权重通过线性变换层映射为权重矩阵,并执行权重矩阵与空间缺陷特征图的逐元素乘积运算以及激活函数运算,在特征提取层面解耦了物理拓扑变化特征与光学反射变化特征,消除了高反光区域对应的特征激活响应,克服了光照突变产生的虚假特征干扰。
Smart Images

Figure CN122574469A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and specifically to an automatic detection and classification system for surface defects of thermos cups based on image recognition. Background Technology
[0002] In the field of image recognition-based industrial surface defect detection, conventional techniques for surface quality inspection of metal or polished workpieces typically employ convolutional neural networks with fixed topologies to extract and classify pixel-level features from acquired two-dimensional images. In practice, these conventional solutions directly crop the workpiece surface image acquired by an industrial camera to a fixed size and input it into a network model containing convolutional and pooling layers. The model extracts grayscale gradients and texture distribution features between pixels through sliding calculations within a local window of the image using convolutional kernels, performs feature dimensionality reduction in the pooling layer, and finally outputs the defect classification result through a fully connected layer. These conventional techniques are primarily designed for flat plates or flat workpieces with known orientations. When processing such workpieces, because the surface normals are uniform and the light source angle is fixed, the pixel grayscale changes in the image directly correspond to the physical topological changes of the workpiece surface.
[0003] When applying the aforementioned conventional technical solutions to detect surface defects in thermos cups, the thermos cups have a cylindrical curvature and a surface with high specular reflectivity. This results in the two-dimensional image input to the convolutional neural network exhibiting both geometric perspective distortion caused by the cylindrical curvature and highlights and shadows caused by the continuous change in the angle between the light source and the surface normal. Since the convolutional kernels in conventional solutions can only calculate local grayscale differences within a fixed rectangular pixel window and cannot perceive the spatial curvature information of the cylindrical surface, the network cannot distinguish during the feature extraction stage whether the sudden change in the current pixel's grayscale is caused by a real physical depression or scratch on the thermos cup's surface or by a change in the light reflection angle due to the cylindrical curvature. In other words, there is a technical problem where the convolutional neural network cannot distinguish between real physical defects and optical artifacts due to the overlapping of geometric distortion and optical artifacts. Summary of the Invention
[0004] The purpose of this invention is to provide an automatic detection and classification system for surface defects of thermos cups based on image recognition, which can solve the problems mentioned in the background art.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0006] An automatic detection and classification system for surface defects of thermos cups based on image recognition includes an image acquisition device, a polar coordinate geometric unfolding unit, a dynamic illumination mask generation unit, and a cross-domain attention classification network. The image acquisition device acquires a sequence of original images along the circumference of the thermos cup. The polar coordinate geometric unfolding unit, connected to the image acquisition device, maps the original image sequence from the camera pixel coordinate system to the polar coordinate system based on pre-calibrated cylindrical radius parameters of the thermos cup, and stitches them together to generate a standardized planar texture map. The dynamic illumination mask generation unit, connected to the polar coordinate geometric unfolding unit, extracts the direction and amplitude of the gray-level gradient of the pixel neighborhood within the spatial domain of the standardized planar texture map. The system constructs a surface reflectance distribution model, divides and outputs a dynamic illumination mask based on a reflectance threshold, and connects the cross-domain attention classification network to the dynamic illumination mask generation unit. The network includes a texture feature extraction branch, a mask feature extraction branch, and a cross-attention layer. The texture feature extraction branch performs convolution operations on the standardized planar texture map to output a spatial defect feature map. The mask feature extraction branch encodes the dynamic illumination mask to output an illumination distribution feature vector. The cross-attention layer uses the illumination distribution feature vector as a suppression weight on the spatial defect feature map to generate a residual feature map. Finally, a fully connected layer outputs the classification result of the surface defects of the thermos cup.
[0007] Preferably, the polar coordinate geometric unfolding unit includes a coordinate mapping subunit and an image stitching subunit; the coordinate mapping subunit obtains the cylindrical radius parameter of the thermos cup and the initial horizontal and vertical coordinates of each pixel in the original image sequence, and calculates the polar radius and polar angle corresponding to each initial horizontal and vertical coordinate with the central axis of the thermos cup as the polar axis; the image stitching subunit performs row alignment on the mapped pixels according to the polar angle, and column alignment on the mapped pixels according to the polar radius, and writes the grayscale values of the multi-view image pixels corresponding to the same polar angle according to the acquisition time sequence to generate the standardized planar texture map, wherein the row direction of the standardized planar texture map corresponds to the axial direction of the thermos cup, and the column direction corresponds to the circumferential direction of the thermos cup.
[0008] Preferably, the dynamic illumination mask generation unit includes a gradient calculation subunit and a model building subunit; the gradient calculation subunit constructs a sliding window on the normalized planar texture map, calculates the gray-level difference between the center pixel and its eight neighboring pixels within the sliding window, takes the largest gray-level difference as the gray-level gradient magnitude of the center pixel, and takes the direction corresponding to the largest gray-level difference as the gray-level gradient direction of the center pixel; the model building subunit inputs the gray-level gradient magnitude and the gray-level gradient direction into a pre-built two-dimensional Gaussian function, outputs the surface reflectance estimate of the center pixel, marks pixels whose surface reflectance estimate is greater than a preset reflectance threshold as highlight regions, sets the pixel position corresponding to the highlight region to a first value, and sets the pixel position corresponding to the non-highlight region to a second value, thereby generating the dynamic illumination mask.
[0009] Preferably, the cross-domain attention classification network includes a texture feature extraction branch and a mask feature extraction branch; the texture feature extraction branch includes three convolutional layers and two pooling layers connected in series, the normalized planar texture map is input to the first convolutional layer, the first pooling layer is connected between the first and second convolutional layers, the second pooling layer is connected between the second and third convolutional layers, and the third convolutional layer outputs the spatial defect feature map; the mask feature extraction branch includes two fully connected layers, the dynamic illumination mask is flattened into a one-dimensional vector and input to the first fully connected layer, the output of the first fully connected layer is connected to the input of the second fully connected layer, and the second fully connected layer outputs the illumination distribution feature vector.
[0010] Preferably, the cross-attention layer receives the spatial defect feature map and the illumination distribution feature vector, inputs the illumination distribution feature vector into a linear transformation layer, the linear transformation layer includes a fully connected computation operation, and maps the illumination distribution feature vector into a weight matrix with the same number of channels as the spatial defect feature map and a size of row vector; the cross-attention layer expands the weight matrix into a three-dimensional tensor with the same length and width as the spatial defect feature map, performs an element-wise multiplication operation between the three-dimensional tensor and the spatial defect feature map in the channel dimension, inputs the product operation result into a Sigmoid activation function, and performs an element-wise addition operation between the output of the Sigmoid activation function and the spatial defect feature map to generate the residual feature map.
[0011] Preferably, the cross-domain attention classification network further includes a global average pooling layer and a flattening layer; the global average pooling layer is connected between the cross-attention layer and the flattening layer, the global average pooling layer calculates the mean of the two-dimensional matrix in each channel of the residual feature map, compresses the two-dimensional matrix in each channel into a single floating-point number, and generates a one-dimensional feature vector; the flattening layer rearranges the dimensions of the one-dimensional feature vector, converts the one-dimensional feature vector into a one-dimensional column vector, the fully connected layer receives the one-dimensional column vector, and outputs a probability distribution vector containing scratch category, dent category and no defect category through matrix multiplication operation.
[0012] Preferably, the process of the coordinate mapping subunit obtaining the cylindrical radius parameter of the thermos cup includes: extracting the pixel coordinate set of the edge of the thermos cup in the original image sequence, performing ellipse fitting on the pixel coordinate set to generate an edge fitting equation, extracting the major axis pixel value and the minor axis pixel value of the edge fitting equation, converting the major axis pixel value and the minor axis pixel value into physical space distance according to a preset camera calibration coefficient, and dividing the physical space distance by pi to obtain the cylindrical radius parameter of the thermos cup; in the image stitching subunit, when the same polar angle corresponds to multiple viewpoint image pixels, calculating the acquisition time sequence weight corresponding to each pixel, and using the gray value of the pixel with the latest acquisition time as the gray value to be overwritten.
[0013] Preferably, the size of the sliding window is set to 3×3 pixels; in the gradient calculation subunit, for the center pixel of the edge region of the normalized planar texture map, the sliding window is constructed after padding the periphery of the normalized planar texture map with zeros; in the model construction subunit, the horizontal axis independent variable of the two-dimensional Gaussian function is the sine value of the gray-level gradient direction, the vertical axis independent variable is the normalized value of the gray-level gradient magnitude, the covariance matrix of the two-dimensional Gaussian function is set to a fixed constant value matrix, and the output value range of the pre-built two-dimensional Gaussian function is mapped to the interval between 0 and 1 through a linear scaling operation, and the mapped output value is used as the estimated surface reflectivity.
[0014] Preferably, the linear transformation layer includes a weight parameter matrix and a bias vector. The number of rows in the weight parameter matrix is equal to the dimension of the illumination distribution feature vector, and the number of columns in the weight parameter matrix is equal to the number of channels in the spatial defect feature map. When performing matrix multiplication, the illumination distribution feature vector is used as the left multiplication vector, the weight parameter matrix is used as the right multiplication matrix, and the product result is added to the bias vector to generate the weight matrix. Before performing the element-wise multiplication operation, all elements in the weight matrix are normalized so that the algebraic sum of all elements in the weight matrix is equal to the number of channels in the spatial defect feature map.
[0015] Preferably, the first convolutional layer in the texture feature extraction branch is configured as a convolution operation with a kernel size of 7×7 pixels and a stride of 2 pixels, the second convolutional layer is configured as a dilated convolution operation with a kernel size of 5×5 pixels and a stride of 1 pixel, and the third convolutional layer is configured as a depth-separable convolution operation with a kernel size of 3×3 pixels and a stride of 1 pixel.
[0016] Both the first and second pooling layers are configured for max pooling. The pooling window size of the first pooling layer is 2×2 pixels with a stride of 2 pixels, and the pooling window size of the second pooling layer is 3×3 pixels with a stride of 2 pixels.
[0017] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0018] 1. This invention uses a polar coordinate geometric unfolding unit to map the original image sequence to a polar coordinate system based on the pre-calibrated cylindrical radius parameters of a thermos cup, and then stitches them together to generate a standardized planar texture map. This eliminates the geometric perspective distortion caused by the curvature of the cylindrical surface and restores the true spatial distribution of defects in a two-dimensional plane. Based on this, a dynamic illumination mask generation unit extracts the gray-level gradient direction and amplitude of the pixel neighborhood within the standardized planar texture map to construct a surface reflectivity distribution model and outputs a dynamic illumination mask. A cross-domain attention classification network outputs a spatial defect feature map and an illumination distribution feature vector through texture feature extraction and mask feature extraction branches, respectively. The cross-attention layer uses the illumination distribution feature vector as suppression weights, maps it to a weight matrix through a linear transformation layer, and performs element-wise multiplication of the weight matrix with the spatial defect feature map, as well as activation function operations. This decouples physical topological change features from optical reflection change features at the feature extraction level, eliminates the feature activation response corresponding to highly reflective areas, and overcomes the interference of false features caused by abrupt changes in illumination.
[0019] 2. This invention extracts the set of edge pixel coordinates for elliptical fitting to generate an edge fitting equation when calculating the cylinder radius parameter. The equation is then converted into physical spatial distance based on the major and minor axis pixel values combined with camera calibration coefficients, eliminating the interference of camera imaging angle deviation on the cylinder radius parameter. During the generation of the dynamic illumination mask, a sliding window calculates the grayscale difference between the center pixel and its eight neighboring pixels. A two-dimensional Gaussian function, with the sine value of the grayscale gradient direction and the normalized value of the grayscale gradient amplitude as independent variables, outputs a surface reflectivity estimate, quantizing the geometric spatial distribution characteristics of optical reflection into mask values. Before performing element-wise multiplication in the cross-attention layer, the weight matrix is normalized so that the algebraic sum of all elements in the weight matrix equals the number of channels in the spatial defect feature map. This avoids feature value shifts caused by the superposition of weights in the channel dimension and maintains the stability of the residual feature map's numerical distribution when input to the global average pooling layer and flattening layer for mean calculation and dimensional rearrangement. Attached Figure Description
[0020] Figure 1 This is an overall flowchart of an image recognition-based automatic detection and classification system for surface defects in thermos cups.
[0021] Figure 2 This is a flowchart of generating a standardized planar texture map from polar coordinate geometric unfolding units;
[0022] Figure 3 This is a flowchart of the dynamic illumination mask generation unit generating a dynamic illumination mask;
[0023] Figure 4 This is a flowchart of dual-branch feature extraction in a cross-domain attention classification network;
[0024] Figure 5 This is a flowchart of the process of generating residual feature maps by performing feature decoupling processing in the cross-attention layer;
[0025] Figure 6 This is a flowchart showing the classification results output by the global average pooling layer and the fully connected layer. Detailed Implementation
[0026] Please refer to Figure 1This embodiment provides an automatic detection and classification system for surface defects of thermos cups based on image recognition. Deployed in an industrial quality inspection scenario, the system includes an image acquisition unit, a polar coordinate geometric unfolding unit, a dynamic illumination mask generation unit, and a cross-domain attention classification network. The image acquisition unit acquires the original image sequence along the circumference of the thermos cup. The original image sequence consists of multiple frames of single-view images. Each frame corresponds to axial texture information at a fixed angle along the circumference of the thermos cup. The pixel coordinate system of each frame has the upper left corner of the image as the origin, with the horizontal direction to the right as the positive x-axis and the vertical direction downwards as the positive y-axis. The grayscale value of each pixel in the image ranges from 0 to 255. The polar coordinate geometric unfolding unit is connected to the image acquisition unit via a data transmission link. It receives the original image sequence output by the image acquisition unit and, based on the pre-calibrated cylinder radius parameters of the thermos cup, maps the coordinates of each pixel in the original image sequence from the camera pixel coordinate system to the polar coordinate system. The mapped pixels are then aligned and stitched together to generate a standardized planar texture map. The dynamic illumination mask generation unit is connected to the polar coordinate geometric unfolding unit. It receives a normalized planar texture map. Within the spatial domain of the normalized planar texture map, it extracts the gray-level gradient direction and magnitude in the neighborhood range of each pixel. Based on the extracted gray-level gradient parameters, it constructs a surface reflectivity distribution model. According to the preset reflectivity threshold, it divides the pixels into regions and outputs a dynamic illumination mask with the same size as the normalized planar texture map. A cross-domain attention classification network is connected to a dynamic illumination mask generation unit, comprising a texture feature extraction branch, a mask feature extraction branch, and a cross-attention layer. The texture feature extraction branch receives a normalized planar texture map and extracts the texture distribution information in the image through multi-layer convolution operations, outputting a spatial defect feature map. The mask feature extraction branch receives a dynamic illumination mask and extracts the spatial illumination distribution information in the mask through encoding operations, outputting an illumination distribution feature vector. The cross-attention layer receives the spatial defect feature map and the illumination distribution feature vector, applies the illumination distribution feature vector as a suppression weight to the spatial defect feature map, suppresses the feature responses of the corresponding highlight areas in the spatial defect feature map, and generates a residual feature map. The residual feature map is input to a fully connected layer, which outputs the classification result of the surface defects of the thermos cup.
[0027] Specifically, when performing coordinate mapping, the polar coordinate geometric expansion unit first obtains the pre-calibrated camera intrinsic and extrinsic parameters. The camera intrinsic parameters include the equivalent focal length in the x-axis direction. Equivalent focal length in the y-axis direction x-coordinate of principal point y-coordinate of the principal point The camera extrinsic parameters include a 3×3 rotation matrix. Translation vector of 3×1 For any pixel in the original image sequence, its initial x-coordinate is u and its initial y-coordinate is v in the pixel coordinate system. The polar coordinate geometric expansion unit first transforms the coordinates of this pixel into coordinates in the normalized plane of the camera coordinate system through the inverse operation of the camera intrinsic parameter matrix. The transformation process is completed by the following formula:
[0028]
[0029] Where u is the initial x-coordinate in the pixel coordinate system, in pixels; v is the initial y-coordinate in the pixel coordinate system, in pixels. The equivalent focal length along the camera's x-axis, expressed in pixels; The equivalent focal length of the camera along the y-axis, in pixels; The x-coordinate of the camera principal point in the pixel coordinate system, in pixels; x' is the ordinate of the camera principal point in the pixel coordinate system, in pixels; x' is the abscissa of the normalized plane in the camera coordinate system, dimensionless; y' is the ordinate of the normalized plane in the camera coordinate system, dimensionless.
[0030] After completing the transformation to normalized planar coordinates, the polar coordinate geometric expansion unit establishes the transformation relationship between the camera coordinate system and the world coordinate system through camera extrinsic parameters. The Z-axis of the world coordinate system coincides with the central axis of the thermos cup. All points on the cylindrical surface of the thermos cup satisfy the cylindrical surface constraint equation in the world coordinate system. The transformation process between the camera coordinate system and the world coordinate system is completed by the following formula:
[0031]
[0032] in, , , These are three-dimensional coordinates in the world coordinate system, with units of millimeters. , , These are three-dimensional coordinates in the camera coordinate system, in millimeters. Let be the rotation matrix of the camera, a 3×3 orthogonal matrix, dimensionless; Let be the translation vector of the camera, a 3×1 column vector, in millimeters.
[0033] The expression for the constraint equation of the cylindrical surface is:
[0034]
[0035] Where R is the radius parameter of the cylinder of the thermos cup, in millimeters.
[0036] By combining normalized planar coordinates, camera extrinsic parameter transformation relationships, and cylindrical surface constraint equations, the polar coordinate geometric expansion element is used to obtain the 3D coordinates of the pixel in the world coordinate system. Then, the polar coordinate parameters corresponding to the pixel are calculated. The calculation process for the polar coordinate parameters is completed using the following formula:
[0037]
[0038] Where ρ is the polar radius, which is the vertical distance from the point to the Z-axis in the world coordinate system, in millimeters; The polar angle is the angle at which a point in the world coordinate system is located. Projection of a plane and The angle in the positive direction of the axis, in radians; Z is the axial coordinate, corresponding to the world coordinate system. Value, in millimeters.
[0039] After mapping the coordinates of all pixels in the original image sequence, the polar coordinate geometric expansion unit aligns and stitches the mapped pixels. Row alignment is performed with the axial coordinate Z as the row reference and column alignment is performed with the polar angle θ as the column reference. The grayscale values of the multi-view image pixels corresponding to the same polar angle are overwritten according to the acquisition time sequence to finally generate a standardized planar texture map. The row direction of the standardized planar texture map corresponds to the axial direction of the thermos cup, and the column direction corresponds to the circumferential direction of the thermos cup, thus completely restoring the texture information of the entire circumferential surface of the thermos cup.
[0040] Table 1. Mapping Parameters Between Pixel Coordinate System and Polar Coordinate System
[0041] 320 240 0.0000 0.0000 0.0000 35.000 120.000 384 240 0.1000 0.0000 0.1745 35.000 120.000 448 240 0.2000 0.0000 0.3491 35.000 120.000 320 300 0.0000 0.1000 0.0000 35.000 130.000 320 180 0.0000 -0.1000 0.0000 35.000 110.000
[0042] Table 1 shows the correspondence between the initial coordinates in the pixel coordinate system and the mapped polar coordinate parameters, clarifying the numerical relationship of each intermediate parameter in the coordinate transformation process. This ensures that those skilled in the art can completely reproduce the mapping process from the original image pixels to polar coordinates, guaranteeing the accuracy and consistency of geometric unfolding.
[0043] Specifically, after receiving the normalized planar texture map, the dynamic illumination mask generation unit first constructs a sliding window within the spatial domain of the normalized planar texture map. For the center pixel within the sliding window, it calculates the grayscale difference between the center pixel and its eight neighboring pixels. The calculation range of the grayscale difference covers the eight neighboring pixels surrounding the center pixel, resulting in eight grayscale difference values. The dynamic illumination mask generation unit selects the value with the largest absolute value from the eight grayscale differences as the grayscale gradient magnitude of the center pixel, and uses the neighborhood direction corresponding to this largest grayscale difference as the grayscale gradient direction of the center pixel. The calculation process of the grayscale gradient magnitude and direction is completed using the following formula:
[0044]
[0045] Where f(x,y) is the pixel grayscale value at coordinates (x,y) in the normalized planar texture map, and its value ranges from 0 to 255. Let f(x,y) be the grayscale difference between the center pixel f(x,y) and the i-th eight-neighbor pixel, i∈{1,2,...,8}; G is the grayscale gradient magnitude of the center pixel. The grayscale gradient direction of the center pixel is expressed in degrees.
[0046] After calculating the grayscale gradient magnitude and direction of all pixels in the standardized planar texture map, the dynamic illumination mask generation unit constructs a surface reflectivity distribution model. The model uses a two-dimensional Gaussian function as the core calculation unit. The horizontal axis of the two-dimensional Gaussian function is the sine value of the grayscale gradient direction, and the vertical axis is the normalized value of the grayscale gradient magnitude. The normalization process is based on the maximum grayscale gradient magnitude in the standardized planar texture map. The calculation process of the two-dimensional Gaussian function is completed by the following formula:
[0047]
[0048] Where s is the sine value of the gray-level gradient direction. , dimensionless; t is the normalized value of the gray-level gradient magnitude. , The maximum grayscale gradient magnitude in the standardized planar texture map is dimensionless. is the Gaussian standard deviation in dimension s, a fixed constant value, and dimensionless; t is the Gaussian standard deviation in dimension t, a fixed constant value, dimensionless; The correlation coefficient is a two-dimensional Gaussian function, a fixed constant value, and dimensionless.
[0049] The dynamic illumination mask generation unit linearly scales the output value of the two-dimensional Gaussian function, mapping the output value range to the interval between 0 and 1. The mapped value is used as the estimated surface reflectance of the center pixel. The linear scaling process is accomplished by the following formula:
[0050]
[0051] Where r(x,y) is the estimated surface reflectance at coordinates (x,y), and its value ranges from 0 to 1 and is dimensionless; This represents the minimum output value of the two-dimensional Gaussian function within its domain. This represents the maximum output value of the two-dimensional Gaussian function within its domain.
[0052] The dynamic illumination mask generation unit has a preset reflectivity threshold. Pixels with a surface reflectivity estimate greater than the reflectivity threshold are marked as highlight areas. The pixel positions corresponding to the highlight areas are set to a first value, and the pixel positions corresponding to the non-highlight areas are set to a second value. Finally, a dynamic illumination mask is generated. The generation process of the dynamic illumination mask is completed by the following formula:
[0053]
[0054] Where M(x,y) is the dynamic illumination mask assignment at coordinates (x,y); The preset reflectivity threshold has a value range of 0 to 1 and is dimensionless. The first value is 1; The second value is 0. The size of the dynamic lighting mask is exactly the same as the size of the normalized planar texture map, and the value assigned to each pixel position corresponds to whether that position belongs to the specular region.
[0055] Specifically, the texture feature extraction branch of the cross-domain attention classification network receives a standardized planar texture map and extracts texture information from the image layer by layer through multi-layer convolution operations. The convolution operation uses a convolution kernel to perform calculations within a local window of the image, extracting gray-level correlation features and texture distribution features between adjacent pixels. After multi-layer convolution and pooling operations, it outputs a spatial defect feature map, which is a three-dimensional tensor containing three dimensions: height, width, and channels. The channel dimension corresponds to the different types of texture features extracted. The mask feature extraction branch receives a dynamic illumination mask. First, it flattens the two-dimensional dynamic illumination mask into a one-dimensional vector. It encodes the one-dimensional vector through multi-layer fully connected operations, extracting the spatial distribution features of the highlight regions contained in the mask, and outputs an illumination distribution feature vector. The illumination distribution feature vector is a one-dimensional row vector, and its dimension matches the number of channels of the spatial defect feature map output by the texture feature extraction branch.
[0056] The cross-attention layer receives the spatial defect feature map and the illumination distribution feature vector. First, the illumination distribution feature vector is input into the linear transformation layer. The linear transformation layer contains fully connected computation operations, mapping the illumination distribution feature vector into a weight matrix with the same number of channels as the spatial defect feature map. The generation of the weight matrix is accomplished by the following formula:
[0057]
[0058] in, Let be the feature vector of illumination distribution, with a dimension of 1×D, where D is the dimension of the feature vector and is dimensionless. The weight parameter matrix of the linear transformation layer has a dimension of D×C, where C is the number of channels in the spatial defect feature map and is dimensionless. is the bias vector of the linear transformation layer, with a dimension of 1×C and dimensionless; The generated weight matrix has a dimension of 1×C and is dimensionless.
[0059] The cross-attention layer expands the generated weight matrix into a three-dimensional tensor with the same dimensions as the spatial defect feature map. During the expansion process, the weight values corresponding to each channel in the weight matrix are globally copied in the height and width dimensions, so that the expanded three-dimensional tensor perfectly matches the dimensions of the spatial defect feature map. The expansion process is accomplished by the following formula:
[0060]
[0061] in, The extended three-dimensional weight tensor has dimensions H×W×C, where H is the height of the spatial defect feature map and W is the width of the spatial defect feature map, which is dimensionless. This is the normalized weight matrix with a dimension of 1×C and is dimensionless.
[0062] The cross-attention layer performs element-wise multiplication of the extended 3D tensor and the spatial defect feature map along the channel dimension. The result of the multiplication is input to the Sigmoid activation function, which maps the input value to the interval between 0 and 1, generating an activation feature map. The calculation of the activation feature map is accomplished by the following formula:
[0063]
[0064] in, The spatial defect feature map has dimensions H×W×C and is dimensionless. This is an element-wise multiplication operation; Use the Sigmoid activation function; The feature map output by the activation function has dimensions H×W×C and is dimensionless.
[0065] The cross-attention layer performs element-wise addition of the activation feature map and the original spatial defect feature map to generate a residual feature map. The generation of the residual feature map is accomplished by the following formula:
[0066]
[0067] in, This is a residual feature map with dimensions H×W×C, which is dimensionless.
[0068] The residual feature map is input to the fully connected layer. The fully connected layer integrates the feature information in the residual feature map through matrix multiplication and outputs the classification result of the surface defects of the thermos cup. The classification result includes the probability distribution of different defect categories.
[0069] This embodiment, through the aforementioned system structure and data processing flow, converts the original image sequence of the cylindrical surface into a standardized planar texture map without geometric perspective distortion, restoring the true spatial distribution of defects in a two-dimensional plane. Simultaneously, it accurately marks the highlight areas through dynamic illumination masks, and then decouples the physical topological change features and optical reflection change features at the feature extraction level through a cross-attention layer, suppressing the false feature responses corresponding to the highlight areas, thereby realizing the automatic detection and classification of defects on the surface of the thermos cup.
[0070] refer to Figure 2 In a preferred embodiment, the polar coordinate geometric unfolding unit includes a coordinate mapping subunit and an image stitching subunit. The coordinate mapping subunit is connected to the image acquisition device, receives the original image sequence and pre-calibrated camera intrinsic and extrinsic parameter data, obtains the cylindrical radius parameter of the thermos cup and the initial horizontal and vertical coordinates of each pixel in the original image sequence, and calculates the polar radius and polar angle corresponding to each initial horizontal and vertical coordinate with the central axis of the thermos cup as the polar axis. The image stitching subunit is connected to the coordinate mapping subunit, receives the mapped polar coordinate parameters and the corresponding pixel grayscale values, performs row alignment of the mapped pixels according to the polar angle, performs column alignment of the mapped pixels according to the polar radius, and overwrites the grayscale values of the multi-view image pixels corresponding to the same polar angle according to the acquisition sequence to generate a standardized planar texture map. The row direction of the standardized planar texture map corresponds to the axial direction of the thermos cup, and the column direction corresponds to the circumferential direction of the thermos cup.
[0071] Specifically, when obtaining the radius parameter of the thermos cylinder, the coordinate mapping subunit first performs edge extraction on each frame of the original image sequence, extracting the set of pixel coordinates of the thermos's edge in the original image sequence. The edge extraction operation is completed through thresholding and edge detection operators. The resulting set of pixel coordinates includes all pixel coordinates of the top and bottom edges and the left and right edges of the thermos's cylindrical surface. The coordinate mapping subunit then performs ellipse fitting on the extracted pixel coordinate set to generate an edge fitting equation. The ellipse fitting process is completed using the least squares method, and the resulting edge fitting equation is expressed by the following formula:
[0072]
[0073] Where A, B, C, D, E, and F are the coefficients of the ellipse fitting equation, which are dimensionless; , These are the coordinates of the edge pixels in the pixel coordinate system, in pixels.
[0074] The coordinate mapping subunit extracts the major and minor axis pixel values of the edge fitting equation. The major axis pixel value corresponds to the pixel length of the major axis of the ellipse, and the minor axis pixel value corresponds to the pixel length of the minor axis of the ellipse. Based on the preset camera calibration coefficient, the major and minor axis pixel values are converted into physical space distances. The camera calibration coefficient is the conversion ratio between the pixel distance and the physical space distance obtained through the calibration operation. The converted physical space distance corresponds to the circumferential projection length of the cylindrical surface of the thermos cup. The physical space distance is divided by pi to obtain the cylindrical radius parameter of the thermos cup.
[0075] Specifically, after receiving the polar coordinate parameters and corresponding grayscale values of all pixels output by the coordinate mapping subunit, the image stitching subunit first constructs a pixel matrix of a standardized planar texture map. The number of rows in the pixel matrix corresponds to the number of sampling points along the axial direction of the thermos, and the number of columns corresponds to the number of polar angle sampling points along the circumference of the thermos. The polar angle sampling range is 0 to 2π radians, and the sampling interval is a fixed value. Based on the axial coordinate Z corresponding to each pixel, the image stitching subunit assigns the pixel to the corresponding row in the pixel matrix, completing the row alignment operation; based on the polar angle θ corresponding to each pixel, it assigns the pixel to the corresponding column in the pixel matrix, completing the column alignment operation. For multiple pixels corresponding to the same polar angle and the same axial coordinate (i.e., multiple pixels at the same location corresponding to multiple views in the image), the image stitching subunit calculates the acquisition time sequence weight for each pixel. The acquisition time sequence weight is positively correlated with the image acquisition time sequence corresponding to the pixel; the later the acquisition time, the higher the weight value. The grayscale value of the pixel with the latest acquisition time is used as the overwrite grayscale value at that location and written into the pixel matrix of the standardized planar texture map. After completing the alignment and writing operations of all pixels, the image stitching subunit interpolates and fills the blank positions in the pixel matrix using a bilinear interpolation method, ultimately generating a complete standardized planar texture map.
[0076] Table 2 Comparison of Ellipse Fitting Parameters and Cylinder Radius Calculation Results
[0077] Number of samples in the edge pixel coordinate set Fitted ellipse major axis pixel values Fitting ellipse minor axis pixel values Camera calibration coefficient (mm / pixel) Converted physical spatial distance (mm) The calculated cylinder radius parameter R (mm) 1246 700 698 0.314 219.800 35.000 1238 698 696 0.314 219.172 34.900 1252 702 700 0.314 220.428 35.100 1242 700 696 0.314 219.172 34.900
[0078] Table 2 shows the correspondence between the parameters in the ellipse fitting process and the final calculated cylinder radius parameter, clarifying the calibration calculation logic of the cylinder radius parameter. By using ellipse fitting of edge pixels, the interference of camera imaging perspective deviation on the radius parameter is eliminated, ensuring the accuracy of polar coordinate mapping.
[0079] This embodiment achieves accurate mapping and stitching of the original image sequence to the polar coordinate system through the division of labor between the coordinate mapping subunit and the image stitching subunit. It achieves adaptive calibration of the cylinder radius parameter of the thermos cup by fitting the ellipse of the edge pixels. It ensures the texture continuity of multi-view image stitching by setting the acquisition time sequence weight, further eliminates the geometric perspective distortion caused by the curvature of the cylinder surface, and improves the quality of the standardized planar texture map.
[0080] refer to Figure 3 In another preferred embodiment, the dynamic illumination mask generation unit includes a gradient calculation subunit and a model building subunit. The gradient calculation subunit is connected to the polar coordinate geometry unfolding unit, receives a normalized planar texture map, constructs a sliding window on the normalized planar texture map, calculates the grayscale difference between the center pixel and its eight neighboring pixels within the sliding window, uses the largest grayscale difference as the grayscale gradient magnitude of the center pixel, and uses the direction corresponding to the largest grayscale difference as the grayscale gradient direction of the center pixel. The model building subunit is connected to the gradient calculation subunit, receives the grayscale gradient magnitude and grayscale gradient direction, inputs the grayscale gradient magnitude and grayscale gradient direction into a pre-built two-dimensional Gaussian function, outputs the surface reflectance estimate of the center pixel, marks pixels with surface reflectance estimates greater than a preset reflectance threshold as highlight regions, sets the pixel position corresponding to the highlight region to a first value, and sets the pixel position corresponding to the non-highlight region to a second value, thereby generating a dynamic illumination mask.
[0081] Specifically, the sliding window constructed by the gradient calculation subunit is set to a size of 3×3 pixels. The sliding window traverses the normalized planar texture map with a step size of one pixel, covering all pixels in the normalized planar texture map. For each center pixel traversed by the sliding window, the sliding window contains the center pixel and its eight surrounding neighboring pixels, totaling nine pixels. The gradient calculation subunit calculates the grayscale difference between the center pixel and its eight neighboring pixels, obtaining eight grayscale difference values. For center pixels in the edge regions of the normalized planar texture map—that is, when the coordinates of the center pixel are located in the first row, last row, first column, or last column of the normalized planar texture map—the gradient calculation subunit performs zero-padding on the periphery of the normalized planar texture map before constructing the sliding window. The zero-padding operation has a range of one pixel width, ensuring that center pixels in the edge regions can also form a 3×3 pixel sliding window, guaranteeing the consistency of the grayscale gradient calculation logic for all pixels. The gradient calculation subunit selects the value with the largest absolute value from the 8 gray-level differences as the gray-level gradient magnitude of the center pixel, and takes the neighborhood direction corresponding to the largest gray-level difference as the gray-level gradient direction of the center pixel. The neighborhood direction has 8 discrete directions, which correspond to the positions of the 8 neighboring pixels relative to the center pixel, and the interval between each direction is 45 degrees.
[0082] Specifically, the model building subunit pre-builds a two-dimensional Gaussian function with the sine value of the gray-level gradient direction as the horizontal axis independent variable and the normalized value of the gray-level gradient magnitude as the vertical axis independent variable. The normalization value is calculated based on the maximum gray-level gradient magnitude in the normalized planar texture map, uniformly mapping the gray-level gradient magnitude of all pixels to the interval between 0 and 1. The covariance matrix of the two-dimensional Gaussian function is set as a fixed constant value matrix. The diagonal elements of the covariance matrix correspond to the squares of the standard deviations of the horizontal and vertical axes, respectively, and the off-diagonal elements correspond to the covariance of the two dimensions. The value of the fixed constant value matrix is determined through pre-experiments to ensure that the output of the two-dimensional Gaussian function can accurately reflect the changes in surface reflectivity. The model building subunit inputs the sine value of the gray-level gradient direction and the normalized gray-level gradient magnitude into the two-dimensional Gaussian function to obtain the original output value of the two-dimensional Gaussian function. The original output value is then linearly scaled to map the output value range to the interval between 0 and 1. The mapped output value is used as the estimated surface reflectivity of the central pixel. The model building subunit has a preset reflectivity threshold, the value of which is determined through pre-experimentation. It can accurately distinguish the reflectivity difference between highlight areas and non-highlight areas. The model building subunit marks pixels with surface reflectivity estimates greater than the reflectivity threshold as highlight areas, sets the pixel positions corresponding to the highlight areas to the first value, and sets the pixel positions corresponding to the non-highlight areas to the second value, and finally generates a dynamic lighting mask that is completely consistent with the size of the standardized planar texture map.
[0083] Table 3 Correspondence between gray-level gradient parameters and surface reflectance estimates
[0084] (120,240) 220 220 90 1.0000 0.8627 0.1592 0.9200 1 (150,300) 180 180 45 0.7071 0.7059 0.1287 0.7400 1 (200,180) 50 50 180 0.0000 0.1961 0.0318 0.1800 0 (250,320) 30 30 270 -1.0000 0.1176 0.0191 0.1000 0 (180,260) 200 200 135 0.7071 0.7843 0.1451 0.8400 1
[0085] Table 3 shows the calculation process of gray-level gradient parameters, the generation logic of surface reflectance estimation and the correspondence between the mask assignment, clarifies the basis for marking the highlight area, and ensures that the dynamic illumination mask can accurately reflect the distribution of highlight areas in the standardized planar texture map.
[0086] This embodiment achieves unified calculation of grayscale gradient parameters of all pixels in the image through a 3×3 sliding window of the gradient calculation subunit. Zero-padding at the edges ensures the consistency of calculation for pixels in the edge region. A pre-built two-dimensional Gaussian function is used to achieve accurate estimation of surface reflectivity. The resulting dynamic illumination mask can accurately mark the spatial distribution of the highlight region, providing an accurate basis for subsequent feature suppression processing.
[0087] refer to Figure 4In another preferred embodiment, the cross-domain attention classification network includes a texture feature extraction branch and a mask feature extraction branch. The texture feature extraction branch comprises three convolutional layers and two pooling layers connected in series. A normalized planar texture map is input to the first convolutional layer. The first pooling layer is connected between the first and second convolutional layers. The second pooling layer is connected between the second and third convolutional layers. The third convolutional layer outputs a spatial defect feature map. The mask feature extraction branch comprises two fully connected layers. A dynamic illumination mask is flattened into a one-dimensional vector and input to the first fully connected layer. The output of the first fully connected layer is connected to the input of the second fully connected layer. The second fully connected layer outputs an illumination distribution feature vector. The cross-attention layer of the cross-domain attention classification network receives a spatial defect feature map and an illumination distribution feature vector. The illumination distribution feature vector is then input into a linear transformation layer, which includes fully connected computation operations. This linear transformation layer maps the illumination distribution feature vector into a weight matrix with the same number of channels as the spatial defect feature map and a row vector format. The cross-attention layer expands the weight matrix into a three-dimensional tensor with the same length and width as the spatial defect feature map. It then performs element-wise multiplication of the three-dimensional tensor and the spatial defect feature map along the channel dimension. The result of the multiplication is input into a Sigmoid activation function. Finally, the output of the Sigmoid activation function is added element-wise to the spatial defect feature map to generate a residual feature map. The cross-domain attention classification network also includes a global average pooling layer and a flattening layer. The global average pooling layer connects the cross-attention layer and the flattening layer. The global average pooling layer calculates the mean of the two-dimensional matrix in each channel of the residual feature map, compressing the two-dimensional matrix in each channel into a single floating-point number to generate a one-dimensional feature vector. The flattening layer rearranges the dimensions of the one-dimensional feature vector, converting it into a one-dimensional column vector. The fully connected layer receives the one-dimensional column vector and outputs a probability distribution vector containing scratch category, dent category and no defect category after matrix multiplication.
[0088] Specifically, the first convolutional layer in the texture feature extraction branch is configured with a 7×7 pixel kernel and a stride of two pixels. The convolution operation uses the same padding method to ensure that the size of the feature map after convolution is in a fixed ratio to the size of the input image. The output channels of the first convolutional layer are set to 64. After the convolution operation, a ReLU activation function is applied to perform a non-linear transformation on the output feature values. The first pooling layer is configured as max pooling with a 2×2 pixel pooling window and a stride of two pixels. This performs feature dimensionality reduction on the feature map output by the first convolutional layer, retaining local maxima features and removing redundant feature information. The second convolutional layer is configured as a dilated convolution with a kernel size of 5×5 pixels and a stride of one pixel. The dilation rate is set to 2, and the padding method is the same. The output channels of the second convolutional layer are set to 128. After the convolution operation, a ReLU activation function is applied. The dilated convolution operation expands the receptive field of the convolutional kernel without increasing the computational cost, enabling it to capture a wider range of texture-related features. The second pooling layer is configured as a max pooling operation with a pooling window size of 3×3 pixels and a stride of two pixels. This further reduces the dimensionality of the feature map output by the second convolutional layer, compressing the size of the feature map. The third convolutional layer is configured as a depthwise separable convolution operation with a kernel size of 3×3 pixels and a stride of one pixel. The depthwise separable convolution operation consists of two steps: depthwise convolution and pointwise convolution. The depthwise convolution performs convolution operations on each input channel separately, with a kernel size of 3×3 pixels and a stride of one pixel. The pointwise convolution uses a convolution operation with a kernel size of 1×1 pixels. The feature maps output by the depthwise convolution are fused along the channel dimension. The number of output channels of the third convolutional layer is set to 256. After the convolution operation, the ReLU activation function is applied. The depthwise separable convolution operation reduces the amount of computation and the number of parameters while ensuring the ability to extract features. The output of the third convolutional layer is the spatial defect feature map, which has dimensions of H×W×256, where H is the height of the feature map, W is the width of the feature map, and 256 is the number of channels.
[0089] Specifically, the mask feature extraction branch receives a dynamic illumination mask. First, it flattens the two-dimensional dynamic illumination mask into a one-dimensional vector in row-major order. The dimension of the one-dimensional vector equals the total number of pixels in the dynamic illumination mask. This flattened one-dimensional vector is input to the first fully connected layer. The input dimension of the first fully connected layer is the same as the dimension of the one-dimensional vector, and the output dimension is set to 1024. After the fully connected operation, a ReLU activation function is applied to encode the input one-dimensional vector for the first time, extracting the basic distribution features from the mask. The output of the first fully connected layer is input to the second fully connected layer. The input dimension of the second fully connected layer is 1024, and the output dimension is set to 256, the same as the number of channels in the spatial defect feature map. After the fully connected operation, a ReLU activation function is applied to encode the features a second time, extracting the higher-order features of the spatial distribution of highlight regions in the mask. The output of the second fully connected layer is the illumination distribution feature vector, which is a 1×256 row vector.
[0090] refer to Figure 5 Specifically, the linear transformation layer of the cross-attention layer includes a weight parameter matrix and a bias vector. The number of rows in the weight parameter matrix is equal to the dimension of the illumination distribution feature vector, i.e., 256. The number of columns in the weight parameter matrix is equal to the number of channels in the spatial defect feature map, i.e., 256. The dimension of the bias vector is 1×256. During matrix multiplication, the illumination distribution feature vector is used as the left multiplication vector, the weight parameter matrix is used as the right multiplication matrix, and the product result is added to the bias vector to generate the weight matrix, which has a dimension of 1×256. Before performing element-wise multiplication, the cross-attention layer normalizes all elements in the weight matrix. The normalization process is completed using the following formula:
[0091]
[0092] in, This is the normalized weight matrix, with a dimension of 1×C and dimensionless. Let C be the algebraic sum of all elements in the weight matrix; C is the number of channels in the spatial defect feature map. Normalization ensures that the algebraic sum of all elements in the weight matrix equals the number of channels in the spatial defect feature map, thus avoiding feature value shifts caused by the summation of weights in the channel dimension and maintaining the stability of the feature value distribution.
[0093] The cross-attention layer expands the normalized weight matrix into a 3D tensor with the same dimensions as the spatial defect feature map. During the expansion, the weight values corresponding to each channel in the weight matrix are globally copied in the height and width dimensions, making the dimensions of the expanded 3D tensor H×W×256, perfectly matching the dimensions of the spatial defect feature map. The cross-attention layer performs element-wise multiplication of the expanded 3D tensor and the spatial defect feature map along the channel dimensions. The result of the multiplication is input to the Sigmoid activation function, which maps the input values to the interval between 0 and 1, generating an activation feature map. The cross-attention layer then performs element-wise addition of the activation feature map and the original spatial defect feature map to generate a residual feature map. The dimensions of the residual feature map are exactly the same as those of the spatial defect feature map, H×W×256.
[0094] refer to Figure 6 Specifically, the global average pooling layer receives the residual feature map output by the cross-attention layer, calculates the mean of the two-dimensional matrix in each channel of the residual feature map, and compresses the H×W two-dimensional matrix in each channel into a single floating-point number. The mean calculation process is completed by the following formula:
[0095]
[0096] in, This is a one-dimensional feature vector output by global average pooling, with a dimension of 1×C and no dimension. This represents the feature value at coordinate (h, w) of the c-th channel in the residual feature map. The output of the global average pooling layer is a one-dimensional feature vector with dimensions 1×256.
[0097] The flattening layer receives the one-dimensional feature vector output by the global average pooling layer and rearranges its dimensions, converting the 1×256 row vector into a 256×1 one-dimensional column vector to ensure matching the input dimension of the subsequent fully connected layers. The fully connected layer receives the one-dimensional column vector output by the flattening layer. The fully connected layer has an input dimension of 256 and an output dimension of 3. After matrix multiplication and the Softmax activation function, it outputs a probability distribution vector containing scratch, dent, and no-defect categories. The sum of the three elements in the probability distribution vector is 1, corresponding to the probability that the input image belongs to one of the three categories. The category with the highest probability value is taken as the final classification result.
[0098] Table 4. Correspondence between computational dimensions of each layer in the cross-domain attention classification network
[0099] Texture feature extraction branch - Convolution 1 512×1024×3 7×7 convolution, stride 2, output channels 64, ReLU activation 256×512×64 Texture feature extraction branch - pooling 1 256×512×64 2×2 max pooling, step size 2 128×256×64 Texture feature extraction branch - Convolution 2 128×256×64 5×5 dilated convolution, stride 1, dilation 2, output channels 128, ReLU activation 128×256×128 Texture feature extraction branch - pooling 2 128×256×128 3×3 max pooling, step size 2 64×128×128 Texture feature extraction branch - Convolution 3 64×128×128 3×3 depthwise separable convolution, stride 1, 256 output channels, ReLU activation 64×128×256 Mask feature extraction branch - fully connected 1 524288×1 Input dimension 524288, output dimension 1024, ReLU activation 1024×1 Mask feature extraction branch - Fully connected 2 1024×1 Input dimension 1024, output dimension 256, ReLU activation 256×1 Cross-attention layer - linear transformation 1×256 The weight matrix is 256×256, and the bias is 1×256. 1×256 Cross-attention layer - normalization 1×256 The sum was normalized to 256 1×256 Cross-attention layer - tensor expansion 1×256 Expanded to 64×128×256 64×128×256 Cross-attention layer - element-wise product 64×128×256 (two) Element-wise multiplication of channel dimensions, sigmoid activation 64×128×256 Cross-attention layer - residual addition 64×128×256 (two) Adding elements one by one 64×128×256 Global average pooling layer 64×128×256 Calculation of global mean within the channel 1×256 Flattening layer 1×256 Dimensional rearrangement 256×1 Output fully connected layer 256×1 Input dimension 256, output dimension 3, Softmax activation 3×1
[0100] Table 4 shows the correspondence between the input tensor dimensions, core operational parameters, and output tensor dimensions of each layer of the cross-domain attention classification network. It clarifies the flow of feature data in the network and the dimension matching logic, ensuring that those skilled in the art can fully reproduce the network structure and realize the corresponding feature extraction and classification functions.
[0101] This embodiment achieves accurate extraction of defect features from standardized planar texture maps through multi-layer convolution and pooling operations in the texture feature extraction branch. It effectively extracts illumination distribution features from dynamic illumination masks through fully connected encoding operations in the mask feature extraction branch. It accurately suppresses false features in highlight areas through weight mapping, normalization, and residual calculation in the cross-attention layer. It accurately classifies defect categories through global average pooling layers, flattening layers, and output fully connected layers. At the same time, it maintains the stability of feature value distribution and ensures the accuracy of classification results through normalization of the weight matrix.
Claims
1. An automatic detection and classification system for surface defects of thermos cups based on image recognition, characterized in that, It includes an image acquisition device, a polar coordinate geometric unfolding unit, a dynamic illumination mask generation unit, and a cross-domain attention classification network; The image acquisition device is used to acquire the original image sequence in the circumferential direction of the thermos cup; The polar coordinate geometric unfolding unit is connected to the image acquisition device. Based on the pre-calibrated cylinder radius parameter of the thermos cup, the original image sequence is mapped from the camera pixel coordinate system to the polar coordinate system and stitched together to generate a standardized planar texture map. The dynamic illumination mask generation unit is connected to the polar coordinate geometric expansion unit. It extracts the direction and magnitude of the gray-level gradient of the pixel neighborhood in the spatial domain of the standardized planar texture map, constructs a surface reflectivity distribution model, and divides and outputs the dynamic illumination mask according to the reflectivity threshold. The cross-domain attention classification network is connected to the dynamic illumination mask generation unit and includes a texture feature extraction branch, a mask feature extraction branch, and a cross-attention layer. The texture feature extraction branch performs convolution operations on the standardized planar texture map to output a spatial defect feature map. The mask feature extraction branch encodes the dynamic illumination mask to output an illumination distribution feature vector. The cross-attention layer uses the illumination distribution feature vector as a suppression weight on the spatial defect feature map to generate a residual feature map. The classification result of the surface defects of the thermos cup is output through a fully connected layer.
2. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 1, characterized in that, The polar coordinate geometric expansion unit includes a coordinate mapping subunit and an image stitching subunit; The coordinate mapping subunit obtains the cylindrical radius parameter of the thermos cup and the initial horizontal and vertical coordinates of each pixel in the original image sequence, and calculates the polar radius and polar angle corresponding to each initial horizontal and vertical coordinate with the central axis of the thermos cup as the polar axis. The image stitching subunit performs row alignment on the mapped pixels based on the polar angle and column alignment on the mapped pixels based on the polar diameter. The multi-view image pixels corresponding to the same polar angle are overwritten with grayscale values according to the acquisition sequence to generate the standardized planar texture map. The row direction of the standardized planar texture map corresponds to the axial direction of the thermos cup, and the column direction corresponds to the circumferential direction of the thermos cup.
3. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 1, characterized in that, The dynamic illumination mask generation unit includes a gradient calculation subunit and a model building subunit; The gradient calculation subunit constructs a sliding window on the standardized planar texture map, calculates the gray-level difference between the center pixel and the eight neighboring pixels within the sliding window, takes the largest gray-level difference as the gray-level gradient magnitude of the center pixel, and takes the direction corresponding to the largest gray-level difference as the gray-level gradient direction of the center pixel. The model construction subunit inputs the gray-level gradient magnitude and the gray-level gradient direction into a pre-built two-dimensional Gaussian function, outputs the surface reflectance estimate of the center pixel, marks the pixels whose surface reflectance estimate is greater than a preset reflectance threshold as highlight regions, sets the pixel position corresponding to the highlight region to a first value, and sets the pixel position corresponding to the non-highlight region to a second value, thereby generating the dynamic illumination mask.
4. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 1, characterized in that, The cross-domain attention classification network includes a texture feature extraction branch and a mask feature extraction branch; The texture feature extraction branch includes three convolutional layers and two pooling layers connected in series. The normalized planar texture map is input to the first convolutional layer. The first pooling layer is connected between the first convolutional layer and the second convolutional layer. The second pooling layer is connected between the second convolutional layer and the third convolutional layer. The third convolutional layer outputs the spatial defect feature map. The mask feature extraction branch includes two fully connected layers. The dynamic illumination mask is flattened into a one-dimensional vector and then input to the first fully connected layer. The output of the first fully connected layer is connected to the input of the second fully connected layer. The second fully connected layer outputs the illumination distribution feature vector.
5. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 1, characterized in that, The cross-attention layer receives the spatial defect feature map and the illumination distribution feature vector, inputs the illumination distribution feature vector into the linear transformation layer, the linear transformation layer contains fully connected computation operations, and maps the illumination distribution feature vector into a weight matrix with the same number of channels as the spatial defect feature map and a size of row vector; The cross-attention layer expands the weight matrix into a three-dimensional tensor with the same length and width as the spatial defect feature map, performs element-wise multiplication of the three-dimensional tensor and the spatial defect feature map in the channel dimension, inputs the product result into the Sigmoid activation function, and performs element-wise addition of the output of the Sigmoid activation function with the spatial defect feature map to generate the residual feature map.
6. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 1, characterized in that, The cross-domain attention classification network also includes a global average pooling layer and a flattening layer; The global average pooling layer is connected between the cross attention layer and the flattening layer. The global average pooling layer calculates the mean of the two-dimensional matrix in each channel of the residual feature map, compresses the two-dimensional matrix in each channel into a single floating-point number, and generates a one-dimensional feature vector. The flattening layer rearranges the dimensions of the one-dimensional feature vector, converting it into a one-dimensional column vector. The fully connected layer receives the one-dimensional column vector and outputs a probability distribution vector containing scratch category, dent category, and no-defect category through matrix multiplication.
7. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 2, characterized in that, The process of obtaining the cylinder radius parameter of the thermos cup by the coordinate mapping subunit includes: extracting the set of pixel coordinates of the edge of the thermos cup in the original image sequence, performing ellipse fitting on the set of pixel coordinates to generate an edge fitting equation, extracting the major axis pixel value and the minor axis pixel value of the edge fitting equation, converting the major axis pixel value and the minor axis pixel value into physical space distance according to the preset camera calibration coefficient, and dividing the physical space distance by pi to obtain the cylinder radius parameter of the thermos cup. In the image stitching subunit, when the same polar angle corresponds to pixels of multi-view images, the acquisition timing weight of each pixel is calculated, and the gray value of the pixel with the latest acquisition timing is used as the gray value to be overwritten.
8. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 3, characterized in that, The size of the sliding window is set to 3×3 pixels; In the gradient calculation subunit, for the center pixel of the edge region of the normalized planar texture map, the sliding window is constructed after zeroing is added around the normalized planar texture map; In the model construction subunit, the horizontal axis independent variable of the two-dimensional Gaussian function is the sine value of the gray-level gradient direction, and the vertical axis independent variable is the normalized value of the gray-level gradient magnitude. The covariance matrix of the two-dimensional Gaussian function is set as a fixed constant value matrix. The output value range of the pre-built two-dimensional Gaussian function is mapped to the interval between 0 and 1 through a linear scaling operation. The mapped output value is used as the estimated surface reflectivity.
9. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 5, characterized in that, The linear transformation layer includes a weight parameter matrix and a bias vector. The number of rows in the weight parameter matrix is equal to the dimension of the illumination distribution feature vector, and the number of columns in the weight parameter matrix is equal to the number of channels in the spatial defect feature map. When performing matrix multiplication, the illumination distribution feature vector is used as the left multiplication vector, the weight parameter matrix is used as the right multiplication matrix, and the product result is added to the bias vector to generate the weight matrix. Before performing the element-wise product operation, all elements in the weight matrix are normalized so that the algebraic sum of all elements in the weight matrix is equal to the number of channels in the spatial defect feature map.
10. The automatic detection and classification system for surface defects of thermos cups based on image recognition according to claim 4, characterized in that, The first convolutional layer in the texture feature extraction branch is configured as a convolution operation with a kernel size of 7×7 pixels and a stride of 2 pixels, the second convolutional layer is configured as a dilated convolution operation with a kernel size of 5×5 pixels and a stride of 1 pixel, and the third convolutional layer is configured as a depth-separable convolution operation with a kernel size of 3×3 pixels and a stride of 1 pixel. Both the first and second pooling layers are configured for max pooling. The pooling window size of the first pooling layer is 2×2 pixels with a stride of 2 pixels, and the pooling window size of the second pooling layer is 3×3 pixels with a stride of 2 pixels.