A method for classifying yellow-spotted smoke, electronic equipment and medium
By employing a multi-camera circumferential arrangement and image processing technology, the yellow-smoke area is automatically identified, solving the problems of low detection efficiency and poor consistency of yellow-smoke, and achieving efficient and accurate yellow-smoke classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-04
- Publication Date
- 2026-05-26
AI Technical Summary
Current technologies rely on manual judgment for the detection of yellow-spotted smoke, which is inefficient, has a high false detection rate, and makes it difficult to ensure the consistency of detection.
Multiple cameras are arranged around the circumference of the cigarette to be tested. The macular region is identified through a preset strategy and model. The classification result is determined by combining statistical parameters. The process includes steps such as image preprocessing, edge detection, model correction and binarization, which reduces human intervention.
It improves the efficiency of yellow-spotted cigarette classification, reduces labor costs, adapts to the testing needs of different batches and base colors of cigarettes, and ensures the consistency of testing.
Smart Images

Figure CN122090119A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image detection technology, and more specifically, to a method for classifying yellow-spot smoke, an electronic device, and a medium. Background Technology
[0002] Yellow-spotted cigarettes are primarily caused by factors such as wet clumps from the tobacco processing stage, oil contamination during the rolling and packaging process, and temperature and humidity issues during storage. Based on the source of contamination, they are categorized into water-stained cigarettes, material-stained cigarettes, flavoring-stained cigarettes, and oil-stained cigarettes. Yellow stains significantly reduce the uniformity of cigarette combustion, taste, and safety, and are one of the core quality control indicators in tobacco production. Relying on the subjective judgment of quality inspectors results in low testing efficiency (requiring 3-5 inspectors per test), a high false positive rate (approximately 8%-12%), and prolonged operation can easily lead to visual fatigue, making it difficult to ensure consistent testing results. Summary of the Invention
[0003] In view of this, the purpose of the embodiments of this application is to provide a method, electronic device and medium for classifying yellow-smoke, which can improve the problem of difficulty in ensuring detection consistency caused by the detection of yellow-smoke.
[0004] To achieve the above technical objectives, the technical solution adopted in this application is as follows:
[0005] In a first aspect, embodiments of this application provide a method for classifying yellow-spotted smoke, the method comprising:
[0006] Acquire several camera images, wherein each camera image is captured by a corresponding preset camera, and all the preset cameras are arranged along the circumference of the cigarette to be tested;
[0007] Based on the first preset strategy, the first outline of the cigarette to be tested in the camera image is obtained;
[0008] Extract the target pixel region within the first contour to characterize the suspected macula;
[0009] The camera image containing the target pixel region is input into a preset model, and the first macular region is obtained by filtering all the target pixel regions through the preset model;
[0010] Based on all the first macular regions, the statistical parameters of the macular region in the cigarette to be tested are determined;
[0011] Based on the statistical parameters, the classification results are obtained.
[0012] Furthermore, between acquiring several camera images and obtaining the first contour of the cigarette to be tested in the camera images based on a first preset strategy, the method further includes:
[0013] According to the second preset algorithm, the first initial contour of the cigarette to be tested in the camera image is extracted;
[0014] Calculate the first RGB parameters of the second pixel region within the first initial contour;
[0015] In a preset template library, a cigarette background color template that matches the camera image is obtained. The preset template library includes multiple cigarette background color templates and a second RGB parameter corresponding to the cigarette background color template. The Euclidean distance between the second RGB parameter and the first RGB parameter of the matching cigarette background color template is minimized.
[0016] Based on the matching cigarette background color template, the pixel value of each pixel in the second pixel region is corrected to obtain a corrected camera image, and the first contour is determined based on the corrected camera image.
[0017] Furthermore, obtaining the first contour of the cigarette to be tested in the camera image based on the first preset strategy includes:
[0018] The corrected camera image is input into the binarization model, and a binarized camera image is obtained through the binarization model.
[0019] Calculate the intersection-over-union ratio (IoU) of the binarized camera image and the adjacent binarized camera images. When the IoU is less than a preset threshold, correct the mask of the binarized image based on the adjacent binarized camera images to obtain a corrected binarized image.
[0020] The first contour is determined based on the pixels in the modified binarized image whose pixel values are preset values.
[0021] Further, the extraction of the target pixel region within the first contour for characterizing the suspected macula includes:
[0022] The camera image is converted to grayscale to obtain a grayscale image;
[0023] Edge detection is performed on the grayscale image to obtain candidate pixel regions within the first contour;
[0024] Calculate the area, first roundness, and average gray value of the candidate pixel region;
[0025] Based on the area, the first roundness, and the average grayscale value, the target pixel region is obtained by filtering the candidate pixel regions.
[0026] Further, the step of selecting the target pixel region from the candidate pixel regions based on the area, the first roundness, and the average grayscale value includes:
[0027] When the area is greater than the area threshold, the first roundness is greater than the first roundness threshold, and the grayscale mean is greater than the grayscale threshold, the candidate pixel region is the target pixel region.
[0028] Furthermore, determining the statistical parameters of the macula of the cigarette to be tested based on all the first macular regions includes:
[0029] The first yellow spot region is transformed to the coordinate system of the cigarette to be tested to obtain the second yellow spot region;
[0030] Based on the second preset strategy, a second detection result is determined. The second detection result indicates whether the two second macular regions corresponding to two adjacent camera images are the same, and whether the two second macular regions corresponding to two adjacent camera images can be stitched together to form a macula.
[0031] Based on the second detection result, the statistical parameters of the macula are calculated.
[0032] Furthermore, determining the second detection result based on the second preset strategy includes:
[0033] Calculate the similarity parameter of the two second macular regions corresponding to the two adjacent camera images. When the similarity parameter is greater than the similarity threshold, the two second macular regions corresponding to the two adjacent camera images are the same.
[0034] When the two second macula regions corresponding to two adjacent camera images are not the same, the second roundness of the image after stitching the two second macula regions corresponding to the two adjacent camera images is calculated, and the texture features of the two second macula regions corresponding to the two adjacent camera images are calculated. When the second roundness is greater than the second roundness threshold and the two texture features are the same, the two second macula regions corresponding to the two adjacent camera images are stitched into one macula.
[0035] Secondly, embodiments of this application also provide an electronic device, which includes a processor and a memory coupled to each other. The memory stores a computer program, and when the computer program is executed by the processor, the electronic device performs the above-described method.
[0036] Thirdly, embodiments of this application also provide a computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program, which, when run on a computer, causes the computer to perform the above-described method.
[0037] The invention employing the above technical solution has the following advantages:
[0038] In the technical solution provided in this application, after acquiring camera images of the cigarette to be tested, the first outline of the cigarette is first determined. Then, a first preset algorithm is used to extract the target pixel region suspected to be a macula. Next, based on a preset model, all target pixel regions are filtered to obtain the first macula region. Finally, the statistical parameters of the macula in the cigarette to be tested are determined. This solution, after determining the target pixel region, can lock the macula region in the camera image based on a preset model. Combined with the statistical parameters of the macula, the classification result is determined. This solution improves the efficiency of macula cigarette classification, reduces labor costs, and can thus adapt to the detection needs of different batches and different background colors of cigarettes. Attached Figure Description
[0039] This application can be further illustrated by the non-limiting embodiments given in the accompanying drawings. It should be understood that the following drawings only illustrate some embodiments of this application and should not be considered as limiting the scope. For those skilled in the art, other related drawings can be obtained from these drawings without any inventive effort.
[0040] Figure 1 A flowchart illustrating the yellow-spot smoke classification method provided in this application embodiment.
[0041] Figure 2 This is a sub-flowchart of S120 provided in an embodiment of this application.
[0042] Figure 3 This is a sub-flowchart of S130 provided in an embodiment of this application.
[0043] Figure 4 This is a sub-flowchart of S150 provided in an embodiment of this application. Detailed Implementation
[0044] The present application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that similar or identical parts are referred to by the same reference numerals in the drawings or description. Implementations not shown or described in the drawings are forms known to those skilled in the art. In the description of this application, terms such as "first" and "second" are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0045] This application provides an electronic device that may include a processing module and a storage module. The storage module stores a computer program, which, when executed by the processing module, enables the electronic device to perform the corresponding steps in the following yellow-spot smoke classification method.
[0046] Please refer to Figure 1 This embodiment also provides a method for classifying yellow-spot smoke. The yellow-spot smoke classification method may include the following steps:
[0047] S110, acquire a number of camera images, wherein each camera image is captured by a corresponding preset camera, and all the preset cameras are arranged along the circumference of the cigarette to be tested;
[0048] S120, based on the first preset strategy, obtain the first outline of the cigarette to be tested in the camera image;
[0049] S130, extract the target pixel region within the first contour used to characterize the suspected macula;
[0050] S140, input the camera image containing the target pixel region into the preset model, and use the preset model to filter all the target pixel regions to obtain the first macular region;
[0051] S150, Based on all the first macular regions, determine the statistical parameters of the macular region in the cigarette to be tested;
[0052] S160, Based on the statistical parameters, obtain the classification result.
[0053] In the above implementation, multiple preset cameras arranged around the circumference of the cigarette to be tested simultaneously acquire multi-angle images of the cigarette to ensure that the visual blind spot around the circumference of the cigarette is small. First, the first contour of the cigarette to be tested in each camera image is extracted according to the first preset strategy to remove background interference. Then, the first preset algorithm separates the target pixel region that conforms to the morphology and grayscale of the macula from the first contour, greatly filtering out non-macula interference. Subsequently, the target pixel region is input into the preset model, and the model accurately identifies the regional features and outputs the first detection result representing whether the region is the first macula region. Finally, the first detection results of all camera images are summarized to determine whether the cigarette to be tested has a macula, and thus determine whether it is a macula cigarette.
[0054] The steps of the yellow-spotted smoke classification method will be explained in detail below:
[0055] Several preset cameras are set up in S110. All preset cameras can be arranged in a dedicated detection device. This detection device is used to randomly inspect selected cigarettes to determine whether they are yellow-spotted cigarettes. The detection device has space to place the preset cameras and can be equipped with lighting to improve the shooting effect. During the detection, the cigarette to be tested is placed at the center of the circular area formed by all the preset cameras, ensuring that the visual blind spot around the cigarette is small. After all the preset cameras have taken pictures, the camera images are numbered, with each number corresponding to a preset camera, and then input into the electronic device. After receiving all the numbered camera images, the electronic device determines whether the cigarette to be tested is a yellow-spotted cigarette based on S120-S150.
[0056] In this embodiment, it is necessary to eliminate the differences in background color and texture between different batches of cigarettes (such as "hard red" and "hard blue"), as well as the influence of uneven lighting within the same batch, to maximize the grayscale difference between the yellow spots and the cigarette paper background, paving the way for subsequent segmentation and recognition. Therefore, between S110 and S120, the method proposed in this embodiment further includes:
[0057] According to the second preset algorithm, a first initial contour of the cigarette to be tested in the camera image is extracted; the first RGB parameters of the second pixel region within the first initial contour are calculated; a cigarette background color template matching the camera image is obtained from a preset template library, the preset template library including multiple cigarette background color templates and the second RGB parameters corresponding to the cigarette background color templates, wherein the Euclidean distance between the second RGB parameters of the matching cigarette background color template and the first RGB parameters is minimized; based on the matching cigarette background color template, the pixel value of each pixel in the second pixel region is corrected to obtain a corrected camera image, and the first contour is determined based on the corrected camera image.
[0058] In this embodiment, a rough outline of the cigarette to be tested is first extracted using a second preset algorithm, which is the first initial outline. The second preset algorithm can be the Canny edge detection algorithm. The process is as follows: first, the edge outline of the cigarette in the image is identified by Canny edge detection, and then the closed outline formed by the edge is extracted using the cv2.findContours function. The outline with the largest area or that conforms to the size ratio of the cigarette is selected as the initial outline.
[0059] In this embodiment, the RGB parameters include the RGB mean and RGB variance, and the variance can reflect the roughness of the cigarette paper texture.
[0060] The preset template library in this embodiment includes multiple cigarette background color templates. The method for establishing the cigarette background color templates is as follows: Under a stable production line operating environment, for each brand and specification of defect-free cigarettes, at least 100 clear camera images of samples are collected. The main body area of each sample is extracted using a second preset algorithm (such as color threshold segmentation, edge detection + contour extraction). The RGB mean (R_mean, G_mean, B_mean) and RGB variance (R_var, G_var, B_var) of all pixels in the area are calculated. At the same time, the optimal color correction parameters (such as Gamma value, white balance gain) corresponding to this type of cigarette are determined through experience or grid search. The "brand / specification identifier, RGB mean, RGB variance, and optimal color correction parameters" are packaged into a cigarette background color template. All templates are summarized to form a preset template library, ensuring that the templates in the library can cover common cigarette background colors and texture differences on the production line.
[0061] The cigarette background color template with the smallest Euclidean distance represents the most likely batch of the current cigarette. The optimal color correction parameters corresponding to this template are then used to correct the pixel values of each pixel in the second pixel region, resulting in the corrected camera image. For example, the correction method could be:
[0062] First, based on the Gamma correction coefficient of the matched cigarette background color template, the RGB pixel values of each channel in the second pixel area are subjected to Gamma transformation, using the following formula: (in The original pixel value is γ, which is the Gamma value corresponding to the matched cigarette background color template; then the white balance gain preset by the matched cigarette background color template is applied. , , Gain adjustment is performed on the pixel values of each channel, i.e. Finally, the adjusted pixel values are limited to the range of 0-255 to obtain the corrected camera image, thereby unifying the background color of different batches of cigarettes and enhancing the contrast between the yellow spots and the background.
[0063] In this embodiment, as Figure 2 As shown, S120 may specifically include the following steps:
[0064] S121: Input the corrected camera image into the binarization model, and obtain the binarized camera image through the binarization model;
[0065] S122: Calculate the intersection-over-union ratio (IoU) of the binarized camera image and the adjacent binarized camera images. When the IoU is less than a preset threshold, correct the mask of the binarized image based on the adjacent binarized camera images to obtain a corrected binarized image.
[0066] S123: Determine the first contour based on the pixels in the modified binarized image whose pixel values are preset values.
[0067] It is understandable that the first preset strategy refers to the overall process method of S121-S123.
[0068] In this embodiment, the binarization model can be a pre-trained lightweight U-Net model. U-Net is a deep learning model well-suited for image segmentation, as it effectively preserves image details through its encoder-decoder structure. After inputting the corrected camera image into the lightweight U-Net model, the model outputs a binary mask of the same size as the input image; this mask represents the binarized camera image. Pixels with a value of 1 on the mask represent regions identified as "cigarettes" by the model, while pixels with a value of 0 represent the "background." For example, the lightweight U-Net model can be trained as follows:
[0069] First, a labeled dataset (with labeled cigarette regions as foreground and background as background) containing cigarettes from different angles, batches, and various background interferences is constructed. The dataset is then augmented with random cropping, flipping, and brightness perturbation to improve generalization. Cross-entropy loss or Dice loss is used as the loss function, and Adam is selected as the optimizer (the learning rate is initially set to 1e-4 and dynamically adjusted as needed). The input image is scaled to the model's fit size (e.g., 256×256) and then input into a lightweight U-Net (which reduces the number of parameters by reducing the number of channels and introducing depthwise separable convolutions). Iterative training is performed in an end-to-end manner. After each training round, the segmentation accuracy (IoU, Dice coefficients) is evaluated using a validation set. Overfitting is prevented by early stopping. Finally, the model weights with the best performance on the validation set are saved. After training, fine-tuning is performed on actual images from the production line to ensure that the segmentation of cigarette outlines is adapted to the industrial scenario.
[0070] In this embodiment, due to factors such as changes in lighting and slight deformation of the cigarette, the edges output by the U-Net model may have a deviation of 1-2 pixels, or small mis-segmented regions may occur in some complex backgrounds. This embodiment uses the Snake algorithm to correct the edges output by the U-Net model. The energy of Snake consists of two parts: Internal Energy: keeps the curve smooth (first derivative) and continuous (second derivative), avoiding jagged edges. External Energy: guides the curve to move towards the high gradient region (i.e., edge) of the image. We usually use the image gradient magnitude as the external energy field. Iterative optimization: the algorithm minimizes the total energy by continuously adjusting the position of each point on the curve. After dozens of iterations, the curve will accurately "fit" the true edge of the cigarette. In this embodiment, the outline of the coarse segmentation mask output by U-Net is used as the initial position of the Snake curve.
[0071] In S122, since the same cigarette to be tested should have a highly similar outline shape and position in adjacent image (frame) frames, if a significant deviation occurs in the binarized camera image of a certain frame, it can be corrected using adjacent frames. In this embodiment, the current binarized camera image is used as the mask of the i-th frame, and the two adjacent binarized camera images are used as the masks of the (i+1)-th and (i-1)-th frames, respectively.
[0072] In this embodiment, the mask for the i-th frame... We calculate it with the mask of the (i-1)th frame. and the mask of the (i+1)th frame The Intersection over Union (IoU) ratio. The IoU is an indicator that measures the degree of overlap between two regions, ranging from 0 to 1. IoU=1 indicates complete overlap, and IoU=0 indicates no overlap.
[0073] If IoU( , )<0.9 and IoU( If the value is less than 0.9 (meaning the difference from the preceding and following frames exceeds 10%), this embodiment considers the segmentation result of the i-th frame to be potentially misjudged. Therefore, it can be used... and The average value (or obtained through morphological fusion) is used to replace or correct the value. This ensures the spatial consistency and stability of the segmentation results for all frames.
[0074] In S123, based on S122 for each corrected binarized image, the edges of the pixel regions with a pixel value of 1 are extracted, which are the first contours.
[0075] In this embodiment, after accurately extracting the first contour, it is necessary to determine the target pixel region. In this embodiment, the target pixel region refers to the region that may be a suspected macula. This embodiment requires extracting these suspected macula regions, and then, based on a preset model, determining whether the suspected macula region is the macula or part of the macula. Therefore, as... Figure 3 As shown, S130 may specifically include the following steps:
[0076] S131: Convert the camera image to grayscale to obtain a grayscale image;
[0077] S132: Perform edge detection on the grayscale image to obtain candidate pixel regions within the first contour;
[0078] S133: Calculate the area, first roundness, and average gray value of the candidate pixel region;
[0079] S134: Based on the area, the first roundness, and the average gray value, the target pixel region is obtained by filtering the candidate pixel regions.
[0080] In S132, the grayscale image is first processed using an edge detection algorithm (such as the Canny algorithm) to identify the edge information of all pixels within the first contour, resulting in a binarized edge map containing the edges. Then, the cv2.findContours function is used to extract all closed contours within the first contour from the edge map (using the cv2.RETR_EXTERNAL parameter to retain only the outermost contour). Next, the pixel region enclosed by each closed contour is marked as an independent candidate region, while excluding tiny regions with an area smaller than a preset minimum threshold (such as the number of pixels corresponding to the minimum detectable area of the macula). Finally, all candidate pixel regions within the first contour defined by the closed contours are obtained.
[0081] Edge detection can capture pixels with abrupt changes in brightness in a grayscale image (such as the boundary between the yellow spot and the cigarette paper background), generate a binary edge map, and quickly locate all possible defect edges within the first contour, avoiding the omission of tiny yellow spots. Using cv2.findContours to extract closed contours (especially the cv2.RETR_EXTERNAL parameter) can transform discrete edges into pixel regions with clear boundaries, giving each candidate region independent morphological features (such as area and roundness), which is convenient for subsequent quantization and screening. Excluding regions with too small an area can directly filter out interference objects such as dust and noise that are much smaller than the size of the yellow spot, reduce unnecessary computation, and ensure that the candidate region focuses on the target that meets the size characteristics of the yellow spot, thereby improving the efficiency and accuracy of subsequent detection.
[0082] In S133, when the area is greater than the area threshold, the first roundness is greater than the first roundness threshold, and the grayscale mean is greater than the grayscale threshold, the candidate pixel region is the target pixel region.
[0083] In this embodiment, the area can be determined based on the number of pixels in the candidate pixel region, and the area threshold is calculated based on the "minimum detectable diameter of the macula". For example, a minimum diameter of 0.1 mm corresponds to a 10x10 pixel circle, with an area of approximately 78.5 pixels. The threshold can be set to 50 pixels to ensure that nothing is missed.
[0084] The first roundness measure is how close the shape of the candidate pixel region is to a circle, and the calculation formula is:
[0085] Roundness = , where A is the area of the candidate region and P is the perimeter of the candidate region.
[0086] A perfect circle has a roundness value of 1. The more a shape deviates from a circle (such as a long strip or an irregular shape), the smaller the roundness value.
[0087] A is calculated using cv2.contourArea(contour), which represents the OpenCV library function used to calculate the area of the region enclosed by a contour. The return value is the pixel area (unit: pixels²) corresponding to the contour.
[0088] P is calculated using `cv2.arcLength(contour, closed=True)`, where `closed=True` indicates that the contour is closed. This is a function in the OpenCV library used to calculate the perimeter of a contour (or the length of a curve). `contour` is the set of contour points (a two-dimensional coordinate array) extracted by `cv2.findContours()`. The parameter `closed=True` indicates that the contour is closed (i.e., the start and end points of the contour are connected, forming a closed shape). If set to `False`, the length is calculated as an open curve. This function calculates the total perimeter of the contour (in pixels) by summing the Euclidean distances between adjacent points on the contour.
[0089] The first roundness threshold needs to be set in conjunction with the morphological characteristics of the macula. For example, a large number of real macula samples can be collected, their roundness values can be calculated, and the minimum roundness of the macula can be obtained statistically (usually the macula is roughly circular, and the roundness is mostly concentrated between 0.6 and 1.0). The first roundness threshold is set as the lower limit of the minimum roundness of the macula sample (such as 0.6), which ensures that long strip-shaped scratches and irregular dust (roundness < 0.6) are filtered out, while not missing normal macula.
[0090] The grayscale mean reflects the overall brightness of the candidate pixel region. For example, the calculation steps are as follows: Obtain the smallest bounding rectangle of the candidate region based on its contour, and extract the grayscale image region (ROI) within this rectangle; calculate the arithmetic mean of the grayscale values of all pixels within the ROI, using the following formula:
[0091] Gray mean =
[0092] in, is the grayscale value of the i-th pixel within the ROI, and n is the total number of pixels within the ROI.
[0093] The grayscale threshold needs to be set based on the brightness difference between the yellow spot and the cigarette paper background. For example, the mean grayscale value of the background area of the defective cigarette (denoted as Bmean) and the mean grayscale value of the yellow spot area (denoted as Mmean) are collected respectively, and the grayscale difference ΔG = Mmean - Bmean is calculated. The grayscale threshold is set to Bmean + k × ΔG (k is 0.3~0.5). For example, if the mean background value is 150 and the mean yellow spot value is 180 (grayscale difference 30), then the grayscale threshold is set to 150 + 15 = 165.
[0094] In S140, the preset model can use the YOLO image detection model as the base model. The YOLO image detection model uses FocalLoss (α=0.25, γ=2) as the loss function to solve the class imbalance problem of "more normal smoke samples and fewer yellow spot smoke samples" and improve the recall rate of yellow spot smoke. The YOLO image detection model uses YOLOv8n fully connected layers as the backbone architecture.
[0095] The training data for the YOLO image detection model is constructed as follows: First, images of cigarettes covering mainstream cigarette paper colors such as brown and white are selectively collected to ensure that the samples cover different background color features. Then, the LabelImg tool is used to label the "yellow spot regions" in the images with rectangular boxes, strictly controlling the labeling accuracy to ≥99%. Subsequently, the dataset is expanded to 500,000 images to solve the sample imbalance problem through geometric transformations (-15°~15° rotation, horizontal / vertical flip, 0.8~1.2x scaling), lighting simulation (±20% brightness, ±15% contrast, 4000K~6000K color temperature adjustment), and noise addition (Gaussian noise with a variance of 0.01, salt-and-pepper noise with a ratio of 0.005). Finally, the training set, validation set, and test set are divided in a 7:2:1 ratio, and the test set specifically includes 10% "unseen" yellow spot types to simulate new defect scenarios in actual production and ensure the model's generalization ability.
[0096] In this embodiment, commonly used image detection models such as YOLO are used as the base model. The model is trained using the collected training data. Based on the base model, several fully connected layers are added to classify and detect the presence of yellow spots on cigarettes with different colored cigarette paper. Specifically, through annotation, the model learns, through operations such as pooling and convolution, which color and texture features constitute yellow spots.
[0097] Finally, the fully connected layer is fine-tuned to enable the model to quickly adapt these general features to the specific task of "smudged smoke recognition".
[0098] In this embodiment, the preset model is used to determine whether the target pixel region is the first macula region, that is, whether the target pixel region determined by S110-S140 is indeed the macula in the image coordinate system. Therefore, as Figure 4 As shown, S150 may specifically include the following steps:
[0099] S151: Transform the first yellow spot region to the coordinate system of the cigarette to be tested to obtain the second yellow spot region;
[0100] S152: Based on the second preset strategy, determine the second detection result, wherein the second detection result characterizes whether the two second macula regions corresponding to two adjacent camera images are the same, and whether the two second macula regions corresponding to two adjacent camera images can be stitched together to form a macula.
[0101] S153: Calculate the statistical parameters of the macula based on the second detection result.
[0102] In S151, the preset model will output the classification result and confidence level. The classification result represents whether the cigarette to be tested is a yellow-spotted cigarette or not. The classification result with the higher confidence level is selected as the first yellow-spotted region.
[0103] In this embodiment, the first macula region identified in each camera image may be the same macula identified in other camera images, or it may be a single macula whose portion was captured in one camera image and another portion in an adjacent camera image. Therefore, this embodiment needs to determine the actual number and area of macula for all camera images to determine whether it is macula smoke. Since each camera image is based on the corresponding preset camera coordinate system, meaning each camera image has a different coordinate system, each camera image needs to be converted to the coordinate system of the cigarette being tested. Then, by comparing the second macula regions in the same coordinate system, the final number and area of macula can be determined.
[0104] For example, firstly, the preset camera is calibrated to obtain the camera's intrinsic parameters (focal length, principal point coordinates) and extrinsic parameters (rotation matrix R and translation vector T of the camera relative to the cigarette coordinate system). Then, the pixel coordinates of the first macula region (such as the center point or corner point of the contour) are extracted, and the pixel coordinates are back-projected to the three-dimensional coordinates in the camera coordinate system using the camera projection model (pinhole imaging model). Then, the macula coordinates in the camera coordinate system are converted to a cigarette cylindrical coordinate system (or Cartesian coordinate system) with the cigarette axis as the Z-axis, the circumferential direction as the θ-axis, and the radial direction as the r-axis using the coordinate transformation formula (coordinates in the cigarette coordinate system = R⁻¹ × (coordinates in the camera coordinate system - T)). Finally, all pixel coordinates of the macula region are transformed according to this rule to obtain the second macula region in the cigarette coordinate system, thus realizing the three-dimensional positioning and unified representation of the macula position.
[0105] In S152, the second detection result can be determined based on the following method, which refers to the second preset strategy.
[0106] Calculate the similarity parameter of the two second macular regions corresponding to the two adjacent camera images. When the similarity parameter is greater than the similarity threshold, the two second macular regions corresponding to the two adjacent camera images are the same, belonging to the case where the same macular region was captured in the two camera images.
[0107] When the two second macula regions corresponding to two adjacent camera images are not the same, the second roundness of the image after stitching the two second macula regions corresponding to the two adjacent camera images is calculated, and the texture features of the two second macula regions corresponding to the two adjacent camera images are calculated. When the second roundness is greater than the second roundness threshold and the two texture features are the same, the two second macula regions corresponding to the two adjacent camera images are stitched into one macula. This means that the same macula is divided into two parts, one part is captured in one camera image, and the other part is captured in another adjacent camera image.
[0108] In this embodiment, by mapping the macula regions in adjacent camera images to a unified cigarette coordinate system, the similarity parameters such as the position, size, and shape of the two second macula regions are first calculated, and a threshold is used to determine whether they are the same macula (to avoid duplicate counting). If they are determined to be different regions, the roundness feature of the stitched image (to verify whether it conforms to the circular shape of the macula) and texture feature matching (to confirm whether they belong to the same split part of the macula) are further used to identify the macula splitting caused by the circumferential shooting angle, realize the merging of split regions, and ultimately ensure the accurate statistics of the number, position, and shape of cigarette macula, solving the problem of duplicate macula identification and missed splitting in multi-frame shooting.
[0109] After step S150, all camera images are combined to obtain the final macular distribution. Then, based on a preset classification rule, the classification result of the cigarette to be tested is determined. For example, the preset classification rule can be:
[0110] It is necessary to determine whether the number of yellow spots on the cigarettes to be tested is more than two; whether the single yellow spot stain on the cigarettes to be tested is greater than or equal to 2.0 mm; whether the single yellow spot stain on the cigarettes to be tested is 1-2 mm; and whether the single yellow spot stain on the cigarettes to be tested is less than 1 mm. After completing the testing of a batch (containing multiple cigarettes to be tested), the following classification results are obtained: how many cigarettes have yellow spots; how many of the yellow-spotted cigarettes have more than two yellow spots; how many cigarettes have single stains ≥ 2.0 mm; how many cigarettes have single stains 1-2 mm; and how many cigarettes have single stains ≤ 1 mm.
[0111] Therefore, after determining the macula, in S160, statistical parameters can be calculated according to the following method, including quantity and area, specifically:
[0112] After the second preset strategy is applied, the total number of independent macula entities after merging is used as the statistical parameter for the number of maculas. For each merged independent macula, if it is a complete macula, the actual physical area enclosed by the contour in the cigarette coordinate system is calculated based on the pixel-physical size mapping relationship (such as pixel equivalent) calibrated by the camera. (For quasi-circular maculas, the area can be calculated using the circle area formula by fitting the diameter. For irregularly spliced maculas, the pixel area of the complete contour after splicing is counted and converted into physical area.) If it is a spliced and merged macula, the contours of the two second macula regions in the cigarette coordinate system are spliced first, and then the physical area is calculated in the above manner. Finally, the physical areas of all independent maculas are summed to obtain the statistical parameter for the total area of maculas.
[0113] In this embodiment, rapid detection of yellow-spotted cigarette classification can be achieved. After the operator places each yellow-spotted cigarette into a camera array (multiple circumferentially arranged cameras), the classification of the cigarette can be quickly determined according to steps S110-S150. Furthermore, after all cigarettes have been placed, a batch of yellow-spotted cigarettes can be classified and statistically analyzed. In this embodiment, the processing module can be an integrated circuit chip with signal processing capabilities. The aforementioned processing module can be a general-purpose processor. For example, the processor can be a Central Processing Unit (CPU), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, capable of implementing or executing the methods, steps, and logic diagrams disclosed in the embodiments of this application.
[0114] The storage module can be, but is not limited to, random access memory, read-only memory, programmable read-only memory, erasable programmable read-only memory, electrically erasable programmable read-only memory, etc.
[0115] It should be noted that those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the electronic device described above can be referred to the corresponding steps in the aforementioned method, and will not be elaborated further here.
[0116] This application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program that, when run on a computer, causes the computer to perform the yellow-spot smoke classification method as described in the above embodiments.
[0117] Based on the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by hardware or by using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application can be embodied in the form of a software product. This software product can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, mobile hard drive, etc.) and includes several instructions to cause a computer device (such as a personal computer, electronic device, or network device, etc.) to execute the methods described in the various implementation scenarios of this application.
[0118] In the embodiments provided in this application, it should be understood that the disclosed methods can also be implemented in other ways. The method embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of methods and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or part of code, which includes one or more executable instructions for implementing a specified logical function. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions. Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0119] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for classifying yellow-spotted smoke, characterized in that, The method includes: Acquire several camera images, wherein each camera image is captured by a corresponding preset camera, and all the preset cameras are arranged along the circumference of the cigarette to be tested; Based on the first preset strategy, the first outline of the cigarette to be tested in the camera image is obtained; Extract the target pixel region within the first contour to characterize the suspected macula; The camera image containing the target pixel region is input into a preset model, and the first macular region is obtained by filtering all the target pixel regions through the preset model; Based on all the first macular regions, the statistical parameters of the macular region in the cigarette to be tested are determined; Based on the statistical parameters, the classification results are obtained.
2. The method according to claim 1, characterized in that, Between acquiring several camera images and obtaining the first contour of the cigarette to be tested in the camera images based on a first preset strategy, the method further includes: According to the second preset algorithm, the first initial contour of the cigarette to be tested in the camera image is extracted; Calculate the first RGB parameters of the second pixel region within the first initial contour; In a preset template library, a cigarette background color template that matches the camera image is obtained. The preset template library includes multiple cigarette background color templates and a second RGB parameter corresponding to the cigarette background color template. The Euclidean distance between the second RGB parameter and the first RGB parameter of the matching cigarette background color template is minimized. Based on the matching cigarette background color template, the pixel value of each pixel in the second pixel region is corrected to obtain a corrected camera image, and the first contour is determined based on the corrected camera image.
3. The method according to claim 2, characterized in that, The step of obtaining the first contour of the cigarette to be tested in the camera image based on the first preset strategy includes: The corrected camera image is input into the binarization model, and a binarized camera image is obtained through the binarization model. Calculate the intersection-over-union ratio (IoU) of the binarized camera image and the adjacent binarized camera images. When the IoU is less than a preset threshold, correct the mask of the binarized image based on the adjacent binarized camera images to obtain a corrected binarized image. The first contour is determined based on the pixels in the modified binarized image whose pixel values are preset values.
4. The method according to claim 1, characterized in that, The step of extracting the target pixel region within the first contour for characterizing the suspected macula includes: The camera image is converted to grayscale to obtain a grayscale image; Edge detection is performed on the grayscale image to obtain candidate pixel regions within the first contour; Calculate the area, first roundness, and average gray value of the candidate pixel region; Based on the area, the first roundness, and the average grayscale value, the target pixel region is obtained by filtering the candidate pixel regions.
5. The method according to claim 4, characterized in that, The step of selecting the target pixel region from the candidate pixel regions based on the area, the first roundness, and the average grayscale value includes: When the area is greater than the area threshold, the first roundness is greater than the first roundness threshold, and the grayscale mean is greater than the grayscale threshold, the candidate pixel region is the target pixel region.
6. The method according to claim 1, characterized in that, The step of determining the statistical parameters of the macula of the cigarette to be tested based on all the first macular regions includes: The first yellow spot region is transformed to the coordinate system of the cigarette to be tested to obtain the second yellow spot region; Based on the second preset strategy, a second detection result is determined. The second detection result indicates whether the two second macular regions corresponding to two adjacent camera images are the same, and whether the two second macular regions corresponding to two adjacent camera images can be stitched together to form a macula. Based on the second detection result, the statistical parameters of the macula are calculated.
7. The method according to claim 6, characterized in that, The determination of the second detection result based on the second preset strategy includes: Calculate the similarity parameter of the two second macular regions corresponding to the two adjacent camera images. When the similarity parameter is greater than the similarity threshold, the two second macular regions corresponding to the two adjacent camera images are the same. When the two second macula regions corresponding to two adjacent camera images are not the same, the second roundness of the image after stitching the two second macula regions corresponding to the two adjacent camera images is calculated, and the texture features of the two second macula regions corresponding to the two adjacent camera images are calculated. When the second roundness is greater than the second roundness threshold and the two texture features are the same, the two second macula regions corresponding to the two adjacent camera images are stitched into one macula.
8. An electronic device, characterized in that, The electronic device includes a processor and a memory coupled together, the memory storing a computer program that, when executed by the processor, causes the electronic device to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when run on a computer, causes the computer to perform the method as described in any one of claims 1-7.