Scratch detection method, device and equipment and computer readable storage medium

By removing the background and dynamically enhancing images with smoke in the mouth, and using a self-attention mechanism and a feature pyramid network for scratch detection, the problem of low accuracy in scratch detection in existing technologies is solved, and high-precision scratch recognition is achieved.

CN121120606APending Publication Date: 2025-12-12CHINA TOBACCO LOGISTICS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511400464.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-28
Publication Date
2025-12-12

AI Technical Summary

Technical Problem

Existing technologies have low accuracy in detecting abnormal scratches from cigarette smoke, making it difficult to effectively identify and detect abnormal scratches.

Method used

By acquiring images of the target mouth containing smoke, removing the background, and using a target scratch detection model to determine the association weights between different pixel regions, the scratch features are dynamically enhanced based on the association weights, and scratch detection is performed. A self-attention mechanism, a feature pyramid network, and a path aggregation network are used for multi-scale fusion, and a deep decoupled detection head is combined to predict the scratch location and category confidence.

Benefits of technology

It improves the accuracy of scratch detection, effectively identifies and detects external scratches caused by cigarette smoke in the mouth, and dynamically enhances the scratched area, thereby improving the accuracy of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121120606A_ABST
    Figure CN121120606A_ABST
Patent Text Reader

Abstract

The invention discloses a scratch detection method, device and equipment and a computer readable storage medium, and is applied to the technical field of image detection.The method comprises the steps that a target buccal cigarette image is obtained; the background of the target buccal cigarette image is removed, and a buccal cigarette image with the background removed is obtained; and determining an association weight between different pixel areas in the background-removed buccal cigarette image by using the target scratch detection model, performing dynamic enhancement on scratch features based on the association weight, and performing scratch detection on the dynamically enhanced buccal cigarette image to obtain a scratch detection result. Compared with the prior art that the scratches on the buccal cigarette cannot be detected, the method has the advantages that the abnormal detection can be performed on the appearance scratches of the buccal cigarette based on the target scratch detection model, and the model can dynamically enhance the scratch part, so that the scratch detection accuracy is relatively high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image detection, and in particular to a scratch detection method, apparatus, device, and computer-readable storage medium. Background Technology

[0002] Oral cigarettes are smokeless and odorless. The nicotine in oral cigarettes is absorbed through the oral mucosa, providing the same effects as traditional cigarettes. In the production process, a layer of highly permeable white mesh cloth contains white powder. The white powder is mechanically filled, and the ends of the white mesh cloth are thermally compressed to tightly encapsulate the powder. However, during the actual production process, the fixed and automated nature of the machinery, along with the flexibility of the white mesh cloth, leads to a series of abnormal mechanical processing phenomena. Currently, the accuracy of scratch detection is low due to the reliance on manual inspection.

[0003] It is evident that improving the accuracy of detecting abnormal scratches from cigarette smoke is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] In view of this, the purpose of the present invention is to provide a scratch detection method, apparatus, device and computer-readable storage medium, which solves the technical problem of low accuracy in detecting abnormal scratches when smoking in the mouth in the prior art.

[0005] To solve the above-mentioned technical problems, the present invention provides a scratch detection method, comprising:

[0006] Acquire an image of the target's mouth containing smoke;

[0007] The background of the target image with smoke in the mouth is removed to obtain an image with smoke in the mouth without background.

[0008] The association weights between different pixel regions in the background-removed mouth-and-smoke image are determined using a target scratch detection model. Based on these association weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain the scratch detection results.

[0009] Optionally, the background of the target image with smoke in the mouth is removed to obtain a background-removed image with smoke in the mouth, including:

[0010] Extract the pixel values ​​of the R, G, and B color channels of the target mouth-smoke image;

[0011] The threshold ranges corresponding to the pixel values ​​of the three color channels R, G, and B are dynamically adjusted until the area with smoke in the mouth and the background area in the target image with smoke in the mouth are distinguished to the greatest extent. Then, the background area is processed into the target color to obtain the image with smoke in the mouth with the background removed. The target color is different from the color of the area with smoke in the mouth.

[0012] Optionally, before determining the correlation weights between different pixel regions in the background-removed smoke-filled image using a target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the method further includes:

[0013] The target image containing smoke is converted into a grayscale image, and the grayscale image is then subjected to Gaussian filtering to obtain a Gaussian-processed image.

[0014] Determine the gradient values ​​of each pixel in the Gaussian-processed image in the horizontal and vertical directions, and calculate the gradient intensity and gradient direction of each pixel based on the gradient values ​​in the horizontal and vertical directions;

[0015] Traverse each pixel in the target mouth-smoke image and compare the gradient intensity of the current pixel with the gradient intensity of the adjacent pixels on both sides along the corresponding gradient direction.

[0016] If the gradient intensity of the current pixel is greater than the gradient intensity of the two adjacent pixels, then the pixel is retained as an edge candidate point, and the gradient-processed image with smoke in the mouth is obtained.

[0017] Set a maximum gradient magnitude threshold and a minimum gradient magnitude threshold, and compare the gradient intensity of each pixel in the gradient-processed smoke-filled image with the maximum gradient magnitude threshold and the minimum gradient magnitude threshold;

[0018] If the gradient intensity of a pixel is greater than the maximum gradient magnitude threshold, it is marked as a strong edge pixel; if the gradient intensity of a pixel is between the maximum gradient magnitude threshold and the minimum gradient magnitude threshold, it is marked as a weak edge pixel; if the gradient intensity of a pixel is less than the minimum gradient magnitude threshold, it is discarded.

[0019] Traverse all the weak edge pixels and check whether there are strong edge pixels within the 8 neighboring pixels corresponding to each weak edge pixel;

[0020] If it exists, the current weak edge pixel is changed to a strong edge pixel and retained; otherwise, it is discarded to obtain the complete outer contour of the mouth holding smoke composed of the strong edge pixels.

[0021] Based on the coordinate point set of the complete outer contour of the smoke in the mouth, the smoke-in-mouth region in the smoke-in-mouth image with the background removed is replaced with the smoke-in-mouth region in the target smoke-in-mouth image to obtain the target smoke-in-mouth image with the background removed, and scratch detection is performed based on the target smoke-in-mouth image with the background removed.

