Hair detection method and device for byproduct product, electronic equipment and storage medium

By adaptively selecting image acquisition strategies and morphological feature analysis, the accuracy problem of hair detection in edible by-products of meat processing was solved, achieving efficient and accurate hair recognition.

CN122243905APending Publication Date: 2026-06-19CHINA MEAT RES CENT

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHINA MEAT RES CENT
Filing Date
2026-03-13
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

In the meat processing process, existing technologies have low accuracy in detecting hair from edible by-products, which can easily lead to false positives and false negatives, especially under mass production conditions.

Method used

An adaptive image acquisition strategy is adopted, combined with transmitted light and diffuse reflection light illumination technology. By dividing the image into a preset grid and performing morphological feature analysis, specific recognition features of hair are constructed to reduce the false detection rate.

Benefits of technology

It improves the accuracy of hair detection, reduces missed and false detections, ensures high-contrast, low-noise detection images, and enhances the reliability of detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122243905A_ABST
    Figure CN122243905A_ABST
Patent Text Reader

Abstract

This invention provides a method, apparatus, electronic device, and storage medium for hair detection in by-product products, relating to the field of foreign object detection technology. The method includes: determining a detection image of the sample to be detected based on a selected image acquisition strategy; dividing the detection image into multiple sub-images according to a preset grid specification in the image detection area; and obtaining the hair detection result of the sample to be detected based on the morphological features of connected objects in the sub-images. This invention achieves refined scanning by dividing the detection image into multiple sub-images using a preset grid, preventing hair from being submerged in complex backgrounds, thereby effectively reducing the probability of missed detections due to insufficient detection density. Furthermore, this invention obtains the hair detection result of the sample to be detected based on the morphological features of connected objects, effectively distinguishing hair from various interfering substances, further reducing the false detection rate, and thus further improving the accuracy of hair detection results for edible by-product products.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of foreign object identification technology, and in particular to a method, apparatus, electronic device, and storage medium for detecting hair in by-products. Background Technology

[0002] Meat processing primarily uses livestock and poultry meat as raw material, while blood, hair, internal organs, gastrointestinal contents, skin, and bones are considered by-products. Edible by-products, which can be further processed into food, are called edible by-products. These mainly include fresh and cooked products from livestock such as pigs, cattle, sheep, and rabbits, and poultry such as chickens, ducks, geese, and pigeons, including their heads, tongues, ears, tails, wings, hooves, liver, kidneys, intestines, heart, lungs, stomach, skin, and blood. Edible livestock and poultry by-products are widely used in local snacks, forming many unique regional delicacies. In today's fast-paced lifestyle, food processing plants across the country, catering to consumer preferences for these products, process by-products into various types of ready-to-eat, semi-finished, and main ingredients for dishes, based on processing methods and usage. This not only increases the added value of processed livestock and poultry by-products and improves the economic benefits of processing enterprises, but also reduces environmental pressure and provides impetus for sustainable agricultural development through comprehensive utilization and resource conservation.

[0003] However, in actual production, enterprises typically process edible by-products on a small to medium scale. At the raw material cleaning stage, semi-automatic cleaning and manual visual inspection are mainly used to check for hair or hair-like substances. After the raw materials are cleaned, finer hairs or hair-like substances may be mixed in or hidden in product folds, multi-layer structures, or packaging joints. Under mass production conditions, false detections and missed detections often occur. Summary of the Invention

[0004] This invention provides a method, apparatus, electronic device, and storage medium for detecting hair in by-products, in order to solve the problem that false detections and missed detections often occur in the prior art under mass production conditions, resulting in low accuracy of hair detection in by-products.

[0005] This invention provides a method for detecting hair in by-products, comprising: Based on the selected image acquisition strategy, the detection image of the sample to be detected is determined; The detected image is divided into multiple sub-images according to the preset grid specifications in the image detection area; Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be tested are obtained.

[0006] The hair detection method for by-product products provided by the present invention includes, before determining the detection image of the sample to be detected based on a selected image acquisition strategy: When the transmittance of the sample to be tested is greater than or equal to a preset transmittance threshold, a first image acquisition strategy is selected; wherein, the first image acquisition strategy is to use a first image acquisition device and a third image acquisition device to acquire images, the first image acquisition device is a back-illuminated array diffuse reflection light source and a top view image acquisition device, and the third image acquisition device is an upward-illuminated bowl-shaped diffuse reflection light source and a bottom view image acquisition device. If the transmittance of the sample to be tested is less than a preset transmittance threshold, a second image acquisition strategy is selected. The second image acquisition strategy is to use a second image acquisition device and a third image acquisition device to acquire images. The second image acquisition device is a downward-illuminating bowl-shaped diffuse reflection light source and a top-view image acquisition device.

[0007] The hair detection method for by-product products provided by the present invention further includes, before determining the detection image of the sample to be detected based on the selected image acquisition strategy: Acquire the grayscale image of the sample to be detected within the preset image area; The target object grayscale image of the sample to be tested is determined based on the grayscale image of the sample to be tested. The number of first pixels in the grayscale image of the target object that are greater than or equal to a preset transparency threshold is counted, and the number of second pixels in the binary template of the grayscale image of the sample to be detected is determined. When the ratio of the first number of pixels to the second number of pixels is greater than a preset ratio threshold, a first image acquisition strategy is adopted; when the ratio of the first number of pixels to the second number of pixels is less than or equal to the preset ratio threshold, a second image acquisition strategy is adopted.

[0008] According to the hair detection method for by-product products provided by the present invention, the step of determining the detection image of the sample to be detected based on the selected image acquisition strategy includes: Based on the selected image acquisition strategy, the corresponding light source grayscale image and the sample grayscale image are acquired within the preset image detection area; Pixels in the grayscale image of the sample to be tested that are smaller than the maximum pixel value in the corresponding light source grayscale image are identified as pixels to be filled. The binary template of the grayscale image of the sample to be tested is obtained by filling the pixels to be filled. If the distance between the center coordinates of the preset image detection area and the centroid coordinates of the binary template is less than or equal to a preset distance, the grayscale image of the current sample to be tested is used as the detection image of the sample to be tested.

