Method and device for counting newly-hatched silkworms

Image recognition technology is used to obtain an ant silkworm image, binarization and area statistics are performed, and combined with the multi-time image change curve correction, the problem of low counting of ant silkworms is solved, and efficient and accurate statistics of ant silkworm count is achieved.

CN119314206APending Publication Date: 2025-01-14SERICULTURE TECH PROMOTION STATION OF GUANGXI ZHUANG AUTONOMOUS REGION
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411416004.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-11
Publication Date
2025-01-14

AI Technical Summary

Technical Problem

In the prior art, the identification and counting of ant silkworms is extremely small, and the reliance on weighing and counting methods has problems of low accuracy and low efficiency, and is greatly affected by factors such as the growth stage of ant silkworms, nutritional conditions, and water changes. .

Method used

By acquiring the ant silkworm images, performing binarization processing, counting the area and number of connected areas, establishing a histogram to determine the standard area, calculating the total number of ant silkworms, and correcting the change curve of the multi-time image, and using image recognition technology to achieve accurate count.

Benefits of technology

It improves the accuracy and efficiency of the ant silkworm count, overcomes the shortcomings of low accuracy and low efficiency of the weighing counting method, ensures the objectivity and repetition of the counting results, and reduces manpower dependence.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119314206A_ABST
    Figure CN119314206A_ABST
Patent Text Reader

Abstract

The invention discloses a newly-hatched silkworm counting method. The method comprises the steps of S1, acquiring a newly-hatched silkworm image; s2, binarizing the newly-hatched silkworm image to obtain a binarized image; s3, counting connected regions in the binarized image, establishing a histogram by taking the area and the corresponding number of the connected regions as coordinates, and determining a standard area according to the area distribution of the connected regions; and S4, determining the number of newly-hatched silkworms contained in all the connected regions according to the standard area to obtain the total number of newly-hatched silkworms. The invention further provides a newly-hatched silkworm counting device. According to the invention, the number of newly-hatched silkworms can be accurately counted, and the statistical efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field related to silkworm detection and inspection, and more specifically, to a method and device for counting silkworms. Background Art

[0002] In current technical practice, the identification and counting of silkworms face significant challenges, especially because silkworms are extremely small (usually less than 2 mm in length and less than 0.5 mm in width), which makes it very difficult to identify and count them directly with the naked eye. However, most existing technologies rely on a primitive and inaccurate method - weighing and counting. The operator first weighs a certain amount of silkworms, and then estimates the number of silkworms based on a pre-set average weight. The main advantage of this method is that it is simple and fast to operate, and is suitable for scenarios where a large number of samples need to be processed quickly. However, since the weight of silkworms may vary significantly at different growth stages and nutritional conditions, the accuracy of this estimation method is greatly limited. In addition, this estimation may result in large errors due to changes in the moisture content of silkworms caused by the long detection time of silkworms in the sample. Therefore, it is necessary to design a technical solution that can overcome the above-mentioned defects. Summary of the invention

[0003] An object of the present invention is to provide a method and device for counting silkworms, which can accurately count the number of silkworms and improve the statistical efficiency.

[0004] In order to achieve these purposes and other advantages of the present invention, according to one aspect of the present invention, the present invention provides a method for counting worms, including: S1: acquiring a worm image; S2: binarizing the worm image to obtain a binary image; S3: counting the connected areas in the binary image, establishing a histogram with the area and corresponding number of the connected areas as coordinates, and determining a standard area based on the area distribution of the connected areas; S4: determining the number of worms contained in all the connected areas based on the standard area to obtain the total number of worms.

[0005] Furthermore, in the S4, it also includes: S41: selecting the connected area whose area is larger than the standard area to obtain a large-area connected area; S42: extracting the block containing the large-area connected area on the ant silkworm image; S43: changing the background color of the block, binarizing the block, and obtaining a binary block; S44: counting the connected areas in the binary block; S45: determining the number of ants silkworms contained according to the standard area.