[0022] Optionally, a target scratch detection model is used to determine the correlation weights between different pixel regions in the background-removed mouth-and-smoke image. Based on these correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain scratch detection results, including:

[0023] The association weights between different regions in the background-removed smoke-filled image are calculated using a self-attention mechanism to dynamically enhance the representation of scratch features, resulting in a dynamically enhanced image.

[0024] The dynamically enhanced image is fused at multiple scales using a feature pyramid network and a path aggregation network to obtain an enhanced feature map for prediction.

[0025] The enhanced feature map used for prediction is processed by the decoupled detection head to predict the location bounding box and class confidence of the scratch, and output the scratch detection result; the scratch detection result includes the location coordinates, confidence score and class label of the scratch.

[0026] Optionally, before determining the correlation weights between different pixel regions in the background-removed smoke-filled image using a target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the method further includes:

[0027] The background-removed image of a person holding a cigarette is subjected to image enhancement processing to obtain an enhanced target image of a person holding a cigarette; wherein, the image enhancement processing includes at least one of brightness and contrast adjustment, hue and saturation adjustment, and RGB channel offset adjustment;

[0028] Accordingly, the correlation weights between different pixel regions in the background-removed mouth-and-smoke image are determined using a target scratch detection model. Based on these correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain scratch detection results, including:

[0029] The target scratch detection model is used to determine the correlation weights between different pixel regions in the enhanced target smoke-in-mouth image. Based on the correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced smoke-in-mouth image to obtain the scratch detection result.

[0030] Optionally, before determining the correlation weights between different pixel regions in the background-removed smoke-filled image using a target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the method further includes:

[0031] A training dataset and a test dataset consisting of images of people holding cigarettes in their mouths are obtained, and an attention-based deep learning detection model is iteratively trained based on the training dataset and the test dataset.

[0032] After each training round, the recognition rates corresponding to the training dataset and the test dataset are determined respectively.

[0033] When the set iteration conditions are met, the optimal training parameters with the highest recognition rate are used as the parameters of the deep learning detection model based on the attention mechanism to obtain the target scratch detection model.

[0034] Optionally, the target scratch detection model is a deep learning model based on window attention mechanism, and the feature pyramid network in the target scratch detection model is a weighted bidirectional feature pyramid network. It also adopts a deep decoupled detection head structure, separates the classification and regression tasks into different branch networks, and introduces a coordinate attention mechanism into the regression branch.

[0035] The present invention also provides a scratch detection method, comprising:

[0036] The image acquisition module is used to acquire images of the target mouth containing smoke.

[0037] The background removal module is used to remove the background of the target image of a person holding a cigarette in their mouth, so as to obtain an image of a person holding a cigarette in their mouth with the background removed.

[0038] The scratch detection module is used to determine the correlation weights between different pixel regions in the background-removed smoke-holding image using a target scratch detection model, dynamically enhance the scratch features based on the correlation weights, and perform scratch detection on the dynamically enhanced smoke-holding image to obtain scratch detection results.

[0039] The present invention also provides a scratch detection device, comprising:

[0040] Memory, used to store computer programs;

[0041] A processor for executing the computer program to implement the steps of the scratch detection method described above.

[0042] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described scratch detection method.

[0043] The present invention also provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the above-described scratch detection method.

[0044] As can be seen, the present invention obtains a target image of a mouth holding smoke; removes the background of the target image of a mouth holding smoke to obtain a background-removed image of a mouth holding smoke; uses a target scratch detection model to determine the correlation weights between different pixel regions in the background-removed image of a mouth holding smoke; dynamically enhances the scratch features based on the correlation weights; and performs scratch detection on the dynamically enhanced image of a mouth holding smoke to obtain scratch detection results.

[0045] The beneficial effects of this invention are as follows: compared with the current inability to detect scratches, this invention can detect anomalies in the appearance of cigarettes held in the mouth based on a target scratch detection model, and the model can dynamically enhance the scratched part, so the scratch detection accuracy is high.

[0046] In addition, the present invention also provides a scratch detection device, equipment, and computer-readable storage medium, which also have the above-mentioned beneficial effects. Attached Figure Description

[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0048] Figure 1 A flowchart of a scratch detection method provided in an embodiment of the present invention;

[0049] Figure 2 This is a schematic diagram of a gradient segmentation direction;

[0050] Figure 3 A schematic diagram of a sampling method provided in an embodiment of the present invention;

[0051] Figure 4 This is a schematic diagram of an IOU according to an embodiment of the present invention;

[0052] Figure 5 A schematic diagram illustrating the diagonal distance and the distance between the center points of the two frames is provided in an embodiment of the present invention.

[0053] Figure 6 A flowchart illustrating a scratch detection method provided in an embodiment of the present invention;

[0054] Figure 7This is a schematic diagram of the structure of a scratch detection device provided in an embodiment of the present invention;

[0055] Figure 8 This is a schematic diagram of a scratch detection device provided in an embodiment of the present invention. Detailed Implementation

[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0057] Please refer to Figure 1 , Figure 1 A flowchart illustrating a scratch detection method provided in an embodiment of the present invention. The method may include:

[0058] S101, Obtain the target image of the mouth containing smoke.

[0059] The steps in this embodiment can be performed by a designated electronic device, which can be a server, a portable terminal, or other forms. The target image of the smoke in the mouth in this embodiment is captured by a sensor-triggered image capture function, and the captured image includes a conveyor belt, the smoke in the mouth, and some impurities.

[0060] S102, remove the background from the target image of the mouth holding smoke to obtain an image of the mouth holding smoke with the background removed.

[0061] In this embodiment, the background refers to the area excluding the target area containing smoke. This embodiment does not limit the specific method for background removal. For example, this embodiment may remove the background based on color space threshold segmentation. Alternatively, this embodiment may also remove the background based on deep semantic segmentation.