[0009] According to the hair detection method for by-product products provided by the present invention, the step of dividing the detection image into multiple sub-images based on a preset grid specification in the image detection area includes: According to the preset grid specifications in the preset image detection area, the preset image detection area is divided into multiple sub-regions; The sub-regions containing non-zero pixels are corresponding to the detection image regions and are used as sub-images of the detection image.

[0010] According to the hair detection method for by-product products provided by the present invention, the step of obtaining the hair detection result of the sample to be detected based on the morphological features of connected objects in the subgraph includes: Construct a binary template of the target object in the subgraph, and construct a label matrix of the binary template of the target object; If the ratio of the number of pixels of the connected objects in the label matrix to the number of pixels of the current subgraph is less than a preset ratio threshold, then the connected objects are subjected to morphological processing to obtain a binary template of the morphological representation of the connected objects. Based on the morphological features of the binary template for morphological characterization, the hair detection results of the test sample are obtained; wherein, the morphological features include the number of endpoints and the number of branch points.

[0011] The hair detection method for by-product products provided by the present invention is characterized in that obtaining the hair detection result of the test sample based on the morphological features of the morphological characterization binary template includes: The number of branch points is determined based on the number of endpoints. If the number of branch points is within the range of the number of branch points, it is determined that the sample to be tested contains hair. If the number of branch points of the connected object is not within the range of the number of branch points, it is determined that the sample to be tested does not contain hair.

[0012] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a hair detection method for any of the by-product products described above.

[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a hair detection method for by-product products as described in any of the above.

[0014] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements a hair detection method for any of the by-product products described above.

[0015] This invention adaptively selects different image acquisition strategies, employing either transmitted or diffused light illumination based on the sample's transmittance characteristics. This ensures high-contrast, low-noise detection images for all types of samples, reducing missed detections and non-detectable objects due to poor image quality. Furthermore, by using a preset grid to divide the detection image into multiple sub-images, this invention achieves refined scanning by partitioning, preventing hair from being obscured in complex backgrounds and effectively reducing the probability of missed detections due to insufficient detection density. Moreover, based on the morphological features of connected objects, this invention obtains hair detection results for the sample under test, effectively distinguishing hair from various interfering substances, further reducing the false detection rate, and thus further improving the hair detection results for edible by-products.

[0016] Furthermore, this invention pre-filters out excessively large background areas and excessively small noise points by using area ratio thresholds, retaining candidate connected objects that conform to hair scale characteristics; then, it extracts skeletonized morphological representation binary templates through morphological processing, reducing the two-dimensional region to a single-pixel-wide topological skeleton, and constructs hair-specific recognition features using geometric parameters such as the number of endpoints and the number of branch points, effectively distinguishing hair from interference objects such as bubbles, particles, and fiber clusters, and significantly reducing the false detection rate. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0018] Figure 1 This is a schematic flowchart of the hair detection method for by-product products provided by the present invention.

[0019] Figure 2 This is a schematic diagram of the process for acquiring detection images provided by the present invention.

[0020] Figure 3 This is one of the structural schematic diagrams of the hair detection device for by-product products provided by the present invention.

[0021] Figure 4 This is the second schematic diagram of the hair detection device for by-products provided by the present invention.

[0022] Figure 5 This is the third schematic diagram of the hair detection device for by-products provided by the present invention.

[0023] Figure 6 This is the fourth schematic diagram of the hair detection device for by-products provided by the present invention.

[0024] Figure 7 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation

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

[0026] This invention is applicable to the detection of hair and hair-like substances in edible by-product semi-finished products and processed products, including edible by-products from livestock and poultry. Furthermore, it is not limited to processing methods, packaging materials, packaging forms, or livestock and poultry breeds; specifically, it can be edible by-products as defined by national standards, industry standards, local standards, or enterprise standards. This invention does not impose specific limitations in these areas.

[0027] Figure 1 This is a flowchart illustrating the hair detection method for by-product products provided by this invention, as shown below. Figure 1 As shown, the method includes the following: S1. Based on the selected image acquisition strategy, determine the detection image of the sample to be detected; In this embodiment of the invention, different image acquisition strategies can be adaptively selected based on the light transmittance characteristics of the sample to be tested, so as to adapt to the characteristics of different samples to be tested.

[0028] S2. Divide the detected image into multiple sub-images according to the preset grid specifications in the image detection area; In this embodiment of the invention, the detection image can be divided into N sub-images according to a preset grid specification. Each sub-image corresponds to a local area of ​​the sample to be detected, so as to reduce the processing complexity of a single image and improve the detection resolution of tiny hair targets.

[0029] S3. Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be detected are obtained.

[0030] In this embodiment of the invention, morphological features may include the number of endpoints and the number of branch points, wherein the number of endpoints and the number of branch points can be determined by constructing a morphological representation binary template of the subgraph.

[0031] The embodiments of the present invention adaptively select different image acquisition strategies, and can use transmitted light or diffuse reflection light for illumination according to the sample transmission characteristics, so as to ensure that all kinds of samples obtain high-contrast and low-noise detection images, which helps to reduce the occurrence of missed detections and physical objects due to poor image quality. Furthermore, this embodiment of the invention divides the detection image into multiple sub-images using a preset grid, achieving refined scanning by partitioning, preventing hair from being submerged in complex backgrounds, thereby effectively reducing the probability of missed detection due to insufficient detection density; and this embodiment of the invention obtains the hair detection results of the sample to be detected based on the morphological features of connected objects, which can effectively distinguish hair from various interferences, further reducing the false detection rate, and thus further improving the hair detection results of edible by-product products.

[0032] In one embodiment, before determining the detection image of the sample to be detected based on the selected image acquisition strategy in S1, the following steps are included: S101. When the transmittance of the sample to be tested is greater than or equal to a preset transmittance threshold, a first image acquisition strategy is selected; wherein, the first image acquisition strategy is to use a first image acquisition device and a third image acquisition device to acquire images, the first image acquisition device is a back-illuminated array diffuse reflection light source and a top view image acquisition device, and the third image acquisition device is an upward-illuminated bowl-shaped diffuse reflection light source and a bottom view image acquisition device. S102. When the transmittance of the sample to be tested is less than the preset transmittance threshold, a second image acquisition strategy is selected; wherein, the second image acquisition strategy is to use a second image acquisition device and a third image acquisition device to acquire images, and the second image acquisition device is a downward-illuminating bowl-shaped diffuse reflection light source and a top-view image acquisition device.