[0006] Furthermore, it also includes: acquiring the silkworm image at multiple subsequent moments; extracting the blocks on the silkworm image at multiple moments accordingly, and executing the operations of S43-S44 in sequence, and counting the number of pixels in the connected area; constructing a change curve of the number of pixels at multiple moments; and determining a correction coefficient based on the change curve to correct the number of silkworms obtained in S45.

[0007] Furthermore, the RGB value of the replaced background color is an average value of the RGB values ​​of all pixels of the background of the block.

[0008] Furthermore, in S3, before establishing the histogram, connected regions with outlier areas are removed.

[0009] Furthermore, in S3, the area with the largest number in the histogram is selected, and the average value of the areas of all the connected regions contained therein is taken as the standard area.

[0010] Furthermore, it also includes: the ant silkworm image contains an identification code, and the identification code contains identification information of the ant silkworm; identifying the identification code, obtaining the identification information of the ant silkworm, and binding it with the total number of ant silkworms.

[0011] According to another aspect of the present invention, there is also provided an ant silkworm counting device, comprising: an acquisition module for acquiring an ant silkworm image; a preprocessing module for binarizing the ant silkworm image to obtain a binary image; a determination module for counting the connected areas in the binary image, establishing a histogram with the areas and corresponding numbers of the connected areas as coordinates, and determining a standard area based on the area distribution of the connected areas; and a counting module for determining the number of ant silkworms contained in all the connected areas based on the standard area to obtain the total number of ant silkworms.

[0012] Furthermore, the counting module is also used to select the connected area whose area is larger than the standard area to obtain a large-area connected area, extract the block containing the large-area connected area on the ant silkworm image, change the background color of the block, binarize the block to obtain a binarized block, count the connected area in the binarized block, and determine the number of ants silkworms contained according to the standard area.

[0013] Furthermore, the counting module is also used to obtain the silkworm image at multiple subsequent moments, correspondingly extract the blocks on the silkworm image at multiple moments, and sequentially perform the operations of changing the background color of the block, binarizing the block, and counting the connected area, and count the number of pixel points in the connected area, and construct a change curve of the number of pixel points at multiple moments, and determine the correction coefficient according to the change curve to correct the obtained number of silkworms.

[0014] The present invention has at least the following beneficial effects: The present invention obtains an image of silkworms, binarizes the image of silkworms to obtain a binarized image, counts connected areas in the binarized image, establishes a histogram with the area and corresponding number of the connected areas as coordinates, determines a standard area according to the area distribution of the connected areas, determines the number of silkworms contained in all connected areas according to the standard area, and obtains the total number of silkworms; the present invention counts the number of silkworms through image recognition technology, overcomes the defects of low accuracy and low efficiency of the weighing and counting method, and the defect of relying on manpower, and ensures the objectivity and repeatability of the counting result.

[0015] Other advantages, objectives and features of the present invention will be embodied in part through the following description, and in part will be understood by those skilled in the art through study and practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 For ant silkworm images; Figure 2 A flowchart of an embodiment of the present application; Figure 3 This is a framework diagram of an embodiment of the present application. DETAILED DESCRIPTION

[0017] The present invention is further described in detail below in conjunction with the accompanying drawings so that those skilled in the art can implement the invention with reference to the description.

[0018] It should be understood that the terms such as "having", "including" and "comprising" used in the embodiments of the present application do not exclude the existence or addition of one or more other elements or their combinations. All directional indications (such as up, down, left, right, front, back...) in the embodiments of the present application are only used to explain the relative position relationship, movement, etc. between the components in a certain specific posture. If the specific posture changes, the directional indication will also change accordingly. When an element is referred to as "fixed on" or "set on" another element, it can be directly on the other element or there may be a centering element at the same time. When an element is referred to as "connecting" another element, it can be directly connected to another element or it can be indirectly connected to another element through a centering element. The description of "first", "second", etc. in the embodiments of the present application is only for descriptive purposes, and cannot be understood as indicating or implying its relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" can explicitly or implicitly include at least one of the features.