[0062] It should be further explained that, based on any of the above embodiments, the above-mentioned removal of the background image of the target smoke-holding image to obtain a smoke-holding image with the background removed may include: extracting the pixel values ​​of the R, G, and B color channels of the target smoke-holding image; dynamically adjusting the threshold range of each color channel, iteratively testing until the smoke-holding area and the background area in the target smoke-holding image are most distinguishable, and then processing the background area to the target color to obtain a smoke-holding image with the background removed; wherein, the target color is different from the color of the smoke-holding area. This embodiment does not limit the specific target color; for example, the target color in this embodiment can be black, purple, etc. It can be understood that the smoke-holding image is composed of the three primary colors RGB, and the three color channels of RGB correspond to the three base colors red, green, and blue, respectively. The digital threshold range of the three color channels of RGB is... The image values ​​of R, G, and B are each composed of pixel values ​​ranging from 0 to 256. The OpenCV (Open Source Computer Vision Library) image processing tool is used to extract these values, and the threshold adjustment function is employed to continuously adjust the range values ​​of the three R, G, and B channels until the image contains only the background image of a person with a mouth holding smoke (for example, finding the minimum and maximum values ​​of the three channels to form a threshold range). , , This makes the area outside the cigarette in the mouth appear as a black region. Extracting using the R, G, and B channels might remove abnormal colors like scratches from the cigarette. Therefore, it's necessary to extract the outer contour of the cigarette in the mouth, replace the points on the outer contour with those in the original image, and extract the corresponding coordinates from the original image along the outer contour coordinates. This allows us to extract the image of the cigarette in the mouth from the original image.

[0063] S103, the correlation weights between different pixel regions in the smoke-filled image with background removed are determined using the target scratch detection model. The scratch features are dynamically enhanced based on the correlation weights, and scratch detection is performed on the dynamically enhanced smoke-filled image to obtain the scratch detection results.

[0064] In this embodiment, the process of the target scratch detection model detecting scratches in a smoke-filled image with the background removed can include determining the association weights between different pixel regions in the smoke-filled image with the background removed, dynamically enhancing the scratch features based on the association weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result. Specifically, the process can include: extracting features from the input image using the attention mechanism module in the target scratch detection model; calculating the association weights between different regions in the image using a self-attention mechanism to dynamically enhance the representation of scratch features; fusing the extracted features at multiple scales using a Feature Pyramid Network (FPN) and a Path Aggregation Network (PAN) to obtain an enhanced feature map for prediction; processing the fused feature map using a decoupled detection head to predict the scratch's location bounding box and class confidence in parallel; and outputting the scratch detection result, including the scratch's location coordinates, confidence score, and class label.

[0065] It should be further explained that, based on any of the above embodiments, the above-described method of using a target scratch detection model to determine the correlation weights between different pixel regions in a smoke-filled image with the background removed, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain scratch detection results may include:

[0066] S1031, The association weights between different regions in the smoke-filled image with background removed are calculated using a self-attention mechanism to dynamically enhance the representation of scratch features and obtain a dynamically enhanced image.

[0067] S1032, the dynamic enhancement image is fused at multiple scales through the feature pyramid network and the path aggregation network to obtain the enhancement feature map for prediction;

[0068] S1033, the enhanced feature map used for prediction is processed by the decoupled detection head to predict the location bounding box and category confidence of the scratch, and output the scratch detection result; the scratch detection result includes the location coordinates, confidence score and category label of the scratch.

[0069] In this embodiment, the pyramid specifically refers to the multi-scale feature maps generated by the backbone network and the neck network. These features at different scales form a "feature pyramid." The core idea of ​​the Path Aggregation (PAN) network is to add a bottom-up path based on the multi-scale feature maps, shortening the path for low-level precise localization information to be transmitted to higher levels, thereby further enhancing the model's localization capability (especially for small targets). The pyramid is responsible for constructing multi-scale features, enabling strong semantic information propagation from top to bottom. Path Aggregation (PAN) adds a bottom-up path to the pyramid, achieving upward enhancement and aggregation of precise localization information. Specifically, the machine learning model in this embodiment is based on the YOLOv-8 algorithm, designed to identify scratches in a cigarette holder and perform bounding box processing, thereby detecting the scratch location and size. YOLO (You Only Look Once) is a one-stage object detection algorithm, meaning it only needs to "look" once to identify the class and bounding box of an object in an image. With the continuous development of the YOLO series, this invention uses the classic YOLOv-8 object detection algorithm from the YOLO series. The core architecture of the YOLOv-8 object detection algorithm consists of three main parts: the Backbone feature extraction module, the Neck feature fusion module, and the Head recognition module. The first part, Backbone feature extraction, commonly uses convolutional neural network architectures in deep learning feature extraction modules. YOLOv-8's feature extraction module employs the idea of ​​VGG (Visual Geometry Group) convolutional neural networks, utilizing a significant amount of... Convolution. An image is taken as input and convolved from top to bottom. As the number of layers increases, the features in the image are preserved from top to bottom, thus achieving the function of image feature extraction. The original YOLOv-8 used 19 layers of convolution. In deep learning, the core idea of ​​convolution is to divide the image into several small squares. The convolution operation extracts features from the image using a movable small square. Each small square is equivalent to a set of weights, and through continuous filtering, features are extracted. YOLOv-8 uses global average pooling. The image is transformed into a two-dimensional data structure. The image of a mouth holding a cigarette is a color image with a three-channel (red, yellow, green) data structure. Global average pooling averages the two-dimensional image of each channel. In the formula: the size of the input image is i, j, and k represent the three-channel data; c represents the three-channel mean of the global average pooling pair; the second part is the Neck feature fusion layer. The Backbone feature extraction module is responsible for image feature extraction, and the Neck feature fusion layer performs dimensionality reduction. The Yolov-8 Neck feature fusion layer uses an FPN (feature pyramid network) for organization. The characteristics of the PAN-FPN network can be summarized as follows: it first downsamples, then upsamples, and there are two cross-layer fusion connections between the upsampling and downsampling branches. Its schematic diagram... Figure 3 As shown, Figure 3 This is a schematic diagram of a sampling method provided in an embodiment of the present invention. Part Three: Head Recognition. The goal of the target detection algorithm for scratches in a mouth with a cigarette is to use bounding boxes to mark the location of the scratches in the image. Therefore, the head is measured using BboxLoss, which is a loss function that calculates the difference between the ground truth bounding box and the predicted bounding box. The Yolov-8 bounding box loss function uses CIOU (Complete-IOU). Figure 4 This is a schematic diagram of an IOU according to an embodiment of the present invention. IOU reflects the overlap range between the ground truth bounding box and the predicted bounding box. Figure 4 In this context, B represents the ground truth bounding box, and Bgt represents the predicted bounding box. The formula for calculating the overlap area between the two is as follows: To fully consider the aspect ratio information of the detection boxes, the minimum closure diagonal distance C and the distance P between the center points of the two boxes are introduced. Please refer to [reference needed]. Figure 5 , Figure 5 This is a schematic diagram of diagonal distance and center point distance between two bounding boxes provided in an embodiment of the present invention. Clou fully considers the three characteristics of the bounding box loss function: overlap area, center point distance, and aspect ratio. Traditional neural network architectures are usually based on neural networks, such as convolutional neural networks and recurrent neural networks. The original deep learning architecture of YOLOv-8 is VGG, which consists of a 36-layer convolutional neural network. With each layer of convolution, key information about the cigarette scratch is extracted. However, the drawback of convolutional neural networks is that they cannot perform detection in the global aspect of the image. Therefore, to improve the recognition rate of the algorithm model, the deep learning module of YOLOv-8 is replaced with the Transformer attention mechanism. The attention mechanism weights are weighted according to different parts of the data. The weight calculation is a function based on the input data and model parameters. Common attention mechanism weighting methods include dot product attention, additive attention, and self-attention. This invention uses dot product attention, which has good performance in natural language processing and image processing. Its principle is as follows: Let the dimensions of vector Q and vector K be dQ and dK, respectively. Then their dot product is expressed as: The calculation method involves multiplying the components (elements) at the same position in both vectors pairwise, then summing all these products to obtain a scalar (a single numerical value). The dot product attention mechanism uses the dot product of vectors as a similarity measure, and then normalizes the weights of each K using a softmax function. The weights of K and the corresponding values ​​of V are summed using a weighted average, where V is a value vector and out is the output. Scaling the dot product attention vectors can resolve size differences between vectors, making the variance of the attention weights more stable and thus improving the robustness of the model. In summary, replacing the VGG convolutional neural network in Yolov-8 with the Transformer attention mechanism module increases the model's receptive field and improves the recognition rate.