[0033] In this embodiment of the invention, three sets of light sources and image acquisition devices of different forms and positions can be used, namely a first image acquisition device, a second image acquisition device and a third image acquisition device. The three different sets of image acquisition devices are combined in pairs to form two different image acquisition strategies. The first image acquisition device and the third image acquisition device constitute the first image acquisition strategy; the second image acquisition device and the third image acquisition device constitute the third image acquisition strategy.

[0034] Understandably, for routine production, the image acquisition strategy can be adjusted by modifying the hardware settings of the light source camera to adapt to the image acquisition needs of different production scenarios.

[0035] In this embodiment of the invention, back-illuminated transmitted light is used for high-transmittance samples to utilize the attenuation characteristics of light as it penetrates the sample, so that the internal hair foreign objects form a clear shadow outline; for low-transmittance samples, downward-illuminated diffuse reflected light is used to utilize the surface scattering characteristics to highlight the external morphological features of the hair. Both strategies ensure high-contrast imaging between the hair and the background, thereby effectively improving the accuracy of hair detection.

[0036] In one embodiment, before step S1, which determines the detection image of the sample to be detected based on the selected image acquisition strategy, the method further includes: S111. Obtain the grayscale image of the sample to be detected within the preset image area; In this embodiment of the invention, if no image acquisition strategy is configured or the transmittance of the sample to be tested is not detected, the target transmittance of the sample to be tested can be calculated to determine the appropriate image acquisition strategy. Here, transmittance is an indicator of the degree of light transmission.

[0037] In this embodiment of the invention, the status array StatusOfLightAndCamera = [True True True True True True False False] is first set, where StatusOfLightAndCamera(1:3) represents the status bits of the image acquisition device, and StatusOfLightAndCamera(4:6) represents the status bits of the light source. This setting indicates that all light sources and image acquisition devices are turned on. The status bits of the light source and the status bits of the image acquisition device have a one-to-one correspondence. While setting the image acquisition status value, the status value of the light source is the same as its value, i.e., StatusOfLightAndCamera(4:6) = StatusOfLightAndCamera(1:3). Typically, for samples to be tested with a certain degree of light transmittance, StatusOfLightAndCamera(1,3,4,6) is set to True, and the rest are set to False, as the first image acquisition strategy; for samples to be tested that do not meet the light transmittance requirements, StatusOfLightAndCamera(2,3,5,6) is set to True, and the rest are set to False, as the second image acquisition strategy. When reading the program loading parameters, the image acquisition strategy can be determined by reading the last three state values ​​in the light source and camera state arrays.

[0038] In this embodiment of the invention, a first image acquisition device can be used to acquire a grayscale image of the sample video stream to be detected within a preset image detection area.

[0039] S112. Determine the target object grayscale image of the sample to be detected based on the grayscale image of the sample to be detected. In this embodiment of the invention, the grayscale image of the target object of the sample to be detected can be determined based on the grayscale image of the sample to be detected.

[0040] In this embodiment of the invention, the detection image of the sample to be detected is multiplied by the binary template mk(1) of the grayscale image of the sample to be detected to obtain the target grayscale image of the sample to be detected. The non-zero pixels in the grayscale image are traversed, and the number of pixels with pixel values ​​greater than or equal to the preset transparency threshold is counted. The ratio of the number of pixels to the number of pixels in the binary template mk(1) of the grayscale image of the sample to be detected is used as an indicator to judge the light transmittance of the sample to be detected.

[0041] S113. Count the number of first pixels in the grayscale image of the target object that are greater than or equal to a preset transparency threshold, and determine the number of second pixels in the binary template of the grayscale image of the sample to be detected. In this embodiment of the invention, by traversing the non-zero pixels in the grayscale image of the target object, the number of first pixels whose pixel values ​​are greater than or equal to a preset transparency threshold is counted, and the number of second pixels in the binary template of the grayscale image of the sample to be detected is determined.

[0042] S114. When the ratio of the number of the first pixel to the number of the second pixel is greater than a preset ratio threshold, a first image acquisition strategy is adopted; when the ratio of the number of the first pixel to the number of the second pixel is less than or equal to the preset ratio threshold, a second image acquisition strategy is adopted.

[0043] In this embodiment of the invention, the ratio of the number of the first pixel to the number of the second pixel is used as an indicator to determine the light transmittance of the sample to be tested. When the indicator is greater than a preset ratio threshold, the sample to be tested is determined to be transparent, and a first image acquisition strategy is adopted, that is, using a first image acquisition device and a third image acquisition device, setting StatusOfLightAndCamera(1, 3, 4, 6) = [True True True True], StatusOfLightAndCamera(2, 5) = [False False]. When the indicator is less than or equal to the preset ratio threshold, a second image acquisition strategy is adopted, that is, setting StatusOfLightAndCamera(2,3,5,6) = [True True TrueTrue], StatusOfLightAndCamera(1, 3) = [False False]. Through the above method, the image acquisition strategy for the current sample to be tested is selected.

[0044] This invention converts the light transmittance into a quantifiable numerical indicator by statistically analyzing the ratio of the number of pixels in the grayscale image of the target object that are greater than or equal to a preset transparency threshold to the total number of pixels in the binary template. This objective data replaces human experience judgment, ensuring the accuracy and consistency of strategy selection.

[0045] In one embodiment, step S1, determining the detection image of the sample to be detected based on the selected image acquisition strategy, includes: S11. Based on the selected image acquisition strategy, acquire the corresponding light source grayscale image and the grayscale image of the sample to be tested within the preset image detection area; In this embodiment of the invention, after the sample to be tested enters the preset image detection area, the corresponding light source grayscale image and the sample grayscale image of the area are acquired based on the selected image acquisition strategy. The sample grayscale image is the grayscale image obtained after the sample enters the preset image detection area. In this embodiment, the corresponding light source grayscale image is a reference background image acquired when only the light source is turned on and no sample is placed, matching the current acquisition strategy.