[0019] It should be noted that the technical solutions between the various embodiments of the present application can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0020] like Figure 2 As shown, the embodiment of the present application provides a method for counting ants and silkworms, comprising: S1: Get the ant silkworm image; In this step, the ant silkworm image is Figure 1 As shown, the background and the ant silkworm should be quite different, such as using a white background, a green background, etc.; S2: binarizing the ant silkworm image to obtain a binarized image; For example, the ant silkworm image is first converted into a grayscale image, the grayscale value of each pixel in the grayscale image is counted, and a segmentation threshold is set. Figure 2 Value conversion, that is, the grayscale value of the pixel point whose grayscale value is greater than the segmentation threshold is set to 255, and the grayscale value of the pixel point whose grayscale value is less than the segmentation threshold is set to 0; S3: Counting the connected regions in the binary image, establishing a histogram with the areas and corresponding numbers of the connected regions as coordinates, and determining a standard area according to the area distribution of the connected regions; Exemplarily, a region consisting of adjacent pixels with the same gray value in the binary image is regarded as a connected region; Exemplarily, the area of ​​the connected region is calculated based on the number of pixels in the connected region and the area represented by a single pixel; In this step, most of the connected areas obtained are connected areas formed by a single ant silkworm, and a small part is connected areas formed by the adhesion of two or more ant silkworms. Using the area and the number of connected areas as the horizontal and vertical coordinates, a histogram is constructed to show the area distribution of the connected areas. The standard area is determined by using the area with the largest distribution, which can better reflect the area of ​​a single ant silkworm. Exemplarily, the area near the highest peak in the histogram is taken to estimate the standard area; S4: Determine the number of ant silkworms contained in all the connected areas according to the standard area to obtain the total number of ant silkworms; In this step, according to the standard area obtained in S3, the total number of ants and silkworms can be obtained by dividing the area of ​​all connected areas by the standard area; It can be seen that this embodiment uses image recognition technology to count the number of silkworms, which is more efficient than the weighing and counting method. After obtaining the silkworm image, the number of silkworms can be obtained immediately with high accuracy. It will not be affected by external factors such as dehydration and unbalanced growth of silkworms. It does not rely on manpower, and only the input of the silkworm image is performed manually, thereby ensuring the objectivity and repeatability of the counting results.