[0070] It should be further explained that, based on any of the above embodiments, the target scratch detection model is a deep learning model based on a window attention mechanism, and the feature pyramid network in the target scratch detection model is a weighted bidirectional feature pyramid network. It also employs a deeply decoupled detection head structure, separating classification and regression tasks into different branch networks, and introducing a coordinate attention mechanism into the regression branch. Window attention can segment the image into multiple non-overlapping local windows, calculating self-attention only within each window. This significantly reduces the computational complexity of traditional global self-attention mechanisms, enabling it to handle high-resolution images. During feature fusion, the weighted bidirectional feature pyramid network does not simply add features together, but introduces learnable weights to each input feature layer. The network automatically determines which feature layers are more important through training, thereby achieving more intelligent and efficient feature fusion. In the deeply decoupled detection head, decoupling separates the target detection task into two independent sub-task branches: a classification branch, which focuses on determining whether each anchor or pixel contains a scratch and its confidence level. The regression branch focuses on predicting the precise coordinates of the scratch bounding box. Each branch consists of multiple stacked convolutional layers (rather than a single convolutional layer), offering stronger non-linear fitting capabilities and task specificity. The coordinate attention mechanism embeds positional information into channel attention, capturing both long-range spatial dependencies and channel relationships. It performs global pooling along two spatial directions (height and width) to generate orientation-aware feature maps. Application: Embedding this mechanism into the regression branch allows the network to more accurately perceive the absolute position and extension direction of the scratch target when predicting bounding box coordinates. This design achieves significantly higher precision and localization accuracy than traditional models for small, diverse, and low-contrast scratches on cigarette surfaces.

[0071] It should be further explained that, based on any of the above embodiments, in order to improve the accuracy of detection, before determining the correlation weights between different pixel regions in the smoke-filled image with background removed using the target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the following may also be included:

[0072] Step 1: Convert the target image with smoke in its mouth to a grayscale image, and perform Gaussian filtering on the grayscale image to obtain a Gaussian-processed image; determine the gradient value of each pixel in the Gaussian-processed image in the horizontal and vertical directions, and calculate the gradient intensity and gradient direction of each pixel based on the gradient values ​​in the horizontal and vertical directions.

[0073] Understandably, the color of the target image containing smoke consists of a three-channel image composed of the three primary colors: red, yellow, and blue. To reduce the number of channels, the image needs to be converted to grayscale. Gaussian filtering smooths the image and also reduces noise, appropriately lowering prominent areas to minimize the impact of noise on edge detection results. A Gaussian filter (or median filtering, bilateral filtering, guided filtering, etc.) is used to incorporate the horizontal and vertical coordinates of the image into a Gaussian function. Where x and y are coordinate values, That's the standard deviation. The Gaussian filter uses a filter with dimensions of (2k+1) x (2k+1). .

[0074] Step 2: Traverse each pixel in the target image with smoke in its mouth, and compare the gradient intensity of the current pixel with the gradient intensity of the adjacent pixels on both sides along the corresponding gradient direction.

[0075] In this embodiment, the purpose of calculating the intensity and direction of the gradient is to find the edges of the image. A large change in grayscale indicates the presence of edge lines. Since the edge direction in an image can be any direction, four operators can be used to detect horizontal, vertical, and diagonal edges in the image, respectively. The Sobel operator Sx is used to detect the x-direction: The Sobel operator Sy is used to detect the y-direction: Let the image contain... Let window A be the pixel, and calculate the gradient values ​​of the pixel in the x and y directions as follows: ; The gradient G and direction of a pixel. for: ; .

[0076] Step 3: If the gradient intensity of the current pixel is greater than the gradient intensity of the adjacent pixels on both sides, then retain the pixel as an edge candidate point to obtain the gradient-processed image of the smoke-filled mouth.