[0046] In this embodiment of the invention, the size of the preset image detection area can be adjusted according to the geometric parameters of samples of different sizes. For example, the diagonal length of the sample to be detected can be used as the minimum value of the shortest side of the image detection area, the aspect ratio of the image detection area is 4:3, and the coordinate form of this area is [X...]. min Y min Width Height], its geometric center coordinates O are [(Xmin + Width - 1) / 2, (Y min +Height -1) / 2).

[0047] S12. Pixels in the grayscale image of the sample to be tested that are smaller than the maximum pixel value in the corresponding light source grayscale image are identified as pixels to be filled. S13. Obtain the binary template of the grayscale image of the sample to be tested by filling the pixels to be filled; In this embodiment of the invention, the maximum pixel value of grayscale images from different light sources within a preset image detection area is first determined. When the sample to be detected enters the image detection area of ​​the image acquisition device, element-wise subtraction is performed between the grayscale image of the sample to be detected, sampGrayIm(h), and ref(h), where h∈[1,3]. A binary template is constructed from pixels with a difference less than 0. After pixel filling, this template is used as the binary template mk(h) of the grayscale image of the sample to be detected. Pixel filling can be achieved by traversing the pixels of the obtained binary template, finding pixels with a value of False, and assigning that pixel value to True, thus completing the pixel filling of holes in the template.

[0048] In this embodiment of the invention, determining the maximum pixel value of grayscale images from different light sources within a preset image detection area includes: Based on the illumination intensity of light sources at different locations, grayscale images of the corresponding light sources within a preset image detection area are acquired. The pixel values ​​of each image are iterated, and the maximum pixel value in each light source's grayscale image is used to construct a background vector ref(1:3). The background panels of the second and third image acquisition devices are made of white polytetrafluoroethylene (PTFE) panels with a rough surface and diffuse reflection properties. The light source is a bowl-shaped diffuse reflection LED light source. Simultaneously, polarizing lenses are installed in the first, second, and third image acquisition devices to reduce the influence of highlights and reflections from the packaging material on the sample to be tested.

[0049] In this embodiment of the invention, the maximum and minimum values ​​of the horizontal and vertical coordinates of the image detection area can be used to determine whether the sample to be detected has completely entered the detection area. Specifically: let mk1 = mk(1), satisfying X min <mk1(i,1)<X min + Width and Y min <mk1(i,2)<Y min + Height pixels indicate whether they are inside the image detection area or outside the image area, where i∈[1,N] and N represents the number of non-zero pixels. When all pixels of the binary template mk(1) of the grayscale image of the sample to be detected meet the conditions, the sample to be detected completely enters the image detection area; otherwise, wait for the next image frame of the sample to be detected to determine whether the sample to be detected has completely entered the image detection area.

[0050] S14. If the distance between the center coordinates of the preset image detection area and the centroid coordinates of the binary template is less than or equal to a preset distance, the grayscale image of the current sample to be tested is used as the detection image of the sample to be tested.

[0051] In this embodiment of the invention, after the sample to be detected has completely entered the image detection area, the horizontal and vertical coordinates of the non-zero pixels of the binary template mk(1) of the grayscale image of the sample to be detected are accumulated and divided by the number of non-zero pixels, so that mk1 = mk(1), and x = y = Where i∈[1,N], N represents the number of non-zero pixels, and the centroid coordinates C of the binary template are obtained after rounding. Based on the geometric center coordinates O of the image detection area and the centroid coordinates C of mk(1), the modulus of |OC| is calculated to obtain the distance d between the two points. Wherein, the coordinates of the set center O represent the coordinate range [X...] of the image detection area. min Y min Width Height],[(X min + Width -1) / 2, (Y min +Height-1) / 2).

[0052] Furthermore, when d is less than or equal to the preset distance threshold or is within the preset distance range, the current grayscale image of the sample to be tested is used as the detection image of the sample to be detected, and the subsequent hair detection steps in the sample to be detected are executed; otherwise, the next frame of the grayscale image of the sample to be detected is waited for, and it is determined whether the distance between the centroid coordinates of the sample to be detected and the geometric center of the image detection area meets the requirements of the preset distance threshold or the preset distance range.

[0053] This invention constructs a binary template that reflects the true distribution of the sample by comparing the grayscale image of the sample to be tested with the corresponding grayscale image of the light source at the pixel level, using the maximum pixel value of the light source image as a threshold to determine the pixels to be filled. Then, by using the distance constraint between the center coordinates of the preset image detection area and the centroid coordinates of the binary template, the centeredness and proper placement of the sample in the detection field of view are verified, effectively eliminating the problem of misalignment of the detection area caused by sample offset, tilt, or improper placement. This ensures that subsequent hair detection targets the effective area of ​​the sample rather than the background or edge noise, thereby effectively improving the accuracy of hair detection.

[0054] In one embodiment, step S2, dividing the detected image into multiple sub-images based on a preset grid specification in the image detection area, includes: S21. Divide the preset image detection area into multiple sub-regions according to the preset grid specifications in the preset image detection area; In this embodiment of the invention, the preset grid size in the preset image detection area can be set and adjusted according to the size of the sample to be detected in the preset image detection area and the resolution of the image acquisition device. For example, with a resolution of 1920×1080 and a preset image detection area of ​​800×800, if the pixel ratio of a sample to be detected after it completely enters the preset image detection area is approximately 60%, the grid size can be set to 200×200, forming 16 sub-images; the grid size can also be set to 100×100, forming 64 sub-images. When the image features of the sample sub-images are more complex and there are more feature matches, the finer the sub-images of the sample to be detected are divided, the smaller the memory occupied by the operation and the faster the operation speed. Typically, the grid size can be set according to the size of the actual production sample and used as an adjustable parameter.

[0055] S22. The sub-regions with non-zero pixels corresponding to the detection image area are used as sub-images of the detection image.

