Tobacco width detection method and device based on residual network, equipment and medium
By preprocessing the tobacco shred image and extracting the target tobacco shred image block, and using the residual network detection model, the problem of difficulty in real-time detection of tobacco shred width in the existing technology is solved, and high-precision tobacco shred width detection is achieved.
Patent Information
- Application Number
- CN202310466051.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2043-04-26
AI Technical Summary
Existing technologies struggle to detect tobacco width in real time while maintaining accuracy, especially for images of soft, overlapping tobacco shreds.
A residual network-based detection method is adopted. The target tobacco image patch is extracted by preprocessing the tobacco image, and the width of the tobacco is detected by the trained residual network detection model.
It enables real-time detection of tobacco width while ensuring detection accuracy, thus improving detection efficiency and accuracy.
Smart Images

Figure CN116612074B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a tobacco shred width detection method and device based on a residual network, an equipment and a medium. BACKGROUND
[0002] The tobacco shred cutting process is one of the important processes in the tobacco production line, which mainly cuts the tobacco leaves with appropriate moisture content and temperature into tobacco shreds with a specified width. The cutting width is one of the main factors affecting the quality of cigarette products, and the width has different effects on the physical indicators and sensory quality of cigarettes.
[0003] The current methods for detecting the width of tobacco shreds mainly include the human eye observation method and the computer vision-based detection method. The human eye observation method relies on manual operation and is prone to errors and low efficiency. The computer vision-based detection method generally consists of two stages of processing methods. In the first stage, the outline image of the tobacco shreds is obtained through image binarization, high-pass filtering, edge detection and other algorithms. In the second stage, the average width is calculated through parallel line algorithm, variable diameter circle algorithm and equidistant scanning method. The detection algorithms involved in the two stages are complex and cannot realize real-time detection of the width of tobacco shreds.
[0004] Therefore, there is an urgent need for a method that can detect the width of tobacco shreds in real time while ensuring accuracy. SUMMARY
[0005] Therefore, the present application provides a tobacco shred width detection method and device based on a residual network, a computer equipment and a computer readable storage medium to solve the problem that it is difficult to detect the width of tobacco shreds in real time while ensuring accuracy in the prior art.
[0006] According to a first aspect, the present application provides a tobacco shred width detection method based on a residual network, which comprises:
[0007] Preprocessing the obtained first tobacco shred image to obtain a second tobacco shred image; the second tobacco shred image is an image with a white background and a black tobacco shred part;
[0008] Extracting a plurality of target tobacco shred image blocks from the second tobacco shred image;
[0009] Inputting the plurality of target tobacco shred image blocks into the trained residual network detection model to obtain the width of the tobacco shreds in the first tobacco shred image.
[0010] In some embodiments, the step of extracting a plurality of target tobacco shred image blocks from the second tobacco shred image comprises:
[0011] Obtaining a connected region in the second tobacco shred image;
[0012] extracting a target connected region from the connected regions according to a preset screening condition; the preset screening condition is a screening condition for screening the connected regions with an area meeting a requirement;
[0013] For each target connected region, a plurality of pixel points are randomly selected from the target connected region as centers of the target tobacco shred image blocks, and a plurality of target tobacco shred image blocks are determined with a preset length as an edge length.
[0014] In some embodiments, the step of obtaining the connected regions in the second tobacco shred image comprises:
[0015] Based on a depth-first traversal algorithm, each black pixel point in the second tobacco shred image is traversed, and in a case where there is an untraversed adjacent black pixel point for any black pixel point, the black pixel point and the adjacent black pixel point are recursively traversed to determine a plurality of connected regions in the second tobacco shred image.
[0016] In some embodiments, after the step of selecting a plurality of pixel points from the target connected region as centers of the first tobacco shred image blocks and determining a plurality of target tobacco shred image blocks with a preset length as an edge length, the method further comprises:
[0017] In a case where the boundary of the determined target tobacco shred image block exceeds the target connected region, the pixel values of the exceeding part are determined as preset pixel values.
[0018] In some embodiments, before the step of preprocessing the obtained first tobacco shred image, the method further comprises:
[0019] extracting a plurality of historical tobacco shred image blocks from a third tobacco shred image; the third tobacco shred image is a historical image;
[0020] annotating the tobacco shred width in the historical tobacco shred image blocks;
[0021] dividing the historical tobacco shred image blocks with annotated tobacco shred widths into a training set and a validation set according to a preset proportion;
[0022] performing at least one round of model training on the residual network detection model based on the training set; the residual network detection model is a neural network model with a residual network as a network structure;
[0023] detecting the tobacco shred width of the validation set based on the residual network detection model that has undergone model training to obtain a detection result;
[0024] in a case where the detection result does not meet a preset standard condition, returning to the step of performing at least one round of model training on the residual network detection model based on the training set.
[0025] In a case where the detection result meets a preset standard condition, a trained residual network detection model is obtained.
[0026] In some embodiments, the step of extracting a plurality of historical tobacco image blocks from the third tobacco image comprises:
[0027] The third tobacco image is preprocessed to obtain a fourth tobacco image;
[0028] A connected region in the fourth tobacco image is obtained;
[0029] A target connected region is extracted from the connected region according to a preset screening condition;
[0030] For each target connected region, a plurality of pixel points are randomly selected from the target connected region as centers of the historical tobacco image blocks, and a plurality of historical tobacco image blocks are determined with a preset length as a side length.
[0031] In some embodiments, the preprocessing comprises grayscale processing and binary processing;
[0032] The grayscale processing is used to assign corresponding weights to red, green and blue channels of a tobacco image respectively to obtain a corresponding grayscale image;
[0033] The binary processing is used to divide pixel points into white or black according to the grayscale of the grayscale image to distinguish background parts and tobacco parts.
[0034] According to a second aspect, an embodiment of the present application provides a tobacco width detection device based on a residual network, which comprises:
[0035] A preprocessing unit is configured to preprocess a first tobacco image obtained to obtain a second tobacco image; the second tobacco image is an image with a white background part and a black tobacco part;
[0036] An extraction unit is configured to extract a plurality of target tobacco image blocks from the second tobacco image;
[0037] A detection unit is configured to input the plurality of target tobacco image blocks into a trained residual network detection model to obtain a tobacco width in the first tobacco image.
[0038] According to a third aspect, an embodiment of the present application provides a computer device, characterized in that comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the method for detecting tobacco width based on residual network according to the first aspect.
[0039] According to a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps of the method for detecting tobacco width based on residual network according to the first aspect.
[0040] The technical scheme of the present application has the following advantages:
[0041] The embodiment of the present application provides a method, device, equipment and medium for detecting tobacco width based on residual network, which comprises the following steps: first, preprocessing the obtained first tobacco image to obtain a second tobacco image; wherein the second tobacco image is an image with white background and black tobacco; then extracting a plurality of target tobacco image blocks from the second tobacco image; finally, inputting the plurality of target tobacco image blocks into the trained residual network detection model to obtain the tobacco width in the first tobacco image, which can effectively realize real-time tobacco width detection while ensuring detection accuracy. BRIEF DESCRIPTION OF DRAWINGS
[0042] In order to more clearly illustrate the specific embodiments of the present application or the technical scheme in the prior art, the following will briefly introduce the drawings needed to be used in the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present application, and those skilled in the art can obtain other drawings according to these drawings without creative labor:
[0043] Figure 1 The flow chart of the method for detecting tobacco width based on residual network provided by the embodiment of the present application.
[0044] Figure 2 The flow chart of the method for extracting target tobacco image blocks provided by the embodiment of the present application.
[0045] Figure 3 The flow chart of the method for training residual network detection model provided by the embodiment of the present application.
[0046] Figure 4 The structural schematic diagram of the device for detecting tobacco width based on residual network provided by the embodiment of the present application.
[0047] Figure 5 A structural schematic diagram of a computer device is also provided for the embodiments of the present application. DETAILED DESCRIPTION
[0048] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in connection with the drawings of the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present application.
[0049] The tobacco cutting process is one of the important processes in the tobacco production line, mainly cutting the tobacco strips with appropriate moisture content and temperature into tobacco of a specified width. The cutting width is one of the main factors affecting the quality of the cigarette product, and the width has different effects on the physical indicators and sensory quality of the cigarette.
[0050] The current computer vision-based detection method involves complex detection algorithms, which cannot detect the tobacco width in real time. For example, when detecting the tobacco width through a convolution network, first, a single tobacco is identified in a plurality of different types of tobaccos, then the tobacco contour pixels are encoded through a Freeman chain code, and finally the tobacco width is calculated based on the incircle of the closed chain code. This method has a large amount of calculation when measuring the width, which is not conducive to the measurement of wide tobacco. In another tobacco image recognition technology based on a U-shaped network (U-Net), the trained neural network is used to segment the tobacco contour of the densely distributed tobacco image. After completing the image segmentation, the image thinning algorithm is used to obtain the skeleton line of the tobacco, and the average width of the tobacco is calculated through the length of the skeleton line and the area of the connected domain. This method needs to perform image segmentation on a large amount of tobacco when detecting the clustered tobacco, and has high detection time cost.
[0051] Therefore, there is an urgent need for a method that can detect the tobacco width in real time while ensuring accuracy.
[0052] The embodiments of the present application provide a tobacco width detection method based on a residual network, which detects the tobacco width of pictures of soft and overlapping tobaccos, to solve the problem that it is difficult to detect the tobacco width in real time while ensuring accuracy in the prior art.
[0053] Figure 1 A flowchart of a tobacco width detection method based on a residual network is provided for the embodiments of the present application. As shown in Figure 1 The method comprises steps S1-S3.
[0054] Step S1, pre-processing the obtained first tobacco image to obtain a second tobacco image.
[0055] The first tobacco image is a real-time image of tobacco, and the first tobacco image includes a background part and a tobacco part. The background part refers to an image part in which there is no tobacco. The tobacco part has an overlapping relationship between tobaccos.
[0056] In some embodiments, the first tobacco image can be obtained by an image acquisition device. For example, a pre-configured camera can be used to capture a tobacco image in real time, which is taken as the obtained first tobacco image. The image acquisition device can be a camera, a video recorder, or the like, which is not specifically limited in the embodiment.
[0057] The pre-processing refers to a standardization process of the first tobacco image, which can distinguish the background part from the tobacco part in the first tobacco image. The second tobacco image obtained by the pre-processing is an image in which the background part is white and the tobacco part is black.
[0058] In an embodiment, the pre-processing includes grayscale processing and binary processing.
[0059] The grayscale processing is used to assign corresponding weights to the red, green, and blue channels of the tobacco image to obtain a corresponding grayscale image. For example, the grayscale processing can be weighted average grayscale processing, in which the red, green, and blue channels of the tobacco image are respectively assigned corresponding weights: 0.299, 0.587, and 0.114.
[0060] The binary processing is used to divide the pixel points into white or black according to the grayscale of the grayscale image to distinguish the background part from the tobacco part. For example, a grayscale threshold can be set, and a pixel point is configured as white (pixel value is configured as 255) if the grayscale of the pixel point is less than the grayscale threshold, and the pixel point is configured as black (pixel value is configured as 0) if the grayscale of the pixel point is equal to or greater than the grayscale threshold.
[0061] In the embodiment, the first tobacco image is first subjected to grayscale processing to obtain a corresponding grayscale image, and then in the process of binary processing, the grayscale difference between the background part and the tobacco part is utilized to divide all pixel points in the image into two levels of white and black by setting a grayscale threshold, thereby obtaining a second tobacco image in which the background part is white and the tobacco part is black. This can realize standardization of the first tobacco image, simplify image information, reduce information quantity, and facilitate subsequent extraction of tobacco features from the first tobacco image.
[0062] Step S2, extracting a plurality of target tobacco image blocks from the second tobacco image.
[0063] The target tobacco image block is an image block (patch) containing and only containing one tobacco connected region. The tobacco connected region refers to a tobacco image region formed by pixels with black color (pixel value of 0) and adjacent positions.
[0064] In the embodiment, the plurality of target tobacco image blocks are extracted from the second tobacco image, so that the details of the tobacco image can be extracted, and data basis for improving the recognition accuracy of the tobacco width is provided.
[0065] It should be noted that, in order to further realize the detail extraction of the tobacco image, the one tobacco connected region contained in the target tobacco image block can not be a complete connected region in the second tobacco image, but only a part of the complete connected region. In the plurality of target tobacco image blocks, the tobacco connected regions in some target tobacco image blocks can jointly constitute a complete connected region in the second tobacco image.
[0066] In step S3, the plurality of target tobacco image blocks are input into the trained residual network detection model, and the tobacco width in the first tobacco image is obtained.
[0067] The residual network detection model is a neural network model with a residual network (ResNet) as the network structure.
[0068] The residual network refers to a network that solves the gradient vanishing problem in a deep network by introducing a residual connection. The residual connection refers to a network connection manner in which each convolutional layer in the residual network is not directly mapped from the input to the output, but the input is added to the output.
[0069] It should be noted that one advantage of the neural network is that it can represent a complex function. Generally, the more layers of the neural network, the more rich features of different levels that the neural network can extract. However, continuously increasing the number of layers of the neural network will cause the problem of gradient dispersion or gradient explosion, and the accuracy of the neural network will not increase but decrease. The residual network can solve the problem of gradient dispersion or gradient explosion in the deep network through the above residual connection, realize the construction of the deep neural network, and improve the accuracy of the network. In addition, compared with a common neural network with the same depth, the residual network can accelerate the convergence speed, and can improve the network processing performance while ensuring the accuracy of the network.
[0070] Therefore, in the embodiment, the tobacco width in the first tobacco image is detected by the trained residual network detection model, so that the real-time tobacco width detection can be effectively realized while ensuring the detection accuracy.
[0071] The embodiment of the present application provides a kind of based on residual network's tobacco width detection method, this method includes: first, the first tobacco image obtained is preprocessed, obtains second tobacco image;Wherein, second tobacco image is the image that background part is white, tobacco part is black;Then, multiple target tobacco image blocks are extracted from the second tobacco image;Finally, multiple target tobacco image blocks are input into trained residual network detection model, obtain the tobacco width in first tobacco image, can effectively realize the real-time detection of tobacco width in the case where guaranteeing detection accuracy.
[0072] Figure 2 It is the flow chart of the method for extracting target tobacco image block provided by the embodiment of the present application.As shown in Figure 2 As shown in the figure, the step of extracting multiple target tobacco image blocks from the second tobacco image includes: step S21-step S23.
[0073] Step S21, the connected region in second tobacco image is acquired.
[0074] Wherein, connected region refers to the region that color is black (pixel value is 0) and position adjacent pixel point constitutes.
[0075] In an embodiment, the step of acquiring the connected region in the second tobacco image includes: based on depth-first traversal algorithm, each black pixel point in the second tobacco image is traversed, and in the case that there is untraversed adjacent black pixel point for any black pixel point, the black pixel point and the adjacent black pixel point are recursively traversed to determine multiple connected regions in the second tobacco image.
[0076] In the embodiment, when each black pixel point in the second tobacco image is traversed based on depth-first traversal algorithm, the connected region can be determined by four-connected and eight-connected method. Wherein, four-connected represents that if a pixel is connected with the pixels in the upper, lower, left and right four directions, then the connected pixels belong to one connected region;Eight-connected represents that if a pixel is connected with the pixels in the upper, lower, left, right, upper left, lower left, upper right and lower right directions, then the connected pixels belong to one connected region. In the present embodiment, the method of eight-connected is preferred to determine the connected region.
[0077] In an embodiment, in the process of acquiring the connected region in the second tobacco image, the area of the connected region can be determined simultaneously.
[0078] Step S22, according to the preset screening condition, target connected region is extracted from the connected region.
[0079] The preset filtering criteria are used to filter connected regions whose area meets the requirements. For example, the preset filtering criteria can be an area threshold. If the area of a connected region is less than the area threshold, the connected region does not meet the preset filtering criteria; if the area of a connected region is greater than or equal to the area threshold, the connected region meets the preset filtering criteria and can be identified as the target connected region.
[0080] In this embodiment, the target connected region is extracted from the connected region according to the preset screening conditions, which can filter out the connected regions that meet the preset screening conditions and improve the quality of the data used for tobacco width detection.
[0081] Step S23: For each target connected region, randomly select multiple pixels from the target connected region as the center of the target tobacco image block, and determine multiple target tobacco image blocks with a preset length as the side length.
[0082] The preset length can be set according to the actual application, and is not specifically limited in this embodiment. In this embodiment, the determined target tobacco image block is generally square.
[0083] In this embodiment, multiple target tobacco image blocks are extracted from the second tobacco image, which enables the extraction of details from the tobacco image and provides a data foundation for improving the accuracy of tobacco width recognition.
[0084] In one embodiment, after randomly selecting multiple pixels from each target connected region as the center point of a first tobacco image block and determining multiple target tobacco image blocks with a preset length as the side length, the method further includes: if the boundary of the determined target tobacco image block extends beyond the target connected region, determining the pixel value of the extended portion as a preset pixel value. This preset pixel value can be 255, meaning the extended portion is configured as white to avoid its influence on the tobacco image.
[0085] Figure 3 This is a flowchart illustrating a residual network detection model training method provided in an embodiment of the present invention. Figure 3 As shown, the method for training a residual network detection model before preprocessing the acquired first tobacco image includes steps S01-S07.
[0086] Step S01: Extract multiple historical tobacco image blocks from the third tobacco image.
[0087] The third image of tobacco shreds is a historical image.
[0088] In one embodiment, the step of extracting multiple historical tobacco image blocks from a third tobacco image includes the following steps one through four.
[0089] Step one, pre-processing the third tobacco image to obtain a fourth tobacco image.
[0090] The pre-processing process can refer to the detailed description of the pre-processing process in the foregoing embodiments, and will not be described here again.
[0091] Step two, obtaining a connected region in the fourth tobacco image.
[0092] The method of obtaining a connected region in the fourth tobacco image can refer to the detailed description of the method of obtaining a connected region in the second tobacco image, and will not be described here again.
[0093] Step three, extracting a target connected region from the connected region according to a preset screening condition.
[0094] The preset screening condition is a screening condition for screening a connected region with an area meeting a requirement. For example, the preset screening condition can be an area threshold. In a case where the area of the connected region is less than the area threshold, the connected region does not meet the preset screening condition. In a case where the area of the connected region is greater than or equal to the area threshold, the connected region meets the preset screening condition, and can be determined as the target connected region.
[0095] Step four, for each target connected region, randomly selecting a plurality of pixel points in the target connected region as centers of historical tobacco image blocks respectively, and determining a plurality of historical tobacco image blocks with a preset length as a side length.
[0096] The preset length can be set according to actual application conditions, and is not specifically limited in this embodiment. In this embodiment, the determined target tobacco image block is generally a square.
[0097] In this embodiment, a plurality of target tobacco image blocks are extracted from the fourth tobacco image, which can realize the extraction of details of the tobacco image, and provide a data basis for improving the recognition accuracy of the tobacco width.
[0098] Step S02, labeling the tobacco width in the historical tobacco image block.
[0099] In some embodiments, the training personnel can label the tobacco width in the historical tobacco image block through the operation interface of the electronic device, such as the operation interface displayed on the terminal such as a computer, a tablet, etc.
[0100] Step S03, dividing the historical tobacco image block with the labeled tobacco width into a training set and a validation set according to a preset proportion.
[0101] The training set is a set of image blocks used for model training of the residual network detection model; and the verification set is a set of image blocks used for detection effect verification of the trained residual network detection model.
[0102] The preset ratio refers to the number ratio of image blocks allocated to the training set and the verification set. The preset ratio can be set according to actual application conditions, for example, set to 5:1, or set to 5:2, and the embodiment is not specifically limited.
[0103] Step S04: performing at least one round of model training on the residual network detection model based on the training set.
[0104] The residual network detection model is a neural network model with a residual network as the network structure.
[0105] The residual network refers to a network that solves the gradient vanishing problem in a deep network by introducing a residual connection. The residual connection refers to a network connection mode in which each convolutional layer in the residual network is not directly mapped from input to output, but the input is added to the output. The residual network can solve the gradient dispersion or gradient explosion problem in the deep network through the above residual connection, realize deep neural network construction, and improve the accuracy of the network.
[0106] In addition, the traditional convolutional layer or fully connected layer has the problem of information loss and loss when transmitting information, while the residual network can protect the integrity of information by directly transmitting the input to the output, and the residual network only needs to learn the difference between the input and the output. Therefore, the model training of the residual network detection model based on the training set in the embodiment can simplify the difficulty of obtaining a high-precision cut tobacco width detection model.
[0107] Step S05: detecting the cut tobacco width of the verification set based on the residual network detection model trained by the model, and obtaining a detection result.
[0108] The detection result includes the cut tobacco width detected by the residual network detection model trained by the model for the verification set.
[0109] Since the historical cut tobacco image blocks in the verification set have been labeled with the cut tobacco width, the accuracy of the detection result of the residual network detection model trained by the model can be determined based on the labeled cut tobacco width.
[0110] Step S06: determining whether the detection result meets a preset standard condition.
[0111] In this embodiment, the detection effect of the residual network detection model trained by the model can be evaluated by determining whether the detection result meets the preset standard condition. The preset standard condition can be set according to actual application, for example, the accuracy is greater than 95%.
[0112] In the case where the detection result does not meet the preset standard condition, the step of performing at least one round of model training on the residual network detection model based on the training set (step S04) is returned.
[0113] In the case where the detection result does not meet the preset standard condition, it indicates that the detection effect of the residual network detection model trained by the model does not meet the expectation, and the model training needs to be continued, so the step of performing at least one round of model training on the residual network detection model based on the training set is returned.
[0114] Step S07, in the case where the detection result meets the preset standard condition, obtaining the trained residual network detection model.
[0115] In the case where the detection result does not meet the preset standard condition, it indicates that the detection effect of the residual network detection model trained by the model meets the expectation, and the model training does not need to be continued.
[0116] The embodiment of the present application obtains the trained residual network detection model by the residual network detection model training method, and detects the tobacco width based on the trained residual network detection model, which can effectively realize the real-time detection of the tobacco width while ensuring the detection accuracy.
[0117] Figure 4 A structure schematic diagram of a tobacco width detection device based on a residual network provided by the embodiment of the present application is shown in FIG. 1. Figure 4 As shown in the figure, the device comprises a preprocessing unit 41, an extraction unit 42 and a detection unit 43.
[0118] The preprocessing unit 41 is used for preprocessing the obtained first tobacco image to obtain a second tobacco image, wherein the second tobacco image is an image with white background and black tobacco.
[0119] The extraction unit 42 is used for extracting a plurality of target tobacco image blocks from the second tobacco image.
[0120] In one embodiment, the extraction unit 42 comprises an acquisition subunit, a screening subunit, a selection subunit and an adjustment subunit.
[0121] The acquisition subunit is used for acquiring a connected region in the second tobacco image.
[0122] In an embodiment, the acquisition subunit is further configured to traverse each black pixel point in the second cut tobacco image based on a depth-first traversal algorithm, and recursively traverse any black pixel point and adjacent black pixel points of the black pixel point in a case where the black pixel point has untraversed adjacent black pixel points, so as to determine the plurality of connected regions in the second cut tobacco image.
[0123] The screening subunit is configured to extract target connected regions from the connected regions according to a preset screening condition; the preset screening condition is a screening condition for screening connected regions with areas meeting requirements.
[0124] The selection subunit is configured to, for each target connected region, randomly select a plurality of pixel points from the target connected region as centers of target cut tobacco image blocks, and determine a plurality of target cut tobacco image blocks with a preset length as a side length.
[0125] The adjustment subunit is configured to, in a case where a boundary of the determined target cut tobacco image block exceeds the target connected region, determine pixel values of the exceeding part as preset pixel values.
[0126] The detection unit 43 is configured to input the plurality of target cut tobacco image blocks into the trained residual network detection model, and obtain the cut tobacco width in the first cut tobacco image.
[0127] In an embodiment, the cut tobacco width detection device based on the residual network further comprises a model training unit.
[0128] The model training unit is configured to extract a plurality of historical cut tobacco image blocks from a third cut tobacco image; the third cut tobacco image is a historical image; the model training unit is further configured to label the cut tobacco width in the historical cut tobacco image blocks; the model training unit is further configured to divide the historical cut tobacco image blocks after labeling the cut tobacco width into a training set and a verification set according to a preset ratio; the model training unit is further configured to perform at least one round of model training on the residual network detection model based on the training set, wherein the residual network detection model is a neural network model with a residual network as a network structure; the model training unit is further configured to perform cut tobacco width detection on the verification set based on the residual network detection model after the model training, and obtain a detection result; in a case where the detection result does not meet a preset standard condition, return to the step of performing at least one round of model training on the residual network detection model based on the training set; and in a case where the detection result meets the preset standard condition, obtain the trained residual network detection model.
[0129] In an embodiment, the model training unit is further configured to pre-process the third cut tobacco image to obtain a fourth cut tobacco image; acquire connected regions in the fourth cut tobacco image; extract target connected regions from the connected regions according to a preset screening condition; and for each target connected region, randomly select a plurality of pixel points from the target connected region as centers of historical cut tobacco image blocks, and determine a plurality of historical cut tobacco image blocks with a preset length as a side length.
[0130] In an embodiment, the preprocessing includes a grayscale processing and a binary processing; the grayscale processing is used to assign corresponding weights to the red, green and blue channels of the tobacco image respectively to obtain a corresponding grayscale image; and the binary processing is used to divide the pixel points into white or black according to the grayscale of the grayscale image to distinguish the background part and the tobacco part.
[0131] The embodiment of the present application provides a tobacco width detection device based on a residual network, wherein a preprocessing unit is used to preprocess a first tobacco image to obtain a second tobacco image; the second tobacco image is an image with a white background and a black tobacco part; an extraction unit is used to extract a plurality of target tobacco image blocks from the second tobacco image; and a detection unit is used to input the plurality of target tobacco image blocks into a trained residual network detection model to obtain the tobacco width in the first tobacco image, so that the real-time detection of the tobacco width can be effectively realized while ensuring the detection accuracy.
[0132] Figure 5 The embodiment of the present application also provides a structural schematic diagram of a computer device. As shown in the figure, the computer device can include a processor 501 and a memory 502, wherein the processor 501 and the memory 502 can be connected through a bus or other means, Figure 5 for example, taking the bus connection as an example. Figure 5
[0133] The processor 501 can be a central processing unit (CPU). The processor 501 can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. chips, or combinations of the above various chips.
[0134] The memory 502 is a non-transitory computer readable storage medium, which can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as the program instructions / modules of the tobacco width detection method based on the residual network in the embodiment of the present application. The processor 501 executes various functions of the processor and data processing by running the non-transitory software programs, instructions and modules stored in the memory 502, that is, realizes the tobacco width detection method based on the residual network in the above method embodiment.
[0135] The memory 502 can include a program storage area and a data storage area, where the program storage area can store an operating system, at least one application required by a function, and the data storage area can store data created by the processor 501 and the like. In addition, the memory 502 can include a high-speed random access memory, and can also include a non-transitory memory such as at least one disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory 502 can optionally include a memory disposed remotely with respect to the processor 501, which can be connected to the processor 501 through a network. Examples of the above network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0136] One or more modules are stored in the memory 502, which, when executed by the processor 501, perform the above-described methods. Figure 1 The residual network-based cut tobacco width detection method in the illustrated embodiment.
[0137] The above computer device specific details can be understood in correspondence with the relevant descriptions and effects of the corresponding embodiments illustrated in the Figure 1 The above computer device specific details can be understood in correspondence with the relevant descriptions and effects of the corresponding embodiments illustrated in the
[0138] Those skilled in the art can understand that all or part of the processes in the above-described embodiments can be completed by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-described embodiments. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc. The storage medium can also include a combination of the above types of memories.
[0139] Although the embodiments of the present application are described in conjunction with the accompanying drawings, various modifications and changes can be made by those skilled in the art without departing from the spirit and scope of the present application, and such modifications and changes fall within the scope defined by the appended claims.
Claims
1. A method for detecting the width of tobacco based on a residual network, characterized in that, The method comprises: preprocessing the obtained first tobacco image to obtain a second tobacco image; the second tobacco image is an image with a white background and a black tobacco part; extracting a plurality of target tobacco image blocks from the second tobacco image; inputting the plurality of target tobacco image blocks into a trained residual network detection model to obtain the tobacco width in the first tobacco image; wherein the step of extracting a plurality of target tobacco image blocks from the second tobacco image comprises: obtaining a connected region in the second tobacco image; extracting a target connected region from the connected region according to a preset screening condition; the preset screening condition is a screening condition for screening the connected region with a required area; for each target connected region, randomly selecting a plurality of pixel points in the target connected region as the centers of the target tobacco image blocks, and determining a plurality of target tobacco image blocks with a preset length as the edge length; the step of obtaining a connected region in the second tobacco image comprises: based on a depth-first traversal algorithm, traversing each black pixel point in the second tobacco image, and in the case that there is an untraversed adjacent black pixel point at any black pixel point, recursively traversing the black pixel point and the adjacent black pixel point to determine a plurality of connected regions in the second tobacco image, wherein the connected regions are determined by four-connected and eight-connected methods; after the step of for each target connected region, randomly selecting a plurality of pixel points in the target connected region as the centers of the first tobacco image blocks, and determining a plurality of target tobacco image blocks with a preset length as the edge length, further comprising: in the case that the boundary of the determined target tobacco image block exceeds the target connected region, determining the pixel value of the exceeding part as a preset pixel value.
2. The method of claim 1, wherein, before the step of preprocessing the obtained first tobacco image, further comprising: extracting a plurality of historical tobacco image blocks from a third tobacco image; the third tobacco image is a historical image; labeling the tobacco width in the historical tobacco image blocks; dividing the historical tobacco image blocks with labeled tobacco width into a training set and a validation set according to a preset ratio; performing at least one round of model training on the residual network detection model based on the training set; the residual network detection model is a neural network model with a residual network as the network structure; performing tobacco width detection on the validation set based on the residual network detection model after model training to obtain a detection result; in the case that the detection result does not meet the preset standard condition, returning to the step of performing at least one round of model training on the residual network detection model based on the training set; in the case that the detection result meets the preset standard condition, obtaining the trained residual network detection model.
3. The method of claim 2, wherein, the step of extracting a plurality of historical tobacco image blocks from a third tobacco image comprises: preprocessing the third tobacco image to obtain a fourth tobacco image; obtaining a connected region in the fourth tobacco image; extracting a target connected region from the connected region according to a preset screening condition; For each target connected region, a plurality of pixel points in the target connected region are randomly selected as centers of the historical cut tobacco image blocks respectively, and a plurality of the historical cut tobacco image blocks are determined with a preset length as a side length.
4. The method according to claim 1 or 3, characterized in that, The preprocessing comprises a grayscale processing and a binary processing. The grayscale processing is used for assigning corresponding weights to three channels of red, green and blue of the cut tobacco image respectively to obtain a corresponding grayscale image. The binary processing is used for dividing pixel points into white or black according to the grayscale of the grayscale image to distinguish the background part and the cut tobacco part.
5. A residual network-based cut tobacco width detection apparatus, characterized by, The device comprises: a preprocessing unit configured to preprocess the acquired first cut tobacco image to obtain a second cut tobacco image, the second cut tobacco image being an image with a white background part and a black cut tobacco part; an extraction unit configured to extract a plurality of target cut tobacco image blocks from the second cut tobacco image; a detection unit configured to input the plurality of target cut tobacco image blocks into a trained residual network detection model to obtain a cut tobacco width in the first cut tobacco image; The extraction unit comprises an acquisition subunit, a screening subunit, a selection subunit and an adjustment subunit. The acquisition subunit is configured to acquire connected regions in the second cut tobacco image. The screening subunit is configured to extract target connected regions from the connected regions according to a preset screening condition. The preset screening condition is a screening condition for screening the connected regions with areas meeting requirements. The selection subunit is configured to, for each target connected region, randomly select a plurality of pixel points in the target connected region as centers of the target cut tobacco image blocks respectively, and determine a plurality of the target cut tobacco image blocks with a preset length as a side length. The adjustment subunit is configured to, in a case where a boundary of a determined target cut tobacco image block exceeds a target connected region, determine pixel values of the exceeding part as preset pixel values. The acquisition subunit is further configured to traverse each black pixel point in the second cut tobacco image based on a depth-first traversal algorithm, and in a case where there is an untraversed adjacent black pixel point for any black pixel point, recursively traverse the black pixel point and the adjacent black pixel point to determine a plurality of connected regions in the second cut tobacco image, wherein the connected regions are determined by a four-connected and eight-connected method.
6. A computer device, comprising: comprises: at least one processor; and a memory connected in communication with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to cause the at least one processor to perform the steps of the residual network-based cut tobacco width detection method according to any one of claims 1-4.
7. A computer-readable storage medium having stored thereon a computer program, characterized in that The computer program is executed by the processor to implement the steps of the residual network-based cut tobacco width detection method according to any one of claims 1-4.
Citation Information
Patent Citations
Tobacco or stem width measuring method, system and server with same
CN107798672A
Fine defect analysis method based on progressive segmentation network
CN114612444A