[0077] The purpose of this embodiment in eliminating edge error checks is to clarify blurred boundaries. After gradient calculation, the edges of gradient values ​​are relatively blurry. To ensure that each edge has only one response value, a non-maximum printing rule is introduced. First, the gradient intensity of the current pixel is compared with two pixels along the positive and negative gradient directions. Second, if the current pixel differs significantly from the other two pixels, the pixel is retained; otherwise, it is discarded. The gradient segmentation direction is as follows: Figure 2 As shown, Figure 2 This is a schematic diagram of a gradient segmentation direction. ; If Gp is ​​greater than both Gp1 and Gp2, then Gp is ​​retained; otherwise, Gp is ​​discarded. NE = SW diagonal length; is the included angle; W is the length.

[0078] Step 4: Set the maximum gradient magnitude threshold and the minimum gradient magnitude threshold, and compare the gradient intensity of each pixel in the smoke-filled image with the maximum gradient magnitude threshold and the minimum gradient magnitude threshold.

[0079] In this embodiment, considering that after step 3, the actual edges of the image can be preserved, but some edge pixels caused by noise and color changes still exist in the image, a dual-threshold detection technique needs to be introduced to identify and weaken noise points. The dual-threshold detection technique establishes a high threshold and a low threshold. If the gradient value of an edge pixel in the image is higher than the high threshold, it is marked as a strong edge pixel; if the gradient value of an edge pixel is less than the high threshold but greater than the low threshold, it is marked as a low threshold pixel; if the gradient value of an edge pixel is less than the low threshold, it is removed.

[0080] Step 5: If the gradient strength of a pixel is greater than the maximum gradient magnitude threshold, it is marked as a strong edge pixel; if the gradient strength of a pixel is between the maximum gradient magnitude threshold and the minimum gradient magnitude threshold, it is marked as a weak edge pixel; if the gradient strength of a pixel is less than the minimum gradient magnitude threshold, it is discarded.

[0081] Step 6: Traverse all weak edge pixels and check if there are strong edge pixels within the 8-neighborhood of each weak edge pixel.

[0082] Step 7: If it exists, change the current weak edge pixel to a strong edge pixel and keep it; otherwise, discard it to obtain the complete outer contour of the mouth holding smoke composed of strong edge pixels.

[0083] This embodiment further processes weak boundaries by defining a weak boundary that connects a strong boundary to a weak boundary as a true boundary, while other weak boundaries are removed. By examining a weak boundary and its eight neighboring pixels, if one of them is a strong boundary, then that weak boundary is preserved and recognized as a true image edge.

[0084] Step 8: Based on the coordinate point set of the complete outer contour of the smoke in the mouth, replace the smoke-in-the-mouth region in the smoke-in-the-mouth image with the smoke-in-the-mouth region in the target smoke-in-the-mouth image to obtain the target smoke-in-the-mouth image with the background removed, and perform scratch detection based on the target smoke-in-the-mouth image with the background removed.

[0085] In this embodiment, the above steps effectively extract the outer contour of the smoke-filled mouth at the outlet, and the image of the smoke-filled mouth in the original image is cropped based on the coordinate values ​​of the outer contour. This ensures that only the portion of the smoke-filled mouth is retained in the image, while abnormal colors such as scratches within the smoke-filled mouth are preserved.

[0086] It should be further explained that, based on any of the above embodiments, before determining the correlation weights between different pixel regions in the background-removed smoke-holding image using the target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-holding image to obtain the scratch detection result, the method may further include: performing image enhancement processing on the background-removed smoke-holding image to obtain an enhanced target smoke-holding image; wherein, the image enhancement processing includes at least one of brightness and contrast joint adjustment, hue and saturation adjustment, and RGB channel offset adjustment; correspondingly, determining the correlation weights between different pixel regions in the background-removed smoke-holding image using the target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-holding image to obtain the scratch detection result may include: determining the correlation weights between different pixel regions in the enhanced target smoke-holding image using the target scratch detection model, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced smoke-holding image to obtain the scratch detection result. Understandably, in deep learning, data augmentation can reduce the model's over-reliance on certain features, thus avoiding overfitting. Therefore, data augmentation is necessary for images of cigarettes in the mouth. Joint brightness and contrast adjustment is an operation that performs a global linear transformation on the image's pixel values, simultaneously changing brightness and contrast to more richly simulate complex lighting conditions in the real world. Hue adjustment: changes the overall color of the image (e.g., reddish or bluish tint). This involves rotating the image on the color wheel. Saturation adjustment: changes the vibrancy of the color. Higher saturation results in a purer, more vibrant color; lower saturation results in a color closer to gray. Hue and saturation adjustments ensure that the model does not misjudge due to minor color differences between batches of cigarettes or color deviations in the camera itself. This allows the model to focus on texture and shape features (e.g., scratches) rather than the color itself. RGB channel shift adjustment independently adds or subtracts an offset value (shift) from the red (R), green (G), and blue (B) color channels of the image. The offset for each channel can be different. This is a powerful tool to combat "color overfitting" in the model. If a model relies too heavily on specific colors to identify scratches (e.g., only recognizing scratches on a particular background color), RGB offset can create samples with different color distributions but the same texture structure, forcing the model to learn more fundamental texture and contour features rather than relying on the unreliable cue of color. These three methods (which can be used in combination) greatly increase the diversity of training data, allowing the model to identify various possible "imaging anomalies."

[0087] It should be further explained that before determining the association weights between different pixel regions in the background-removed smoke-holding image using the target scratch detection model, dynamically enhancing the scratch features based on the association weights, and performing scratch detection on the dynamically enhanced smoke-holding image to obtain the scratch detection result, the process may further include: acquiring a training dataset and a test dataset composed of smoke-holding images, and iteratively training the attention-based deep learning detection model based on the training and test datasets; after each training round, determining the recognition rates corresponding to the training and test datasets respectively; when the set iteration conditions are met, using the optimal training parameters with the highest recognition rate as the parameters of the attention-based deep learning detection model to obtain the target scratch detection model. Specifically, the scratch photos of smoke-holding images are compiled, a client is installed, a virtual environment for dataset creation is built using Python as the development language, and a data labeling tool is installed in the virtual environment. In the high-resolution photos of smoke-holding images, the scratch locations of the smoke-holding images are drawn in a frame-like manner and saved as XML format files. A scratch detection model was built with the following parameters: image size: 256*256; training batch size: 32; training iterations: 200; learning rate: 0.001; weight decay: 0.0001. The model was trained for 200 epochs, and the recognition rates on the training and test sets were observed. The optimal training weights with the highest recognition rates were then saved. Finally, based on the optimal training weights, the inference model was edited and deployed privately.