[0056] In this embodiment of the invention, [X] can be set according to the coordinate region of the image detection area. min Y min [WidthHeight], set the grid as a rectangle with a side length of fxEdge(1,2), and the coordinates of each grid cell are in the form of [X...]. min +(n-1) ×fxEdge(1), Ymin + (m-1) × fxEdge(2) , fxEdge(1), fxEdge(2)], where n∈[1, ],m∈[1, To avoid the phenomenon of remainders between n and m, the width and height of the preset image detection area can be expressed as integer multiples of fxEdge(1) and fxEdge(2). For example, if the coordinate region of the image detection area is [141 138 1000 750], the optimal detection image is segmented into square regions with a side length of 50 pixels. The form of each grid is [138 + (n-1)×50, 141 + (m-1)×50, 50, 50], where n∈[1,20] and m∈[1,15]. This image can be divided into 300 50×50 grids. As another example, if the coordinate region of the preset image detection area is [241 213 800 600], the binary template detection area is segmented into square regions with a side length of 100 pixels. The form of each grid matrix is ​​[241 + (n-1)×100, 213 + (m-1)×100, 100, 100], where n∈[1,8] and m∈[1,6]. This image can be divided into 48 100×100 grids.

[0057] Furthermore, in this embodiment of the invention, the m×n binary template grid matrix is ​​traversed, and the number of non-zero pixels in each grid is accumulated. If the accumulated sum is 0, the grid is discarded; if it is greater than 0, the corresponding m and n values ​​are recorded. After the traversal is completed, the coordinate form of the corresponding grayscale sub-image in the detection area of ​​the detection image of the sample to be detected is obtained according to the obtained m and n values. The coordinates are arranged in parallel to obtain the coordinate matrix of the sub-image subGrayImArray(1:V) of the sample to be detected, where V is the number of grids containing non-zero pixels, i.e., the number of sub-images.

[0058] This invention divides the detection area into predefined grid regions and extracts only sub-regions with non-zero pixels as valid sub-images, automatically removing blank areas without sample coverage. This avoids redundant calculations on invalid backgrounds, significantly reducing the amount of data and algorithm overhead in image processing, thereby effectively improving the response time of hair detection. Furthermore, this invention uses non-zero pixels as the sub-image selection criterion, ensuring that all regions containing sample information are included in the subsequent detection process, preventing sample edge truncation or local omissions caused by grid division. Simultaneously, grid-based partitioning enables fine-grained hair localization, providing structured local image units for subsequent connected object analysis and morphological feature extraction.

[0059] In one embodiment, step S3, obtaining the hair detection result of the sample to be detected based on the morphological features of the connected objects in the subgraph, includes: S31. Construct a binary template of the target object in the subgraph, and construct a label matrix of the binary template of the target object; It should be noted that, based on the current level of production and processing of edible by-products, the phenomenon of large amounts of hair or similar substances being mixed into marketed products during the pretreatment process of by-products has largely disappeared. However, due to workers' failure to properly implement SOPs or the lack of negative pressure circulation in the processing workshop, foreign objects such as dust, hair fragments, and small cut edges of cardboard boxes can fall into the product with the airflow and become mixed in with the product contents after packaging. Therefore, for the construction of morphological structures, based on the scale range of common foreign objects, a multi-morphological and multi-scale approach can be used to sequentially perform morphological opening or reconstruction operations on the binary templates of hair or hair-like foreign objects to confirm their morphological structure.

[0060] In this embodiment of the invention, when the foreign object is located in a darker color area, the contrast between the two can be enhanced by stretching the grayscale range, so as to highlight the gradient of grayscale change between the hair or similar object and the sample to be detected.

[0061] In this embodiment of the invention, the grayscale sub-images subGrayImArray(i) (where i∈N, N represents the number of sub-images) in the column-oriented sample sub-image subGrayImArray are sequentially subjected to image inversion operation, and the target object binary template is obtained according to the dynamic threshold of the inverted image of the current sample to be detected, and the corresponding label matrix is ​​constructed.

[0062] In this embodiment of the invention, the presence of a target object in a sub-graph can be determined using the following methods: Following column order, the corresponding grid coordinates are sequentially obtained from the coordinate matrix of the sample sub-image subGrayImArray to be detected, and the image data subGrayImArray(i) corresponding to the sample sub-image to be detected within the grid coordinates is extracted, i∈[1,V], where V is the number of sub-images. The image acquired by the first image acquisition device is in back-illuminated mode, and the background of the images acquired by the second and third image acquisition devices is white. Therefore, the acquired sub-image is inverted to obtain the inverted image subGrayImArray(i)'=255-subGrayImArray(i). Hair or similar objects are presented in high grayscale. Thresholding is performed on the inverted image. Dynamic thresholding, fixed thresholding, double thresholding, or top-hat operation can be used to segment the hair or the target object that is similar to the hair in grayscale features from the background, and obtain the binary template of the target object.

[0063] S32. If the ratio of the number of pixels of the connected objects in the label matrix to the number of pixels of the current sub-image is less than a preset ratio threshold, then the connected objects are subjected to morphological processing to obtain a binary template of the morphological representation of the connected objects. In this embodiment of the invention, if the number of pixels of connected objects in the current label matrix is ​​0, the current detection is skipped and the detection of the next sub-image is performed. If it is non-zero, the ratio of the number of pixels of each connected object in the label matrix to the number of pixels of the current sub-image is checked to see if it is less than a preset ratio threshold. If it is, morphological processing is performed. If it is not, the image parameters of the sub-image are adjusted, and the ratio of the number of connected objects to the number of pixels of the current sub-image is matched again. If such connected objects still do not exist, the current detection is skipped and the detection of the next sub-image is performed. If they exist, morphological processing is performed. In this embodiment of the invention, a morphological structure can be constructed with preset parameters based on the characteristics of hair or hair-like objects. Morphological operations are performed on the connected objects in the label matrix in sequence, retaining the connected objects that can be completely deleted. The number of deleted connected objects is counted. If it is equal to 0, the current detection is skipped and the detection of the next sub-image is performed. If it is greater than 0, the deletable connected objects are skeletonized to obtain a binary template of the morphological representation of the currently detected connected objects.

[0064] In this embodiment of the invention, adjusting the subgraph parameters includes: By employing methods such as histogram equalization and gamma value transformation, parameters such as the number of discrete gray levels in the sub-image, the shape of the gamma curve, the stretching contrast enhancement limit, and the adjustment of the histogram shape are adjusted to enhance the contrast between the background and the target object in the sub-image. Then, the connected objects are obtained after binarization.

[0065] S33. Based on the morphological features of the binary template for morphological characterization, obtain the hair detection results of the test sample; wherein, the morphological features include the number of endpoints and the number of branch points.

[0066] In this embodiment of the invention, the non-zero pixels of the morphological representation binary template can be traversed, the number of adjacent pixels of each pixel can be counted, and the geometric parameters such as the number of endpoints and the number of branch points of the binary template can be determined. Based on these set parameters, it can be determined whether the sample to be detected has hair or hair-like objects. If so, the detection of subsequent sub-images can be stopped, and the next sample to be detected can be waited for. If not, the next sub-image can be detected.

[0067] In this embodiment of the invention, step S33, obtaining the hair detection result of the test sample based on the morphological features of the morphological characterization binary template, includes: S331. Determine the range of branch point numbers based on the number of endpoints. If the number of branch points is within the range of branch point numbers, determine that the sample to be tested contains hair. In this embodiment of the invention, the number of suspected hairs n can be calculated based on the number of endpoints: n = floor(EdN / 2) Where EdN is the number of endpoints of the connected object, rounded down from n. The maximum number of branch points BrNinCal that n hairs or similar objects can form is: BrNinCal=n×(n-1) / 2.

[0068] Therefore, the number of branch points can be determined to be within the range of [0, BrNinCal]. If the number of branch points of the connected object is within the range of the number of branch points, it can be determined that the sample to be tested contains hair.

[0069] S332. If the number of branch points of the connected object is not within the range of the number of branch points, it is determined that the sample to be tested does not contain hair.

[0070] This invention pre-filters excessively large background areas and excessively small noise points by using area ratio thresholds, retaining candidate connected objects that conform to hair scale characteristics. Then, it extracts a skeletonized morphological representation binary template through morphological processing, reducing the two-dimensional region to a single-pixel-wide topological skeleton. The specific recognition features of hair are constructed using geometric parameters such as the number of endpoints and the number of branch points, effectively distinguishing hair from interference objects such as bubbles, particles, and fiber clusters, and significantly reducing the false detection rate.

[0071] In one embodiment, after obtaining the hair detection result of the sample to be detected based on the morphological features of the connected objects in the subgraph in step S3, the method further includes: If foreign objects such as hair are detected in the sample to be tested, an activation signal is sent to the sorting device. The time required for the sample to reach the sorting device is calculated by dividing the distance from the centroid coordinates of the sample's grayscale image binary template to the sorting device by the ratio of the distance to the current conveying speed obtained by the speed encoder. After the countdown ends, a push cylinder pushes the abnormal sample to the sorting chute, and then the push cylinder resets. After sorting is completed, the device waits for the next activation signal.

[0072] In this embodiment of the invention, when it is determined that there are foreign objects such as hair in the sample to be detected, the computation time T spent by the algorithm can be determined based on the difference between the timestamp of the detection image of the sample and the timestamp at which the hair determination result ends. t .

[0073] Based on the centroid coordinates C of the binary template of the grayscale image of the sample to be tested, acquired during the acquisition of the sample's detection image, and the pre-determined distance d between the left edge of the field of view of the image acquisition device detecting hair foreign objects and the sorting device, the sum of their distances D = d + C (1) is calculated. The current sample conveying speed V is obtained by accessing a specific register address of the speed encoder, reading hexadecimal data, converting it to decimal speed data, and then calculating the time it takes for the sample to arrive at the sorting device as T = D / V - T.t - T d T d The time lead required to activate the sorting device.

[0074] This invention dynamically determines the range of branch point numbers by the number of endpoints, transforming the double-endpoint + finite-branch topological features of hair into quantifiable constraints. It adaptively matches different morphological scenarios such as single hair (branch point = 0) and intersecting hair (branch point ≤ endpoint - 1), avoiding rigid misjudgments caused by fixed thresholds, thereby effectively improving the robustness of recognition of complex hair distribution patterns.

[0075] Implementing the embodiments of the present invention has the following beneficial effects: This invention, through adaptive selection of different image acquisition strategies, can employ either transmitted or diffuse light illumination based on the sample's transmittance characteristics, ensuring high-contrast, low-noise detection images for all types of samples. This helps reduce missed and false detections caused by poor image quality. Furthermore, by using a preset grid to divide the detection image into multiple sub-images, this invention achieves refined scanning by partitioning, preventing hair from being submerged in complex backgrounds, thereby effectively reducing the probability of missed detections due to insufficient detection density. Moreover, this invention obtains hair detection results for the sample based on the morphological features of connected objects, effectively distinguishing hair from various interfering substances, further reducing the false detection rate, and thus further improving the hair detection results for edible by-products.

[0076] Furthermore, in this embodiment of the invention, excessively large background areas and excessively small noise points are pre-filtered by area ratio threshold, while retaining candidate connected objects that conform to the hair scale characteristics. Then, morphological processing is used to extract the skeletonized morphological representation binary template, reducing the two-dimensional region to a topological skeleton with a width of one pixel. The specific recognition features of hair are constructed using geometric parameters such as the number of endpoints and the number of branch points, which effectively distinguishes hair from interference objects such as bubbles, particles, and fiber clusters, and significantly reduces the false detection rate.

[0077] Please see Figure 3-5 In one embodiment, three schematic diagrams of a hair detection device for by-products are provided. The hair detection device includes a servo motor 1, an image acquisition device 2, an array of diffuse LED light sources 3, a bowl-shaped diffuse LED light source 4, an adjustable clamp 5, a speed encoder 6, a frosted diffuse background plate 7, a drive motor 8, a light source clamp 9, a tensioning wheel assembly 10, a conveyor belt cleaning brush 11, a conveyor belt cleaning roller 12, a pusher cylinder 13, and an abnormal product chute 14.

[0078] In this embodiment of the invention, the height of the image acquisition device 2 can be adjusted by the camera clamp of the servo motor 1, and the light sources corresponding to the three sets of image acquisition devices are respectively an array diffuse reflection LED light source 3, a bowl-shaped diffuse reflection LED light source 4 located above the transparent conveyor belt, and an array diffuse reflection LED light source 3. Figure 3 (visible) and the bowl-shaped diffuse reflection LED light source 4 located below the transparent conveyor belt. Figure 5 As can be seen, the top-view and bottom-view image acquisition devices are both equipped with white frosted diffuse reflection background plates 7, which are fixed by adjustable clamps and held by light source clamps 9. The transparent conveyor belt is powered by a drive motor 8. Since it is necessary to provide installation space for the light source, background plate and image acquisition device under the conveyor belt, the direction of the conveyor belt is adjusted by tensioning wheel sets 10 installed at different positions. When the sample to be tested passes through the image acquisition device 2 set by the application strategy, the detection image and grayscale binary template of the sample to be tested are acquired. Sub-images of the sample to be tested are obtained according to the preset grid division of the image detection area. Based on the width and structural features of each connected object in the target object in each sub-image, the presence of hair or similar objects in the sample to be tested is assessed. If present, the time when the sample to be tested arrives at the push cylinder 13 is calculated based on the sum of the centroid coordinates of the grayscale binary template of the sample to be tested, the distance from the field of view of the image acquisition device detecting the foreign object to the sorting push cylinder 13, the transmission speed of the speed encoder, the time consumed in determining the hair or foreign object, and the advance time for activating the sorting device. An activation signal is then sent. If not present, the analysis results of the next sample are awaited. After the activation signal is sent, the timer starts counting down. When the countdown ends, the push cylinder ejects the sorting push rod, pushing the abnormal sample to the abnormal item chute 14. The push cylinder 13 then resets, the timer resets, and the system waits for the next activation signal. To ensure the transparent conveyor belt remains clean and to prevent debris, lint, and other impurities from interfering with the judgment, a conveyor belt cleaning brush 11 and a conveyor belt cleaning roller are installed below the conveyor mechanism to remove any solid or liquid interfering factors that may appear on the surface of the transparent conveyor belt.

[0079] The hair detection device for by-products provided by the present invention is described below. The hair detection device for by-products described below and the hair detection method for by-products described above can be referred to in correspondence with each other.

[0080] Please see Figure 6 The present invention provides a fourth schematic diagram of a hair detection device for a product, the device comprising: The detection image determination module 610 is used to determine the detection image of the sample to be detected based on the selected image acquisition strategy; The sub-image division module 620 is used to divide the detected image into multiple sub-images according to a preset grid specification in the image detection area; The hair detection result determination module 630 is used to obtain the hair detection result of the sample to be detected based on the morphological features of the connected objects in the subgraph.

[0081] In one embodiment, before determining the detection image of the sample to be detected based on the selected image acquisition strategy, the method includes: When the transmittance of the sample to be tested is greater than or equal to a preset transmittance threshold, a first image acquisition strategy is selected; wherein, the first image acquisition strategy is to use a first image acquisition device and a third image acquisition device to acquire images, the first image acquisition device is a back-illuminated array diffuse reflection light source and a top view image acquisition device, and the third image acquisition device is an upward-illuminated bowl-shaped diffuse reflection light source and a bottom view image acquisition device. If the transmittance of the sample to be tested is less than a preset transmittance threshold, a second image acquisition strategy is selected. The second image acquisition strategy is to use a second image acquisition device and a third image acquisition device to acquire images. The second image acquisition device is a downward-illuminating bowl-shaped diffuse reflection light source and a top-view image acquisition device.

[0082] In one embodiment, before determining the detection image of the sample to be detected based on the selected image acquisition strategy, the method further includes: Acquire the grayscale image of the sample to be detected within the preset image area; The target object grayscale image of the sample to be tested is determined based on the grayscale image of the sample to be tested. The number of first pixels in the grayscale image of the target object that are greater than or equal to a preset transparency threshold is counted, and the number of second pixels in the binary template of the grayscale image of the sample to be detected is determined. When the ratio of the first number of pixels to the second number of pixels is greater than a preset ratio threshold, a first image acquisition strategy is adopted; when the ratio of the first number of pixels to the second number of pixels is less than or equal to the preset ratio threshold, a second image acquisition strategy is adopted.

[0083] In one embodiment, determining the detection image of the sample to be detected based on the selected image acquisition strategy includes: Based on the selected image acquisition strategy, the corresponding light source grayscale image and the sample grayscale image are acquired within the preset image detection area; Pixels in the grayscale image of the sample to be tested that are smaller than the maximum pixel value in the corresponding light source grayscale image are identified as pixels to be filled. The binary template of the grayscale image of the sample to be tested is obtained by filling the pixels to be filled. If the distance between the center coordinates of the preset image detection area and the centroid coordinates of the binary template is less than or equal to a preset distance, the grayscale image of the current sample to be tested is used as the detection image of the sample to be tested.

[0084] In one embodiment, dividing the detected image into multiple sub-images based on a preset grid specification in the image detection area includes: According to the preset grid specifications in the preset image detection area, the preset image detection area is divided into multiple sub-regions; The sub-regions containing non-zero pixels are corresponding to the detection image regions and are used as sub-images of the detection image.

[0085] In one embodiment, obtaining the hair detection result of the sample to be detected based on the morphological features of connected objects in the subgraph includes: Construct a binary template of the target object in the subgraph, and construct a label matrix of the binary template of the target object; If the ratio of the number of pixels of the connected objects in the label matrix to the number of pixels of the current subgraph is less than a preset ratio threshold, then the connected objects are subjected to morphological processing to obtain a binary template of the morphological representation of the connected objects. Based on the morphological features of the binary template for morphological characterization, the hair detection results of the test sample are obtained; wherein, the morphological features include the number of endpoints and the number of branch points.

[0086] In one embodiment, obtaining the hair detection result of the test sample based on the morphological features of the morphological characterization binary template includes: The number of branch points is determined based on the number of endpoints. If the number of branch points is within the range of the number of branch points, it is determined that hair is present in the sample to be tested. If the number of branch points of the connected object is not within the range of the number of branch points, it is determined that the sample to be tested does not contain hair.

[0087] Figure 7 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 7 As shown, the electronic device may include: a processor 710, a communications interface 720, a memory 730, and a communication bus 740, wherein the processor 710, the communications interface 720, and the memory 730 communicate with each other via the communication bus 740. The processor 710 can call logical instructions in the memory 730 to execute a hair detection method for by-products, the method including: Based on the selected image acquisition strategy, the detection image of the sample to be detected is determined; The detected image is divided into multiple sub-images according to the preset grid specifications in the image detection area; Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be tested are obtained.

[0088] Furthermore, the logical instructions in the aforementioned memory 730 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a 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 includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0089] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program that can be stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, the computer is capable of performing a hair detection method for byproduct products provided by the above methods, the method comprising: Based on the selected image acquisition strategy, the detection image of the sample to be detected is determined; The detected image is divided into multiple sub-images according to the preset grid specifications in the image detection area; Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be tested are obtained.