[0021] In another embodiment, in said S4, it further includes: S41: Selecting the connected region whose area is larger than the standard area to obtain a large-area connected region; Exemplarily, a connected area formed by the adhesion of two or more ant silkworms, or a connected area formed by an ant silkworm and its shadow, which is larger in area than a connected area formed by a single ant silkworm, is regarded as a large-area connected area; In this step, large connected areas may form large shadows, or ants and silkworms may overlap, resulting in relatively large counting errors, which require further optimization; S42: extracting blocks containing large connected areas on the ant silkworm image; Exemplarily, a square, circle or other irregular shape is used to surround a large connected area to form a block; S43: changing the background color of the block, binarizing the block, and obtaining a binarized block; In this step, the background color of the block is replaced with a color with greater contrast, and the block is binarized again to reduce the error caused by binarization of the entire ant silkworm image. Replacing the background color can reduce the interference of the ant silkworm shadow on the binarization; S44: counting the connected areas in the binarized blocks; This step takes the area consisting of adjacent pixels with the same grayscale value in the binary image as the connected area, which is more accurate than the connected area obtained in S3; S45: Determine the number of ant silkworms included according to the standard area, that is, divide the area of ​​the large connected area by the standard area to obtain the number of ant silkworms. Figure 1 ), resulting in inaccurate counting, although the previous embodiment can partially solve the problem, there is still room for improvement, so another embodiment further provides: obtaining the ant silkworm images at multiple subsequent moments; correspondingly extracting the blocks on the ant silkworm images at multiple moments, and sequentially performing the operations of S43-S44 to count the number of pixels in the connected area; constructing a change curve of the number of pixels at multiple moments; according to the change curve, determining a correction coefficient, and correcting the number of ant silkworms obtained in S45; This embodiment further optimizes the counting of silkworms in large connected areas, that is, collecting silkworm images at multiple subsequent moments, with intervals of 30 s, 60 s, 90 s, etc. between adjacent moments, that is, capturing the position changes of silkworms, correcting the number of silkworms according to the change amount, and improving the counting accuracy; specifically, for the silkworm images at these subsequent moments, extracting blocks at the same position as the silkworm images currently being processed, changing the background color, binarizing, obtaining binarized blocks, counting the connected areas in the binarized blocks, and recording the number of pixels; for each block, using time as the horizontal coordinate and the number of pixels as the vertical coordinate to construct a change curve; inputting the image generated by the change curve into a pre-established convolutional neural network model, outputting a correction coefficient, and multiplying the correction coefficient by the number of silkworms to correct the number of silkworms to obtain a more accurate count of each block. The convolutional neural network includes an input layer, a convolutional layer, a pooling layer, a fully connected layer and an output layer. The input layer inputs a 128*128 change image, the convolution kernel is 3*3, the maximum pooling is adopted, the fully connected layer adopts 30 nodes, and the output layer is a correction coefficient. The convolutional neural network model uses experimental collection images to establish a training set and a test set. The training set and the test set are obtained by training. The input image is a change curve image, and the output is the ratio of the actual number of ants and silkworms to the calculated number of ants and silkworms. After experiments, after the correction coefficient is obtained by using the convolutional neural network to correct the number of ants and silkworms in this embodiment, the accuracy of the number of ants and silkworms in large connected areas is improved by 30%.

[0022] In another embodiment, the RGB value of the replaced background color is an average value of the RGB values ​​of all pixels of the background of the block, so as to improve the accuracy of the binarization result.

[0023] In another embodiment, in S3, before establishing the histogram, connected regions with outliers in area are eliminated, that is, abnormal connected regions are deleted to reduce interference with the process of determining the standard area.

[0024] In another embodiment, in S3, the area with the largest number in the histogram is selected, and the average value of the areas of all the connected regions contained therein is taken as the standard area; this step can determine the standard area more accurately.

[0025] In another embodiment, the invention further comprises: the silkworm image includes an identification code, the identification code includes identification information of the silkworm; identifying the identification code, obtaining the identification information of the silkworm, and binding it with the total number of silkworms; Exemplarily, the identification code is a QR code, which is recognized after the silkworm image is input, and the batch, growth stage, etc. of the silkworms in the silkworm image are obtained. After the total number of silkworms is obtained, they are bound to each other for fast output of the total number of silkworms in different batches and growth stages, which is convenient for biological research, quality control, etc.

[0026] In another embodiment, Figure 3 As shown in the figure, the picture is automatically uploaded after being shot by a high-definition camera; the uploaded picture is securely sent to the server through a front-end interface built on WebSocket technology; the main functions of the back-end system server include processing image files, creating and managing user tasks, database interaction, user management, and real-time communication and notification broadcasting through WebSocket. In this process, Nginx, as a proxy server, first receives the data packet from WebSocket, which not only ensures the secure transmission of data, but also optimizes the processing speed and resource allocation through the load balancing mechanism; once the picture reaches the Flask backend, a dedicated image processing module Start working, the module structure covers many functions from image preprocessing, connected domain analysis, color operation, block extraction, change curve construction, correction coefficient calculation and other multi-threaded processing; including the application of edge detection, color analysis and morphology recognition technology to accurately identify and count each ant silkworm in the picture; and can recognize the QR code in the picture, read the information into the name of the task, automatically calculate the most suitable threshold through the Otsu algorithm (automatic threshold determination), convert the grayscale image into a black and white binary image, effectively separate the ant silkworm from the background, mark the foreground object through the connected domain analysis, identify and mark all independent ants silkworms in the image, and use area filtering to exclude noise and non-target objects. And through area analysis, overlapping larvae are separated to estimate the number of larvae contained. After processing, the counting results and possible analysis reports are encapsulated in JSON format and safely returned to the front end through Nginx. After receiving these data, the front-end system immediately displays the results to the user dynamically. The user can see the detailed counting results and provide options for saving and re-uploading for analysis. The mask area can also be set to remove the range that does not want to be counted. For users who need long-term tracking and analysis, the system also provides data storage options to store the results and related data of each detection in the back-end database. These data can be used for historical performance evaluation and formulation of system optimization strategies.

