Method and device for detecting the number of circular solid objects, electronic equipment and storage medium
By performing initial contour extraction and shape template matching on the original image of the filter rod, and combining the watershed algorithm and affine transformation matrix, the problems of low efficiency and false detection in filter rod quantity detection are solved, and efficient and accurate filter rod quantity detection is achieved.
Patent Information
- Application Number
- CN202211606371.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-12
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2042-12-12
AI Technical Summary
Existing technologies have low efficiency in detecting the number of filter rods and are prone to false detections, making accurate detection impossible.
By acquiring the original image of the filter rod, initial contour extraction and shape template matching are performed. Combined with the watershed algorithm and affine transformation matrix, the number of filter rods is accurately located.
This improves the efficiency and accuracy of filter rod quantity detection, reduces the risk of false detection by human eye, and achieves efficient and accurate filter rod quantity detection.
Smart Images

Figure CN116205849B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image processing technology, and in particular to a method, apparatus, electronic device, and readable storage medium for detecting the number of circular solid objects. Background Technology
[0002] In the tobacco industry, cigarettes are typically equipped with filter rods to alter the quality of the cigarette smoke. The filter rods are cut into multiple small segments on a cigarette packaging machine, then wrapped in tipping paper and adhered to the cigarette to create a cigarette with a filter. The number of filter rods used in each cigarette needs to be counted both during the actual production of the filter rods and during the cigarette manufacturing process.
[0003] The relevant technology has a relatively simple process for detecting the number of filter rods, which only involves manual detection. However, manual detection is inevitably prone to false detections due to eye fatigue among staff, and the detection efficiency is low.
[0004] Therefore, how to accurately detect the number of filter rods in real time is a technical problem that needs to be solved by technicians in this field. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and readable storage medium for detecting the quantity of round solid objects, which can efficiently and accurately detect the quantity of filter rods.
[0006] To address the aforementioned technical problems, the embodiments of the present invention provide the following technical solutions:
[0007] One embodiment of the present invention provides a method for detecting the quantity of circular solid objects, comprising:
[0008] Acquire the original image of the filter rod to be inspected;
[0009] The initial contour of each filter rod contained in the original image of the filter rod is extracted to obtain an initial filter rod contour image;
[0010] Based on the original image of the filter rod, a shape template is determined, and each filter rod is positioned according to the shape template to obtain a filter rod positioning contour image;
[0011] Based on the initial filter rod outline image and the filter rod positioning outline image, the number of filter rods contained in the original filter rod image is determined.
[0012] Optionally, the step of extracting the initial contour of each filter rod contained in the original image of the filter rod to obtain an initial filter rod contour image includes:
[0013] The original image of the filter rod is subjected to global threshold segmentation to obtain a binarized image;
[0014] For each pixel in the binarized image, the pixel value of the pixel closest to the current pixel is assigned to the current pixel to generate a Euclidean distance transform image;
[0015] Based on the watershed algorithm, the pixels in the Euclidean distance transformation image that meet the preset spatial-pixel similarity condition are connected to form a contour, thereby obtaining the contour of each filter rod in the original image of the filter rod.
[0016] Based on the global threshold segmentation algorithm, the initial filter rod contour image is obtained by filtering by area and roundness.
[0017] Optionally, the step of connecting pixels in the Euclidean distance transform image that satisfy a preset spatial-pixel proximity condition to form a contour based on the watershed algorithm includes:
[0018] For each pixel in the Euclidean distance transformation map, pixels that are spatially adjacent and whose grayscale value difference is less than a preset value are connected to form a closed contour.
[0019] Optionally, the step of locating each filter rod according to the shape template to obtain a filter rod positioning contour image includes:
[0020] The original image of the filter rod is processed based on the contrast enhancement algorithm to obtain a preprocessed image;
[0021] Based on the shape template, template matching is performed on the filter rods identified in the preprocessed image to obtain a filter rod positioning contour image.
[0022] Optionally, determining the shape template based on the original image of the filter rod includes:
[0023] The diameter of the target filter rod is extracted from the original image of the filter rod, and a shape template is generated based on the diameter.
[0024] Optionally, the step of locating each filter rod according to the shape template to obtain a filter rod positioning contour image includes:
[0025] Based on the shape template matching algorithm, the initial positioning of the filter rod through the origin is obtained;
[0026] Based on the affine transformation matrix, the initial positioning of each filter rod through the origin coordinates is translated and scaled to determine the position of each filter rod.
[0027] Generate a filter rod positioning contour image based on the position of each filter rod.
[0028] Optionally, the process of determining the number of filter rods contained in the original filter rod image based on the initial filter rod contour image and the filter rod positioning contour image includes:
[0029] Based on whether there is an intersection between the filter rods at corresponding positions in the initial filter rod contour image and the filter rod positioning contour image, the number of filter rods contained in the original filter rod image is determined.
[0030] Another embodiment of the present invention provides a device for detecting the quantity of circular solid objects, comprising:
[0031] The image acquisition module is used to acquire the original image of the filter rod to be detected;
[0032] The initial contour extraction module is used to extract the initial contours of each filter rod contained in the original image of the filter rod to obtain an initial filter rod contour image.
[0033] The secondary contour extraction module is used to determine the shape template based on the original image of the filter rod, and to locate each filter rod according to the shape template to obtain the filter rod positioning contour image;
[0034] The quantity detection module is used to determine the number of filter rods contained in the original image of the filter rods based on the initial filter rod outline image and the filter rod positioning outline image.
[0035] This invention also provides an electronic device, including a processor, which executes a computer program stored in a memory to implement the steps of the method for detecting the number of circular solid objects as described in any of the preceding claims.
[0036] Finally, this embodiment of the invention also provides a readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method for detecting the quantity of circular solid objects as described in any of the preceding claims.
[0037] The advantage of the technical solution provided in this application is that by processing the image of the filter rod to be detected, the total number of filter rods is counted based on the contours of all filter rods contained in the image extracted using different methods. This solves the problems of low efficiency and missed detection in manual detection of filter rods in the prior art, effectively improves the efficiency of filter rod quantity detection, reduces the risk of false detection by human eyes in the production line, and ensures the accuracy of filter rod quantity detection, thereby enabling efficient and accurate detection of the number of filter rods.
[0038] Furthermore, embodiments of the present invention also provide corresponding implementation devices, electronic devices, and readable storage media for the method of detecting the quantity of circular solid objects, further making the method more practical. The devices, electronic devices, and readable storage media have corresponding advantages.
[0039] It should be understood that the above general description and the following detailed description are merely exemplary and do not limit this application. Attached Figure Description
[0040] To more clearly illustrate the technical solutions of the embodiments of the present invention or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 A flowchart illustrating a method for detecting the quantity of circular solid objects provided in an embodiment of the present invention;
[0042] Figure 2 A flowchart illustrating another method for detecting the quantity of circular solid objects provided in an embodiment of the present invention;
[0043] Figure 3 A schematic diagram of the original image of a filter rod as provided in an embodiment of the present invention;
[0044] Figure 4 Provided for embodiments of the present invention Figure 3 A schematic diagram of the image obtained after global thresholding;
[0045] Figure 5 Provided for embodiments of the present invention Figure 3 A schematic diagram of the corresponding Euclidean distance transform image;
[0046] Figure 6 This is a schematic diagram of the image obtained after watershed processing of an Euclidean distance transform image, as provided in an embodiment of the present invention.
[0047] Figure 7 Provided for embodiments of the present invention Figure 3 Schematic diagram of the corresponding initial filter rod outline;
[0048] Figure 8 Provided for embodiments of the present invention Figure 3 A schematic diagram of the corresponding preprocessed image;
[0049] Figure 9 The embodiments of the present invention provide Figure 3 Corresponding shape template diagram;
[0050] Figure 10 The initial positioning diagram passing through the origin provided in this embodiment of the invention;
[0051] Figure 11 A schematic diagram of filter rod positioning obtained by affine transformation provided in an embodiment of the present invention;
[0052] Figure 12Template matching diagram provided in this embodiment of the invention;
[0053] Figure 13 A schematic diagram of the filter rod quantity detection provided in this embodiment of the invention;
[0054] Figure 14 A structural diagram of a specific embodiment of the circular solid object quantity detection device provided in this invention;
[0055] Figure 15 This is a structural diagram of a specific embodiment of the electronic device provided in this invention. Detailed Implementation
[0056] To enable those skilled in the art to better understand the present invention, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] The terms "comprising" and "having," and any variations thereof, in the specification, claims, and accompanying drawings of this application are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may include steps or units not listed. Various non-limiting embodiments of this application are described in detail below.
[0058] First see Figure 1 , Figure 1 This is a flowchart illustrating a method for detecting the quantity of circular solid objects according to an embodiment of the present invention. This embodiment is applicable to detecting the quantity of easily deformable solid objects. The embodiment of the present invention may include the following:
[0059] S101: Obtain the original image of the filter rod to be detected.
[0060] The original image of the filter rod to be inspected is obtained by using an image acquisition device installed on the production line to capture images of the filter rod that needs to be inspected. The original image of the filter rod to be inspected contains multiple filter rods.
[0061] S102: Extract the initial contours of each filter rod contained in the original image of the filter rod to obtain the initial filter rod contour image.
[0062] In this embodiment, the initial filter rod contour image refers to the image that identifies the contours of all identifiable filter rods in the original filter rod image. Any contour extraction method can be used to process the original filter rod image to be detected to determine the contour of each filter rod in the original image, thereby obtaining the initial filter rod contour image.
[0063] S103: Determine the shape template based on the original image of the filter rod, and locate each filter rod according to the shape template to obtain the filter rod positioning contour image.
[0064] In this embodiment, the shape template is used to represent a template image of the filter rod shape. Considering that the filter rod is a deformable solid, in order to improve the detection accuracy of the filter rod, the filter rod in the shape template can be generated based on the filter rod in the original filter rod image. Optionally, in this embodiment, any image extraction method can be used to extract the diameter of the target filter rod from the original filter rod image, and then the shape template is generated based on the diameter. After determining the shape template, shape matching is performed on the original filter rod image based on the shape template to identify all filter rods contained in the initial filter rod contour image, and the position of each filter rod in the initial filter rod contour image is located. Based on the shape of the filter rod in the shape template, a filter rod positioning contour image that identifies the filter rod contour can be obtained. Furthermore, in order to improve the accuracy of filter rod recognition, before performing shape template matching, the original filter rod image can be processed based on an enhanced contrast algorithm to obtain a preprocessed image; based on the shape template, template matching is performed on the filter rods identified in the preprocessed image to obtain the filter rod positioning contour image. Template matching of the contrast-enhanced image helps improve the accuracy of filter rod recognition, thereby improving the accuracy of filter rod quantity detection.
[0065] S104: Based on the initial filter rod contour image and the filter rod positioning contour image, determine the number of filter rods contained in the original filter rod image.
[0066] In this embodiment, both the initial filter rod outline image and the filter rod positioning outline image are images that identify each filter rod in the same original filter rod image and determine the filter rods in the image. The number of filter rods contained in the original filter rod image is detected by comparing the initial filter rod outline image and the filter rod positioning outline image. Optionally, the number of filter rods contained in the original filter rod image can be determined based on whether there is an intersection between the filter rods at corresponding positions in the initial filter rod outline image and the filter rod positioning outline image.
[0067] In the technical solution provided by the embodiments of the present invention, the total number of filter rods is counted by processing the image of the filter rods to be detected and extracting the outlines of all filter rods contained in the image using different methods. This solves the problems of low efficiency and missed detection in manual detection of filter rods in the prior art, effectively improves the efficiency of filter rod quantity detection, reduces the risk of false detection by human eyes in the production line, and ensures the accuracy of filter rod quantity detection, thereby enabling efficient and accurate detection of the number of filter rods.
[0068] In the above embodiments, there is no limitation on how to perform step S102. This embodiment provides an optional implementation method that is beneficial to further improve the detection accuracy of the number of filter rods, which may include the following steps:
[0069] Considering the large grayscale difference between the filter rod outline and the background, a global threshold segmentation process is performed on the original image of the filter rod to obtain a binarized image;
[0070] For each pixel in the binarized image, the pixel value of the pixel closest to the current pixel is assigned to the current pixel, generating a Euclidean distance transform map;
[0071] Based on the watershed algorithm, the pixels in the Euclidean distance transformation image that meet the preset spatial-pixel similarity condition are connected to form a contour, thus obtaining the contour of each filter rod in the original image of the filter rod.
[0072] Based on the global threshold segmentation algorithm and the information of each filter rod outline in the image determined in the previous step, the initial filter rod outline image is obtained by filtering by area and roundness.
[0073] In this embodiment, the Euclidean distance transform map can be obtained by processing a binary image using the Euclidean distance transform algorithm. Each pixel is assigned the distance value to its nearest background pixel (image boundary), resulting in a distance matrix. Therefore, pixels farther from the boundary are brighter. Distance transform is the process of calculating and identifying the distance between spatial points (to a target point), ultimately transforming the binary image into a Euclidean distance transform map, where the grayscale value of each grid cell is equal to its distance to the nearest target point. On a two-dimensional plane, two points (x1, y1) and (x2, y2) are defined, and the Euclidean distance D between these two points can be expressed as:
[0074]
[0075] In a binary image, 1 represents a target point and 0 represents the background; in a grayscale image, the grayscale value of a grid cell represents the distance from that grid cell to the nearest target point. Thus, an M*N image can be represented as a two-dimensional array A[M][N], where grid cells corresponding to A[i][j] = 1 represent target points, and grid cells corresponding to A[i][j] = 0 represent background points. If B = {(x, y) | A[i][j] = 1} is the set of target points, then the Euclidean distance transformation processes all grid cells in A according to the following relationship, thereby obtaining the Euclidean distance transformation map of the binary image A:
[0076]
[0077] in,
[0078] The preset spatial-pixel proximity condition refers to pixels that simultaneously satisfy both spatial location and pixel value conditions. For example, for pixels in a Euclidean distance transform image, pixels that are spatially adjacent and whose grayscale value difference is less than a preset value are connected to form a closed contour. The preset value is a small number, and the specific value can be flexibly determined according to the actual application scenario. The watershed algorithm is an image region segmentation method. During the segmentation process, it uses the similarity between neighboring pixels as an important reference, thus connecting pixels that are spatially close and have similar grayscale values to form a closed contour. The watershed transform yields a basin image of the input image, and the boundary points between the basins are the watersheds. Obviously, the watershed represents the maxima of the input image. Therefore, to obtain the edge information of the image, the gradient image is usually used as the input image, i.e.
[0079]
[0080] Where f(x, y) represents the original image, grad{.} represents the gradient operation. x and y are the pixel coordinates, grad represents the gradient image of the original image, and g(x, y) is the segmented image.
[0081] In the above embodiments, there is no limitation on how to perform step S103. This embodiment provides an optional implementation method that is beneficial to further improve the detection accuracy of the number of filter rods, which may include the following steps:
[0082] Based on the shape template matching algorithm, the initial positioning of the filter rod through the origin is obtained;
[0083] Based on the affine transformation matrix, the initial positioning of each filter rod through the origin coordinates is translated and scaled to determine the position of each filter rod.
[0084] Generate a filter rod positioning contour image based on the position of each filter rod.
[0085] The process involves using shape templates to create a shape matching model. Based on the shape template matching algorithm, the initial location of the filter rods at the origin is obtained. Then, according to the affine transformation matrix, the initial location of the filter rods at the origin is translated and scaled to obtain the location of the filter rods after the affine transformation. Finally, template matching is performed on all identifiable filter rods in the image. Optionally, the position of each filter rod can be determined by calling the following relation:
[0086]
[0087] Δx represents horizontal translation, and Δy represents vertical translation; Sx and Sy are the first and second scaling factors, respectively. x0 and y0 are the initial coordinates, and x1 and y1 are the coordinates after translation and scaling.
[0088] To enable those skilled in the art to more clearly understand the technical solution of this application, this application combines... Figure 2 An illustrative embodiment is also provided, which uses... Figure 3 The image shown is the original image of the filter rod to be detected, and may include the following:
[0089] A1: Obtain the original image of the filter rod to be detected, such as... Figure 3 As shown;
[0090] A2: Based on the global threshold segmentation algorithm, the following is obtained: Figure 4 The binarized image shown.
[0091] A3: Based on the Euclidean distance transform algorithm, convert the binarized image into... Figure 5 The Euclidean distance transformation diagram is shown.
[0092] A4: Based on the watershed algorithm, pixels with similar gray values in the Euclidean distance transform image are connected to form a contour, resulting in... Figure 6 The outline of each filter rod is shown.
[0093] A5: Based on a global threshold segmentation algorithm, the initial outline of the filter rod is obtained by filtering according to the region area and the region roundness, i.e., the initial filter rod outline image, such as... Figure 7 As shown.
[0094] B1: Obtain as follows Figure 3 The original filter rod image shown;
[0095] B2: Based on a contrast enhancement algorithm, the contrast of the image is enhanced to obtain a preprocessed image, such as... Figure 8 As shown.
[0096] B3: Create a template image, i.e., a shape template, based on the diameter of any complete filter rod in the original image, such as... Figure 9As shown.
[0097] B4: Based on the shape template matching algorithm, the initial positioning of the filter rod through the origin is obtained, such as... Figure 10 Based on the affine transformation matrix, the initial positioning of the tobacco shreds at the origin coordinates is translated and scaled to obtain the positioning of the filter rod after the affine transformation, i.e., the positioning contour image of the filter rod, as shown below. Figure 11 As shown.
[0098] B5: Obtain the preprocessed image, and perform template matching on all identifiable filter rods in the preprocessed image, such as... Figure 12 As shown.
[0099] C: The initial contour obtained after processing by the watershed algorithm (e.g.) Figure 5 The initial filter rod contour image shown) and the contour after matching the template (e.g.) Figure 10 The intersection of the filter rod positioning contour images shown can be used as the number of filter rods, such as... Figure 13 As shown.
[0100] As can be seen from the above, the embodiments of the present invention can efficiently and accurately detect the number of filter rods.
[0101] It should be noted that there is no strict order of execution for the steps in this application. As long as they conform to a logical order, these steps can be executed simultaneously or in a certain preset order. Figures 1-2 This is just an illustrative example and does not mean that this is the only possible execution order.
[0102] This invention also provides a corresponding apparatus for the method of detecting the quantity of circular solid objects, further enhancing the practicality of the method. The apparatus can be described from both a functional module perspective and a hardware perspective. The following description of the apparatus for detecting the quantity of circular solid objects provided by this invention is provided, and the apparatus described below corresponds to the method for detecting the quantity of circular solid objects described above.
[0103] From the perspective of functional modules, see Figure 14 , Figure 14 This is a structural diagram of a circular solid object quantity detection device provided in an embodiment of the present invention, wherein the device may include:
[0104] Image acquisition module 141 is used to acquire the original image of the filter rod to be detected;
[0105] The initial contour extraction module 142 is used to extract the initial contours of each filter rod contained in the original image of the filter rod to obtain an initial filter rod contour image.
[0106] The secondary contour extraction module 143 is used to determine the shape template based on the original image of the filter rod, and to locate each filter rod according to the shape template to obtain the filter rod positioning contour image.
[0107] The quantity detection module 144 is used to determine the number of filter rods contained in the original filter rod image based on the initial filter rod contour image and the filter rod positioning contour image.
[0108] Optionally, in some embodiments of this example, the initial contour extraction module 142 may also be used to: perform global threshold segmentation on the original image of the filter rod to obtain a binarized image; assign the pixel value of the pixel closest to the current pixel to each pixel in the binarized image to generate a Euclidean distance transform image; connect the pixels in the Euclidean distance transform image that meet the preset spatial-pixel proximity condition to form a contour based on the watershed algorithm to obtain the contour of each filter rod in the original image of the filter rod; and obtain the initial filter rod contour image by filtering by area and roundness based on the global threshold segmentation algorithm.
[0109] As an optional implementation of the above embodiments, the initial contour extraction module 142 can be further used to connect pixels that are spatially adjacent and whose grayscale value difference is less than a preset value into a closed contour for each pixel in the Euclidean distance transformation map.
[0110] Optionally, in some other embodiments of this example, the secondary contour extraction module 143 may be further used to: process the original image of the filter rod based on the contrast enhancement algorithm to obtain a preprocessed image; and perform template matching on the filter rod identified in the preprocessed image based on the shape template to obtain a filter rod positioning contour image.
[0111] As an optional implementation of the above embodiments, the secondary contour extraction module 143 can also be used to: extract the diameter of the target filter rod from the original image of the filter rod, and generate a shape template based on the diameter.
[0112] Optionally, in some other embodiments of this example, the above-mentioned secondary contour extraction module 143 may be further used to: obtain the initial positioning of the filter rod through the origin based on the shape template matching algorithm; perform translation and scaling processing on the initial positioning of each filter rod through the origin coordinates based on the affine transformation matrix to determine the position of each filter rod; and generate a filter rod positioning contour image according to the position of each filter rod.
[0113] Optionally, in some other embodiments of this example, the quantity detection module 144 may be further used to: determine the number of filter rods contained in the original filter rod image based on whether there is an intersection between the filter rods at corresponding positions in the initial filter rod contour image and the filter rod positioning contour image.
[0114] The functions of each module of the circular solid object quantity detection device described in this embodiment of the invention can be specifically implemented according to the methods in the above method embodiments. The specific implementation process can be referred to the relevant descriptions in the above method embodiments, which will not be repeated here.
[0115] As can be seen from the above, the embodiments of the present invention can efficiently and accurately detect the number of filter rods.
[0116] The above-mentioned circular solid object quantity detection device is described from the perspective of functional modules. Furthermore, this application also provides an electronic device, which is described from the perspective of hardware. Figure 15 This is a schematic diagram of the structure of the electronic device provided in one embodiment of this application. For example... Figure 15 As shown, the electronic device includes a memory 150 for storing a computer program; and a processor 151 for executing the computer program to implement the steps of the method for detecting the number of circular solid objects as described in any of the above embodiments.
[0117] The processor 151 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 151 may also be a controller, microcontroller, microprocessor, or other data processing chip. The processor 151 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 151 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 151 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 151 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0118] The memory 150 may include one or more computer-readable storage media, which may be non-transitory. The memory 150 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the memory 150 may be an internal storage unit of an electronic device, such as a server hard drive. In other embodiments, the memory 150 may be an external storage device of an electronic device, such as a plug-in hard drive on a server, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. Furthermore, the memory 150 may include both internal and external storage units of the electronic device. The memory 150 can be used not only to store application software and various types of data installed on the electronic device, such as code in the process of executing the method for detecting the number of circular solid objects, but also to temporarily store data that has been output or will be output. In this embodiment, the memory 150 is used to store at least the following computer program 1501, which, after being loaded and executed by the processor 151, is capable of implementing the relevant steps of the method for detecting the number of circular solid objects disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 150 may also include an operating system 1502 and data 1503, and the storage method may be temporary storage or permanent storage. The operating system 1502 may include Windows, Unix, Linux, etc. The data 1503 may include, but is not limited to, data corresponding to the quantity detection results of circular solid objects.
[0119] In some embodiments, the aforementioned electronic device may further include a display screen 152, an input / output interface 153, a communication interface 154 (or network interface), a power supply 155, and a communication bus 156. The display screen 152 and input / output interface 153, such as a keyboard, are user interfaces; optional user interfaces may also include standard wired interfaces, wireless interfaces, etc. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a display screen or display unit, used to display information processed in the electronic device and to display a visual user interface. The communication interface 154 may optionally include a wired interface and / or a wireless interface, such as a Wi-Fi interface, a Bluetooth interface, etc., typically used to establish communication connections between the electronic device and other electronic devices. The communication bus 156 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 15 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0120] Those skilled in the art will understand that Figure 15 The structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, such as sensors 157 that perform various functions.
[0121] The functions of each functional module of the electronic device described in the embodiments of the present invention can be specifically implemented according to the methods in the above method embodiments. The specific implementation process can be referred to the relevant descriptions in the above method embodiments, which will not be repeated here.
[0122] As can be seen from the above, the embodiments of the present invention can efficiently and accurately detect the number of filter rods.
[0123] It is understood that if the method for detecting the number of circular solid objects in the above embodiments is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes: USB flash drive, mobile hard drive, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, removable disk, CD-ROM, magnetic disk or optical disk, and other media capable of storing program code.
[0124] Based on this, embodiments of the present invention also provide a readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the steps of the method for detecting the number of circular solid objects as described in any of the above embodiments are as follows.
[0125] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the hardware disclosed in the embodiments, including devices and electronic equipment, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.
[0126] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0127] The foregoing provides a detailed description of a method, apparatus, electronic device, and readable storage medium for detecting the quantity of circular solid objects provided in this application. Specific examples have been used to illustrate the principles and implementation methods of the invention. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and core ideas of the invention. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from the principles of the invention, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A method for detecting the quantity of circular solid objects, characterized in that, include: Acquire the original image of the filter rod to be inspected; The original image of the filter rod is subjected to global threshold segmentation to obtain a binarized image; For each pixel in the binarized image, the pixel value of the pixel closest to the current pixel is assigned to the current pixel to generate a Euclidean distance transformation map; based on the watershed algorithm, the pixels in the Euclidean distance transformation map that satisfy the preset spatial-pixel proximity condition are connected to form a contour to obtain the contour of each filter stick in the original image of the filter stick. Based on the global threshold segmentation algorithm, the initial filter rod contour image is obtained by filtering by area and roundness; A shape template is determined based on the original image of the filter rod, and the original image of the filter rod is processed based on an enhanced contrast algorithm to obtain a preprocessed image; Based on the shape template, template matching is performed on the filter rods identified in the preprocessed image to obtain a filter rod positioning contour image. Based on whether there is an intersection between the filter rods at corresponding positions in the initial filter rod contour image and the filter rod positioning contour image, the number of filter rods contained in the original filter rod image is determined.
2. The method for detecting the quantity of circular solid objects according to claim 1, characterized in that, The watershed algorithm-based method connects pixels in the Euclidean distance transform image that satisfy a preset spatial-pixel proximity condition to form a contour, including: For each pixel in the Euclidean distance transformation map, pixels that are spatially adjacent and whose grayscale value difference is less than a preset value are connected to form a closed contour.
3. The method for detecting the quantity of circular solid objects according to claim 1, characterized in that, The step of determining the shape template based on the original image of the filter rod includes: The diameter of the target filter rod is extracted from the original image of the filter rod, and a shape template is generated based on the diameter.
4. The method for detecting the quantity of circular solid objects according to any one of claims 1 to 3, characterized in that, The step of performing template matching on the filter rod identified in the preprocessed image based on the shape template to obtain a filter rod positioning contour image includes: Based on the shape template matching algorithm, the initial positioning of the filter rod through the origin is obtained; Based on the affine transformation matrix, the initial positioning of each filter rod through the origin coordinates is translated and scaled to determine the position of each filter rod. Generate a filter rod positioning contour image based on the position of each filter rod.
5. A device for detecting the quantity of circular solid objects, characterized in that, include: The image acquisition module is used to acquire the original image of the filter rod to be detected; An initial contour extraction module is used to perform global threshold segmentation on the original image of the filter stick to obtain a binarized image; for each pixel in the binarized image, the pixel value of the pixel closest to the current pixel is assigned to the current pixel to generate a Euclidean distance transform map; based on the watershed algorithm, the pixels in the Euclidean distance transform map that meet the preset spatial-pixel proximity condition are connected to form a contour to obtain the contour of each filter stick in the original image of the filter stick; Based on the global threshold segmentation algorithm, the initial filter rod contour image is obtained by filtering by area and roundness; The secondary contour extraction module is used to determine the shape template based on the original image of the filter rod, and to process the original image of the filter rod based on the contrast enhancement algorithm to obtain a preprocessed image; Based on the shape template, template matching is performed on the filter rods identified in the preprocessed image to obtain a filter rod positioning contour image. The quantity detection module is used to determine the number of filter rods contained in the original filter rod image based on whether there is an intersection between the filter rods at corresponding positions in the initial filter rod outline image and the filter rod positioning outline image.
6. An electronic device, characterized in that, It includes a processor and a memory, the processor being configured to execute a computer program stored in the memory to implement the steps of the method for detecting the number of circular solid objects as described in any one of claims 1 to 4.
7. A readable storage medium, characterized in that, The readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method for detecting the quantity of circular solid objects as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Overlapped particulate matter layered counting method based on a color image and a depth image
CN109584281A