[0090] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a hair detection method for byproduct products provided by the methods described above, the method comprising: Based on the selected image acquisition strategy, the detection image of the sample to be detected is determined; The detected image is divided into multiple sub-images according to the preset grid specifications in the image detection area; Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be tested are obtained.

[0091] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0092] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0093] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for detecting hair in a by-product, characterized in that, include: Based on the selected image acquisition strategy, the detection image of the sample to be detected is determined; The detected image is divided into multiple sub-images according to the preset grid specifications in the image detection area; Based on the morphological features of the connected objects in the subgraph, the hair detection results of the sample to be tested are obtained.

2. The hair detection method for by-product products as described in claim 1, characterized in that, Before determining the detection image of the sample to be detected based on the selected image acquisition strategy, the process includes: When the transmittance of the sample to be tested is greater than or equal to a preset transmittance threshold, a first image acquisition strategy is selected; wherein, the first image acquisition strategy is to use a first image acquisition device and a third image acquisition device to acquire images, the first image acquisition device is a back-illuminated array diffuse reflection light source and a top view image acquisition device, and the third image acquisition device is an upward-illuminated bowl-shaped diffuse reflection light source and a bottom view image acquisition device. If the transmittance of the sample to be tested is less than a preset transmittance threshold, a second image acquisition strategy is selected. The second image acquisition strategy is to use a second image acquisition device and a third image acquisition device to acquire images. The second image acquisition device is a downward-illuminating bowl-shaped diffuse reflection light source and a top-view image acquisition device.