[0027] The embodiment of the present application further provides an ant silkworm counting device, comprising: an acquisition module, used to acquire an ant silkworm image; a preprocessing module, used to binarize the ant silkworm image to obtain a binary image; a determination module, used to count the connected areas in the binary image, using the area and the corresponding number of the connected areas as coordinates, to establish a histogram, and determine the standard area according to the area distribution of the connected areas; a counting module, used to determine the number of ant silkworms contained in all the connected areas according to the standard area, and obtain the total number of ant silkworms; This embodiment utilizes a computer program to construct an acquisition module, a preprocessing module, a determination module, and a counting module, and uses image recognition technology to count the number of silkworms. Compared with the weighing and counting method, it is more efficient. After acquiring the silkworm image, the number of silkworms can be obtained immediately with high accuracy. It will not be affected by external factors such as dehydration and unbalanced growth of silkworms. It does not rely on manpower, and only the input of the silkworm image is performed manually, thereby ensuring the objectivity and repeatability of the counting results.

[0028] In another embodiment, the counting module is further used to select the connected area with an area larger than the standard area to obtain a large-area connected area, extract the block containing the large-area connected area on the ant silkworm image, change the background color of the block, binarize the block to obtain a binarized block, count the connected area in the binarized block, and determine the number of ant silkworms contained according to the standard area; In this embodiment, since a large connected area may form a large shadow or there may be overlap of ants and silkworms, the counting error is relatively large and needs to be further optimized; a square, circle or other irregular shapes are used to surround the large connected area to form a block; the background color of the block is replaced with a color with greater contrast, and the block is binarized again to reduce the error caused by the binarization of the entire ant and silkworm image. Replacing the background color can reduce the interference of the ant and silkworm shadow on the binarization; the area composed of adjacent pixels with the same grayscale value in the binary image is used as a connected area, which is more accurate than the connected area obtained by a single binarization; the area of ​​the large connected area is divided by the standard area to accurately obtain the number of ants and silkworms.

[0029] In another embodiment, the counting module is further used to obtain the silkworm images at multiple subsequent moments, correspondingly extract the blocks on the silkworm images at multiple moments, and sequentially perform operations of changing the background color of the blocks, binarizing the blocks, and counting the connected areas, counting the number of pixels in the connected areas, constructing a change curve of the number of pixels at multiple moments, determining a correction coefficient based on the change curve, and correcting the obtained number of silkworms; This embodiment further optimizes the counting of silkworms in large connected areas, that is, collecting silkworm images at multiple subsequent moments; for the silkworm images at these subsequent moments, extracting blocks at the same position as the silkworm image currently being processed, changing the background color, binarizing, obtaining binarized blocks, counting the connected areas in the binarized blocks, and recording the number of pixels; for each block, using time as the horizontal coordinate and the number of pixels as the vertical coordinate to construct a change curve; inputting the image generated by the change curve into a pre-established convolutional neural network model, outputting a correction coefficient, and using the correction coefficient to correct the number of silkworms; the convolutional neural network model uses experimentally collected images to establish a training set and a test set, and the training set and the test set have the input image as the change curve image, and the output as the ratio of the actual number of silkworms to the calculated number of silkworms.