[0088] This invention provides a scratch detection method, which may include: S101, acquiring a target image of a cigarette held in the mouth; S102, removing the background image of the target image of a cigarette held in the mouth to obtain a background-removed image of a cigarette held in the mouth; S103, using a target scratch detection model to determine the correlation weights between different pixel regions in the background-removed image of a cigarette held in the mouth, dynamically enhancing the scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced image of a cigarette held in the mouth to obtain a scratch detection result. Compared with current methods that cannot detect scratches, this invention can perform anomaly detection on the appearance scratches of a cigarette held in the mouth based on a target scratch detection model, and this model can dynamically enhance the scratched parts, thus achieving higher scratch detection accuracy.

[0089] For a clearer understanding of this invention, please refer to the following details. Figure 6 , Figure 6 A flowchart illustrating a scratch detection method provided in this embodiment of the invention may specifically include:

[0090] S201. Obtain the target image of smoke in the mouth, dynamically adjust the threshold range corresponding to the pixel values ​​of the R, G, and B color channels of the image of smoke in the mouth until the smoke-in-mouth area and the background area in the target image of smoke in the mouth are distinguished to the greatest extent, then process the background area to the target color to obtain the smoke-in-mouth image with the background removed.

[0091] S202. Extract the outer contour of the target image with smoke in the mouth to obtain the complete outer contour of the smoke in the mouth.

[0092] S203. Based on the coordinate point set of the complete outer contour of the mouth holding smoke, replace the mouth holding smoke region in the background-removed mouth holding smoke image with the mouth holding smoke region in the target mouth holding smoke image to obtain the mouth holding smoke image to be enhanced.

[0093] S204. The image of the mouth holding smoke to be enhanced is enhanced using data augmentation methods including random brightness adjustment, contrast adjustment and hue adjustment, to obtain the enhanced image of the mouth holding smoke.

[0094] S205. The association weights between different pixel regions in the enhanced mouth-and-smoke image are determined using the target scratch detection model. The scratch features are dynamically enhanced based on the association weights, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain the scratch detection results.

[0095] The scratch detection device provided in the embodiments of the present invention will be described below. The scratch detection device described below can be referred to in correspondence with the scratch detection method described above.

[0096] Please refer to the details. Figure 7 , Figure 7 A schematic diagram of a scratch detection device provided in an embodiment of the present invention may include:

[0097] Image acquisition module 100 is used to acquire images of the target mouth containing smoke;

[0098] Background removal module 200 is used to remove the background of the target mouth-smoking image to obtain a mouth-smoking image with the background removed;

[0099] The scratch detection module 300 is used to determine the correlation weights between different pixel regions in the background-removed smoke-holding image using a target scratch detection model, dynamically enhance the scratch features based on the correlation weights, and perform scratch detection on the dynamically enhanced smoke-holding image to obtain scratch detection results.

[0100] Furthermore, based on the above embodiments, the background removal module 200 may include:

[0101] The pixel value extraction unit is used to extract the pixel values ​​of the R, G, and B color channels of the target smoke-filled image.

[0102] The background removal unit is used to dynamically adjust the threshold range corresponding to the pixel values ​​of the three color channels R, G, and B until the smoke-containing area in the target smoke-containing image is most distinguishable from the background area. Then, the background area is processed into the target color to obtain the smoke-containing image with the background removed. The target color is different from the color of the smoke-containing area.

[0103] It should be further noted that, based on any of the above embodiments, the scratch detection device may further include:

[0104] The filtering module is used to convert the target smoke-filled image into a grayscale image, and perform Gaussian filtering on the grayscale image to obtain a Gaussian-processed image; determine the gradient values ​​of each pixel in the Gaussian-processed image in the horizontal and vertical directions, and calculate the gradient intensity and gradient direction of each pixel based on the gradient values ​​in the horizontal and vertical directions;

[0105] Traverse each pixel in the target mouth-smoke image and compare the gradient intensity of the current pixel with the gradient intensity of the adjacent pixels on both sides along the corresponding gradient direction.

[0106] The gradient processing port smoke image determination module is used to retain the current pixel as an edge candidate point if the gradient intensity of the current pixel is greater than the gradient intensity of the adjacent pixels on both sides, thus obtaining the gradient processing port smoke image.

[0107] The comparison module is used to set the maximum gradient magnitude threshold and the minimum gradient magnitude threshold, and compare the gradient intensity of each pixel in the gradient-processed smoke-filled image with the maximum gradient magnitude threshold and the minimum gradient magnitude threshold.

[0108] The processing module is configured to mark a pixel as a strong edge pixel if the gradient intensity of the pixel is greater than the maximum gradient magnitude threshold; mark a pixel as a weak edge pixel if the gradient intensity of the pixel is between the maximum gradient magnitude threshold and the minimum gradient magnitude threshold; and discard a pixel if the gradient intensity of the pixel is less than the minimum gradient magnitude threshold.

[0109] The strong edge pixel determination module is used to traverse all the weak edge pixels and check whether there are strong edge pixels within the 8 neighboring pixels corresponding to each weak edge pixel.

[0110] The contour determination module is used to change the current weak edge pixel to a strong edge pixel if it exists and retain it; otherwise, it is discarded to obtain the complete outer contour of the mouth containing smoke composed of the strong edge pixels.

[0111] The scratch enhancement module is used to replace the area of ​​the mouth holding smoke in the background-removed image with the area of ​​the mouth holding smoke in the target image based on the coordinate point set of the complete outer contour of the mouth holding smoke, so as to obtain the target background-removed image of the mouth holding smoke, and to perform scratch detection based on the target background-removed image of the mouth holding smoke.