3. The hair detection method for by-product products as described in claim 2, characterized in that, Before determining the detection image of the sample to be detected based on the selected image acquisition strategy, the process also includes: Acquire the grayscale image of the sample to be detected within the preset image area; The target object grayscale image of the sample to be tested is determined based on the grayscale image of the sample to be tested. The number of first pixels in the grayscale image of the target object that are greater than or equal to a preset transparency threshold is counted, and the number of second pixels in the binary template of the grayscale image of the sample to be detected is determined. When the ratio of the first number of pixels to the second number of pixels is greater than a preset ratio threshold, a first image acquisition strategy is adopted; when the ratio of the first number of pixels to the second number of pixels is less than or equal to the preset ratio threshold, a second image acquisition strategy is adopted.

4. The hair detection method for by-product products as described in claim 1, characterized in that, The process of determining the detection image of the sample to be detected based on the selected image acquisition strategy includes: Based on the selected image acquisition strategy, the corresponding light source grayscale image and the sample grayscale image are acquired within the preset image detection area; Pixels in the grayscale image of the sample to be tested that are smaller than the maximum pixel value in the corresponding light source grayscale image are identified as pixels to be filled. The binary template of the grayscale image of the sample to be tested is obtained by filling the pixels to be filled. If the distance between the center coordinates of the preset image detection area and the centroid coordinates of the binary template is less than or equal to a preset distance, the grayscale image of the current sample to be tested is used as the detection image of the sample to be tested.