[0030] Although the embodiments of the present invention have been disclosed as above, they are not limited to the applications listed in the specification and the implementation modes, and they can be fully applied to various fields suitable for the present invention. For those familiar with the art, additional modifications can be easily implemented. Therefore, without departing from the general concept defined by the claims and the scope of equivalents, the present invention is not limited to the specific details and the illustrations shown and described herein.

Claims

1. A method for counting ants and silkworms, characterized in that: include: S1: Get the ant silkworm image; S2: binarizing the ant silkworm image to obtain a binarized image; S3: Counting the connected regions in the binary image, establishing a histogram with the areas and corresponding numbers of the connected regions as coordinates, and determining a standard area according to the area distribution of the connected regions; S4: Determine the number of ants and silkworms contained in all the connected areas according to the standard area to obtain the total number of ants and silkworms.

2. The method for counting ant silkworms according to claim 1, characterized in that: In said S4, it also includes: S41: Selecting the connected region whose area is larger than the standard area to obtain a large-area connected region; S42: extracting blocks containing large connected areas on the ant silkworm image; S43: changing the background color of the block, binarizing the block, and obtaining a binarized block; S44: counting the connected areas in the binarized blocks; S45: Determine the number of ants and silkworms included according to the standard area.

3. The method for counting ant silkworms as claimed in claim 2, characterized in that: Also includes: Acquire the ant silkworm images at a plurality of subsequent moments; Correspondingly extracting the blocks on the ant silkworm image at multiple moments, and sequentially performing the operations of S43-S44 to count the number of pixels in the connected area; Constructing a change curve of the number of pixels at multiple moments; According to the change curve, a correction coefficient is determined to correct the number of ant larvae obtained in S45.

4. The method for counting ant silkworms as claimed in claim 2, characterized in that: The RGB value of the replaced background color is the average RGB value of all pixels of the background of the block.

5. The method for counting ant silkworms according to claim 1, characterized in that: In S3, before establishing the histogram, connected regions with outlier areas are removed.

6. The method for counting ant silkworms according to claim 1, characterized in that: In S3, the area with the largest number in the histogram is selected, and the average value of the areas of all the connected regions contained therein is taken as the standard area.

7. The method for counting ant silkworms according to claim 1, characterized in that: Also includes: The ant silkworm image includes an identification code, and the identification code includes identification information of the ant silkworm; Identify the identification code, obtain the identification information of the silkworm, and bind it with the total number of silkworms.

8. A device for counting ants and silkworms, characterized in that: include: An acquisition module, used for acquiring ant silkworm images; A preprocessing module, used for binarizing the ant silkworm image to obtain a binarized image; A determination module, used for counting the connected areas in the binary image, establishing a histogram with the areas and corresponding numbers of the connected areas as coordinates, and determining the standard area according to the area distribution of the connected areas; The counting module is used to determine the number of ant silkworms contained in all the connected areas according to the standard area to obtain the total number of ant silkworms.

9. The ant silkworm counting device according to claim 8, characterized in that: The counting module is also used to select the connected area whose area is larger than the standard area to obtain a large-area connected area, extract the block containing the large-area connected area on the ant silkworm image, change the background color of the block, binarize the block to obtain a binarized block, count the connected area in the binarized block, and determine the number of ants silkworms contained according to the standard area.

10. The ant silkworm counting device according to claim 9, characterized in that: The counting module is also used to obtain the silkworm images at multiple subsequent moments, correspondingly extract the blocks on the silkworm images at multiple moments, and sequentially perform the operations of changing the background color of the blocks, binarizing the blocks, and counting the connected areas, counting the number of pixels in the connected areas, constructing a change curve of the number of pixels at multiple moments, determining a correction coefficient based on the change curve, and correcting the obtained number of silkworms.

Citation Information

Cited By

  • Silkworm health state monitoring method based on computer vision

    CN119887785A