[0112] Furthermore, based on any of the above embodiments, the scratch detection module 300 may include:

[0113] The dynamic enhancement module is used to calculate the correlation weights between different regions in the background-removed smoke-filled image using a self-attention mechanism, dynamically enhance the representation of scratch features, and obtain a dynamically enhanced image.

[0114] A multi-scale fusion module is used to perform multi-scale fusion on the dynamically enhanced image through a feature pyramid network and a path aggregation network to obtain an enhanced feature map for prediction.

[0115] The prediction module is used to process the enhanced feature map used for prediction through the decoupled detection head, predict the location bounding box and category confidence of the scratch, and output the scratch detection result; the scratch detection result includes the location coordinates, confidence score and category label of the scratch.

[0116] Furthermore, based on any of the above embodiments, the scratch detection device may further include:

[0117] An image enhancement processing module is used to perform image enhancement processing on the background-removed image of a mouth holding smoke to obtain an enhanced target image of a mouth holding smoke; wherein, the image enhancement processing includes at least one of brightness and contrast joint adjustment, hue and saturation adjustment, and RGB channel offset adjustment;

[0118] Accordingly, the scratch detection module 300 may include:

[0119] The scratch detection unit is used to determine the correlation weights between different pixel regions in the enhanced target mouth-and-smoke image using the target scratch detection model, dynamically enhance the scratch features based on the correlation weights, and perform scratch detection on the dynamically enhanced mouth-and-smoke image to obtain the scratch detection result.

[0120] Furthermore, based on any of the above embodiments, the scratch detection device may further include:

[0121] The dataset acquisition module is used to acquire training and test datasets consisting of images of people with cigarettes in their mouths, and to iteratively train the deep learning detection model based on the attention mechanism based on the training and test datasets.

[0122] The recognition rate determination module is used to determine the recognition rate corresponding to the training dataset and the test dataset respectively after each training round.

[0123] The training module is used to take the optimal training parameters with the highest recognition rate as the parameters of the deep learning detection model based on the attention mechanism when the set iteration conditions are met, so as to obtain the target scratch detection model.

[0124] Furthermore, based on any of the above embodiments, the target scratch detection model is a deep learning model based on window attention mechanism, and the feature pyramid network in the target scratch detection model is a weighted bidirectional feature pyramid network, and a deep decoupled detection head structure is adopted to separate the classification and regression tasks into different branch networks, and a coordinate attention mechanism is introduced into the regression branch.

[0125] It should be noted that the order of the modules and units in the above scratch detection device can be changed without affecting the logic.

[0126] This invention provides a scratch detection device, which may include: an image acquisition module 100 for acquiring a target image of a cigarette held in the mouth; a background removal module 200 for removing the background from the target image of a cigarette held in the mouth to obtain a background-removed image of a cigarette held in the mouth; and a scratch detection module 300 for determining the correlation weights between different pixel regions in the background-removed image of a cigarette held in the mouth using a target scratch detection model, dynamically enhancing scratch features based on the correlation weights, and performing scratch detection on the dynamically enhanced image of a cigarette held in the mouth to obtain a scratch detection result. Compared with current methods that cannot detect scratches, this invention can detect anomalies in the appearance of cigarette held in the mouth based on a target scratch detection model, and this model can dynamically enhance the scratched parts, thus achieving higher scratch detection accuracy.

[0127] The following is a description of a scratch detection device provided by an embodiment of the present invention. The scratch detection device described below can be referred to in correspondence with the scratch detection method described above.

[0128] Please refer to Figure 8 , Figure 8 A schematic diagram of a scratch detection device provided in an embodiment of the present invention may include:

[0129] Memory 10 is used to store computer programs;

[0130] The processor 20 is used to execute computer programs to implement the scratch detection method described above.

[0131] The memory 10, processor 20, and communication interface 30 all communicate with each other through the communication bus 40.

[0132] In this embodiment of the invention, the memory 10 is used to store one or more programs. The programs may include program code, which includes computer operation instructions. In this embodiment of the invention, the memory 10 may store programs for implementing the following functions:

[0133] Acquire an image of the target's mouth containing smoke;

[0134] The background image of the target image with smoke in its mouth is removed to obtain the image with smoke in its mouth without the background.

[0135] The association weights between different pixel regions in a smoke-filled image with background removed are determined using a target scratch detection model. Based on the association weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced smoke-filled image to obtain the scratch detection results.

[0136] In one possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and applications required for at least one function; and the data storage area may store data created during use.

[0137] Furthermore, memory 10 may include read-only memory and random access memory, providing instructions and data to the processor. A portion of the memory may also include NVRAM. The memory stores operating systems and operating instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and handling hardware-based tasks.

[0138] Processor 20 can be a central processing unit (CPU), an application-specific integrated circuit, a digital signal processor, a field-programmable gate array, or other programmable logic device. Processor 20 can be a microprocessor or any conventional processor. Processor 20 can call programs stored in memory 10.

[0139] The communication interface 30 can be an interface for the communication module, used to connect with other devices or systems.

[0140] Of course, it should be noted that, Figure 8 The structure shown does not constitute a limitation on the scratch detection device in the embodiments of the present invention. In practical applications, the scratch detection device may include more than Figure 8 More or fewer components as shown, or combinations of certain components.

[0141] The following describes the computer-readable storage medium provided in the embodiments of the present invention. The computer-readable storage medium described below can be referred to in correspondence with the scratch detection method described above.

[0142] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the scratch detection method described above.

[0143] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0144] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0145] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0146] Finally, it should be noted that in this document, relationships such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0147] The present invention provides a detailed description of a scratch detection method, apparatus, device, and computer-readable storage medium. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A scratch detection method, characterized in that, include: Acquire an image of the target's mouth containing smoke; The background of the target image with smoke in the mouth is removed to obtain an image with smoke in the mouth without background. The association weights between different pixel regions in the background-removed mouth-and-smoke image are determined using a target scratch detection model. Based on these association weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain the scratch detection results.