5. The hair detection method for by-product products as described in claim 1, characterized in that, The detection image is divided into multiple sub-images based on a preset grid specification in the image detection area, including: According to the preset grid specifications in the preset image detection area, the preset image detection area is divided into multiple sub-regions; The sub-regions containing non-zero pixels are corresponding to the detection image regions and are used as sub-images of the detection image.

6. The hair detection method for by-product products as described in claim 1, characterized in that, The hair detection result of the sample to be detected based on the morphological features of the connected objects in the subgraph includes: Construct a binary template of the target object in the subgraph, and construct a label matrix of the binary template of the target object; If the ratio of the number of pixels of the connected objects in the label matrix to the number of pixels of the current subgraph is less than a preset ratio threshold, then the connected objects are subjected to morphological processing to obtain a binary template of the morphological representation of the connected objects. Based on the morphological features of the binary template for morphological characterization, the hair detection results of the test sample are obtained; wherein, the morphological features include the number of endpoints and the number of branch points.

7. The hair detection method for by-product products as described in claim 6, characterized in that, The step of obtaining the hair detection result of the test sample based on the morphological features of the morphological characterization binary template includes: The number of branch points is determined based on the number of endpoints. If the number of branch points is within the range of the number of branch points, it is determined that hair is present in the sample to be tested. If the number of branch points of the connected object is not within the range of the number of branch points, it is determined that the sample to be tested does not contain hair.

8. A hair detection device for a by-product, characterized in that, include: The detection image determination module is used to determine the detection image of the sample to be detected based on the selected image acquisition strategy. The sub-image division module is used to divide the detected image into multiple sub-images according to a preset grid specification in the image detection area; The hair detection result determination module is used to obtain the hair detection result of the sample to be detected based on the morphological features of the connected objects in the subgraph.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the hair detection method for the by-product product as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the hair detection method for the by-product product as claimed in any one of claims 1 to 7.