2. The scratch detection method according to claim 1, characterized in that, The background of the target image with smoke in the mouth is removed to obtain a background-removed image with smoke in the mouth, including: Extract the pixel values ​​of the R, G, and B color channels of the target mouth-smoke image; The threshold ranges corresponding to the pixel values ​​of the three color channels R, G, and B are dynamically adjusted until the area with smoke in the mouth and the background area in the target image with smoke in the mouth are distinguished to the greatest extent. Then, the background area is processed into the target color to obtain the image with smoke in the mouth with the background removed. The target color is different from the color of the area with smoke in the mouth.

3. The scratch detection method according to claim 1, characterized in that, Before determining the correlation weights between different pixel regions in the background-removed smoke-filled image using a target scratch detection model, dynamically enhancing the scratch features based on these correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the process further includes: The target image containing smoke is converted into a grayscale image, and the grayscale image is then subjected to Gaussian filtering to obtain a Gaussian-processed image. Determine the gradient values ​​of each pixel in the Gaussian-processed image in the horizontal and vertical directions, and calculate the gradient intensity and gradient direction of each pixel based on the gradient values ​​in the horizontal and vertical directions; Traverse each pixel in the target mouth-smoke image and compare the gradient intensity of the current pixel with the gradient intensity of the adjacent pixels on both sides along the corresponding gradient direction. If the gradient intensity of the current pixel is greater than the gradient intensity of the two adjacent pixels, then the pixel is retained as an edge candidate point, and the gradient-processed image with smoke in the mouth is obtained. Set a maximum gradient magnitude threshold and a minimum gradient magnitude threshold, and compare the gradient intensity of each pixel in the gradient-processed smoke-filled image with the maximum gradient magnitude threshold and the minimum gradient magnitude threshold; If the gradient intensity of a pixel is greater than the maximum gradient magnitude threshold, it is marked as a strong edge pixel; if the gradient intensity of a pixel is between the maximum gradient magnitude threshold and the minimum gradient magnitude threshold, it is marked as a weak edge pixel; if the gradient intensity of a pixel is less than the minimum gradient magnitude threshold, it is discarded. Traverse all the weak edge pixels and check whether there are strong edge pixels within the 8-neighborhood pixels corresponding to each weak edge pixel; If it exists, the current weak edge pixel is changed to a strong edge pixel and retained; otherwise, it is discarded to obtain the complete outer contour of the mouth holding smoke composed of the strong edge pixels. Based on the coordinate point set of the complete outer contour of the smoke in the mouth, the smoke-in-mouth region in the smoke-in-mouth image with the background removed is replaced with the smoke-in-mouth region in the target smoke-in-mouth image to obtain the target smoke-in-mouth image with the background removed, and scratch detection is performed based on the target smoke-in-mouth image with the background removed.

4. The scratch detection method according to any one of claims 1 to 3, characterized in that, A target scratch detection model is used to determine the correlation weights between different pixel regions in the background-removed mouth-and-smoke image. Based on these correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain scratch detection results, including: The association weights between different regions in the background-removed smoke-filled image are calculated using a self-attention mechanism to dynamically enhance the representation of scratch features, resulting in a dynamically enhanced image. The dynamically enhanced image is fused at multiple scales using a feature pyramid network and a path aggregation network to obtain an enhanced feature map for prediction. The enhanced feature map used for prediction is processed by the decoupled detection head to predict the location bounding box and class confidence of the scratch, and output the scratch detection result; the scratch detection result includes the location coordinates, confidence score and class label of the scratch.

5. The scratch detection method according to claim 1, characterized in that, Before determining the correlation weights between different pixel regions in the background-removed mouth-and-smoke image using a target scratch detection model, dynamically enhancing the scratch features based on these correlation weights, and performing scratch detection on the dynamically enhanced mouth-and-smoke image to obtain the scratch detection result, the process further includes: The image image with the background removed and the smoke in the mouth is subjected to image enhancement processing to obtain an enhanced target image with the smoke in the mouth; wherein, the image enhancement processing includes at least one of brightness and contrast joint adjustment, hue and saturation adjustment, and RGB channel offset adjustment; Accordingly, the correlation weights between different pixel regions in the background-removed mouth-and-smoke image are determined using a target scratch detection model. Based on these correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced mouth-and-smoke image to obtain scratch detection results, including: The target scratch detection model is used to determine the correlation weights between different pixel regions in the enhanced target smoke-in-mouth image. Based on the correlation weights, the scratch features are dynamically enhanced, and scratch detection is performed on the dynamically enhanced smoke-in-mouth image to obtain the scratch detection result.

6. The scratch detection method according to claim 1, characterized in that, Before determining the correlation weights between different pixel regions in the background-removed smoke-filled image using a target scratch detection model, dynamically enhancing the scratch features based on these correlation weights, and performing scratch detection on the dynamically enhanced smoke-filled image to obtain the scratch detection result, the process further includes: A training dataset and a test dataset consisting of images of people holding cigarettes in their mouths are obtained, and an attention-based deep learning detection model is iteratively trained based on the training dataset and the test dataset. After each training round, the recognition rates corresponding to the training dataset and the test dataset are determined respectively. When the set iteration conditions are met, the optimal training parameters with the highest recognition rate are used as the parameters of the deep learning detection model based on the attention mechanism to obtain the target scratch detection model.

7. The scratch detection method according to claim 1, characterized in that, The target scratch detection model is a deep learning model based on window attention mechanism. The feature pyramid network in the target scratch detection model is a weighted bidirectional feature pyramid network. It also adopts a deep decoupled detection head structure, separating classification and regression tasks into different branch networks, and introducing a coordinate attention mechanism into the regression branch.

8. A scratch detection method, characterized in that, include: The image acquisition module is used to acquire images of the target mouth containing smoke. The background removal module is used to remove the background of the target image of a person holding a cigarette in their mouth, so as to obtain an image of a person holding a cigarette in their mouth with the background removed. The scratch detection module is used to determine the correlation weights between different pixel regions in the background-removed smoke-holding image using a target scratch detection model, dynamically enhance the scratch features based on the correlation weights, and perform scratch detection on the dynamically enhanced smoke-holding image to obtain scratch detection results.

9. A scratch detection device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the scratch detection method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the scratch detection method as described in any one of claims 1 to 7.