Image-based material detection method and apparatus

By using a pixel histogram and step sampling method based on reference materials, the problem of detection errors caused by inconsistent pixel value thresholds was solved, thereby improving the accuracy and speed of material detection.

CN117197488BActive Publication Date: 2026-06-09BEIJING TIANMA INTELLIGENT CONTROL TECHNOLOGY CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING TIANMA INTELLIGENT CONTROL TECHNOLOGY CO LTD
Filing Date
2023-09-01
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

In existing technologies, image detection methods based on pixel value thresholds suffer from inconsistent thresholds due to manual adjustments, leading to detection errors and making it difficult to accurately identify material features.

Method used

By obtaining the pixel histogram of the reference material, the slope is calculated to determine the range of pixel values. Based on the preset step size sampling, the image region is divided and feature points are extracted. A uniform threshold for the number of pixels is used to determine whether the material is qualified.

Benefits of technology

It achieves accurate feature point extraction without manual debugging, improving detection accuracy and shortening debugging time, while also increasing computing speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117197488B_ABST
    Figure CN117197488B_ABST
Patent Text Reader

Abstract

This disclosure proposes an image-based material inspection method and apparatus, relating to the field of image inspection technology. The method includes: acquiring a first image of the material to be inspected; determining first feature points in the first image based on a first threshold; determining a first center position and a first centroid position of the first feature points; dividing the first image into multiple regions based on the first center position and the first centroid position, and sampling each region to obtain first pixels; determining a first number of first feature points contained in the first pixels; and determining whether the material to be inspected is qualified based on the first number and a pixel number threshold. This disclosure determines the first threshold by referring to the pixel histogram of the material, which can accurately extract feature points from the first image without manual adjustment. This disclosure also divides and samples the first image based on the center and centroid positions of the feature points, eliminating the need for full pixel detection and improving computational speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image detection technology, and in particular to an image-based material detection method and apparatus. Background Technology

[0002] In related technologies, there are methods for feature detection in images based on pixel value thresholds. If the feature in the image to be detected is black, pixels below the threshold are considered feature points. By counting the number of identified feature points, the quality of the material in the image is determined, i.e., whether the feature to be detected exists in the image. However, the pixel value threshold in this method is often manually adjusted, making it difficult for technicians to accurately find a suitable threshold. In practical applications, different technicians may have different feature selection criteria. Therefore, in the detection task of the same material, inconsistencies in pixel value thresholds may lead to detection errors. Summary of the Invention

[0003] This disclosure aims to at least partially address one of the technical problems in the related art.

[0004] Therefore, the first aspect of this disclosure proposes an image-based material detection method, comprising:

[0005] Acquire the first image of the material to be inspected;

[0006] A first feature point in the first image is determined based on a first threshold; wherein, the first threshold is a pixel value threshold used to extract image features, and the first threshold is obtained based on a second image of a reference material, wherein the reference material and the material to be detected are of the same type.

[0007] Determine the first center position and the first centroid position of the first feature point;

[0008] The first image is divided into multiple regions based on the first center position and the first centroid position, and the multiple regions are sampled respectively to obtain the first pixel.

[0009] Determine the first number of first feature points contained in the first pixel;

[0010] Whether the material to be tested is qualified is determined based on the first quantity and the pixel number threshold; wherein, the pixel number threshold is obtained based on the second image.

[0011] In some embodiments of this disclosure, the first threshold is determined in the following manner:

[0012] A second image of the reference material is obtained, and a pixel histogram of the second image is obtained, wherein the horizontal axis of the pixel histogram is the pixel value, and the vertical axis is the number of pixels for each pixel value;

[0013] The number of first pixels for each pixel value is determined based on the pixel histogram, and the discrete first derivative is calculated for the number of first pixels for each pixel value to obtain the slope corresponding to multiple pixel values.

[0014] Determine the minimum slope among the slopes corresponding to the plurality of pixel values;

[0015] The range of the first pixel value is determined based on the minimum slope;

[0016] The number of pixels for each pixel value within the first pixel value range is summed based on a preset step size to obtain the total number of pixels for each pixel value within the first pixel value range within the step size range.

[0017] The pixel value corresponding to the minimum total number of pixels within the step range of each pixel value within the first pixel value range is determined as the first threshold.

[0018] In some embodiments of this disclosure, determining the number of first pixels for each pixel value based on the pixel histogram includes:

[0019] The number of pixels for each pixel value in the pixel histogram is filtered to obtain the first number of pixels for each pixel value.

[0020] In some embodiments of this disclosure, determining the number of first pixels for each pixel value based on the pixel histogram includes:

[0021] Determine the background pixel values ​​in the pixel histogram;

[0022] Determine the number of first pixels for each pixel value in the pixel histogram, excluding the background pixel value.

[0023] In some embodiments of this disclosure, when the backgrounds of the first image and the second image are white and the feature threshold is black, determining the first pixel value range based on the minimum slope includes: determining the pixel value from the minimum slope to the maximum pixel value as the first pixel value range; or...

[0024] When the background of the first image and the second image is black and the feature threshold is white, the step of determining the first pixel value range based on the minimum slope includes: determining the pixel value from the minimum pixel value to the pixel value corresponding to the minimum slope as the first pixel value range.

[0025] In some embodiments of this disclosure, the pixel count threshold is predetermined in the following manner:

[0026] The second feature point in the second image is determined based on the first threshold;

[0027] Determine the second center position and the second centroid position of the second feature point;

[0028] The second image is divided into multiple regions based on the second center position and the second centroid position, and the multiple regions are sampled respectively to obtain the second pixel.

[0029] The number of pixels containing the second feature point in the second pixel is determined as the pixel number threshold.

[0030] In some embodiments of this disclosure, when the backgrounds of the first image and the second image are white and the feature threshold is black, determining the first feature point in the first image based on the first threshold includes: determining pixels in the first image whose pixel values ​​are less than or equal to the first threshold as the first feature point; or,

[0031] When the background of the first image and the second image is black and the feature threshold is white, the step of determining the first feature point in the first image based on the first threshold includes: determining the pixel points in the first image whose pixel values ​​are greater than or equal to the first threshold as the first feature points.

[0032] In some embodiments of this disclosure, dividing the first image into multiple regions based on the first center position and the first centroid position includes:

[0033] The first image is used as the first region;

[0034] The smallest rectangle centered at the first center position and including the first feature point is defined as the second region;

[0035] Based on the distance from the first centroid position to the two nearest adjacent sides of the second region, a first length and a first width are determined, and a third region is constructed with the first centroid position as the center, the first length as the region length, and the first width as the region length.

[0036] In some embodiments of this disclosure, sampling the plurality of regions to obtain a first pixel includes:

[0037] Pixel sampling is performed using a first step distance in the first region, a second step distance in the second region, and a third step distance in the third region to obtain the first pixel.

[0038] Wherein, the first step distance is greater than or equal to the second step distance, and the second step distance is greater than or equal to the third step distance.

[0039] In some embodiments of this disclosure, determining whether the material to be tested is qualified based on the first pixel count and a pixel count threshold includes:

[0040] The comparison similarity between the first image and the second image is determined based on the first number of pixels and the pixel number threshold.

[0041] Based on the comparison similarity and the judgment threshold, it is determined whether the material to be tested is qualified.

[0042] In some embodiments of this disclosure, the comparison similarity between the first image and the second image is determined using the following formula based on the first pixel count and the pixel count threshold:

[0043]

[0044] Where Re is the comparison similarity between the first image and the second image, N is the threshold number of pixels, and M is the number of the first pixels.

[0045] A second aspect of this disclosure provides an image-based material detection device, comprising:

[0046] The acquisition module is used to acquire the first image of the material to be inspected;

[0047] The first determining module is used to determine a first feature point in the first image based on a first threshold; wherein, the first threshold is a pixel value threshold for extracting image features, and the first threshold is obtained based on a second image of a reference material, wherein the reference material and the material to be detected are of the same type.

[0048] The second determining module is used to determine the first center position and the first centroid position of the first feature point;

[0049] The sampling module is used to divide the first image into multiple regions based on the first center position and the first centroid position, and to sample the multiple regions respectively to obtain the first pixel.

[0050] The third determining module is used to determine the first number of first feature points contained in the first pixel.

[0051] The detection module is used to determine whether the material to be detected is qualified based on the first quantity and the pixel number threshold; wherein the pixel number threshold is obtained based on the second image.

[0052] A third aspect of this disclosure 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, when executing the program, implements the method described in the first aspect above.

[0053] The fourth aspect of this disclosure provides a non-transitory computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the method described in the first aspect above.

[0054] According to the image-based material detection method disclosed herein, feature points in a first image can be accurately extracted based on a first threshold obtained from a reference material, eliminating the need for manual debugging by personnel, saving debugging time, and improving feature extraction accuracy. Furthermore, by dividing the first image into regions based on the center and centroid positions of the first feature points and assigning different sampling step sizes to different regions, full-pixel detection of the image is unnecessary, thus improving computational speed while ensuring detection effectiveness.

[0055] Additional aspects and advantages of this disclosure will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this disclosure. Attached Figure Description

[0056] The above and / or additional aspects and advantages of this disclosure will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, in which:

[0057] Figure 1 A flowchart illustrating a method for determining a first threshold provided in an embodiment of this disclosure;

[0058] Figure 2 A pixel histogram of a rubber ring region image in a hydraulic component provided in this embodiment of the present disclosure;

[0059] Figure 3 This is a flowchart illustrating a method for determining a threshold number of pixels provided in an embodiment of this disclosure.

[0060] Figure 4 This is a schematic diagram of a second feature point in a second image provided by an embodiment of the present disclosure;

[0061] Figure 5 This is a schematic flowchart of an image-based material detection method provided in an embodiment of the present disclosure;

[0062] Figure 6 This is a schematic diagram of an image-based material detection device provided in an embodiment of this application. Detailed Implementation

[0063] Embodiments of this disclosure are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this disclosure, and should not be construed as limiting this disclosure.

[0064] This disclosure proposes an image-based material detection method and apparatus to improve the accuracy of material detection. Specifically, embodiments of the image-based material detection method and apparatus of this disclosure are described below with reference to the accompanying drawings.

[0065] To better understand the image-based material detection method in the embodiments of this disclosure, the method for determining the first threshold and the pixel number threshold used in this method will be described first. Figure 1 This is a flowchart illustrating a method for determining a first threshold provided in an embodiment of this disclosure. Figure 1 As shown, the method for determining the first threshold includes the following steps:

[0066] Step 101: Obtain a second image of the reference material and obtain the pixel histogram of the second image.

[0067] In the pixel histogram, the horizontal axis represents pixel values ​​from 0 to 255, and the vertical axis represents the number of pixels for each pixel value.

[0068] It should be noted that the reference material is a qualified material with the features to be detected. The second image is an image of the features to be detected within the reference material. As an example, let's consider a hydraulic component as the reference material, which includes a rubber ring. In the task of detecting the rubber ring of a hydraulic component, the rubber ring is the feature to be detected; that is, whether the hydraulic component includes a rubber ring is detected. If it does not include a rubber ring, the hydraulic component is unqualified; if it does include a rubber ring, it is qualified. The aperture and focal length of the camera lens are adjusted to ensure clear image features and distinct outlines. A photograph of the hydraulic component is taken, obtaining a photo of the hydraulic component. Then, the area of ​​the rubber ring is cropped from the photograph of the hydraulic component and used as the second image of the reference material. As an example... Figure 2 This is a pixel histogram of a rubber ring region image in a hydraulic component provided in an embodiment of this disclosure.

[0069] Step 102: Determine the number of first pixels for each pixel value based on the pixel histogram, and calculate the discrete first derivative of the number of first pixels for each pixel value to obtain the slope corresponding to multiple pixel values.

[0070] In one implementation, to reduce the impact of noise in the pixel histogram, the number of pixels for each pixel value in the pixel histogram can be filtered to obtain the first pixel count for each pixel value. As an example, a 1x5 filter kernel can be used to filter the number of pixels for each pixel value in the pixel histogram using the following formula:

[0071]

[0072] Among them, P i p represents the number of pixels with pixel value i after filtering. i This represents the number of pixels with pixel value i in the pixel histogram.

[0073] In another implementation, in order to reduce the impact of background pixels on the extraction of features to be detected, background pixel values ​​and their corresponding number of pixels can be deleted from the pixel histogram, and the number of first pixels for each pixel value other than the background pixel value can be determined.

[0074] As an example, when the background of the second image is white and the feature threshold is black (see reference). Figure 2 , Figure 2 In the first image, with a white background and a black feature threshold for the rubber band, background pixels in the range of 246-255 are deleted, and the number of first pixels for each pixel value in the range of 0-245 is determined. In the second image, with a black background and a white feature threshold, background pixels in the range of 0-9 are deleted, and the number of first pixels for each pixel value in the range of 10-255 is determined. Alternatively, the background color and feature threshold can be disregarded; for both white and black background images, pixels in the ranges of 0-9 and 246-255 are deleted, and the number of first pixels for each pixel value in the range of 10-245 is determined.

[0075] In another implementation, background pixel values ​​can be removed from the pixel histogram, and the number of pixels for each pixel value other than the background pixel value in the pixel histogram can be filtered to obtain the first pixel value for each pixel value other than the background pixel value.

[0076] After determining the number of first pixels for each pixel value based on the pixel histogram, the discrete first derivative is calculated for each number of first pixels to obtain the slope corresponding to multiple pixel values. As an example, assuming pixel values ​​in the ranges of 0-9 and 246-255 are removed from the pixel histogram, after filtering the number of first pixels for each pixel value in the range of 10-245, the slope corresponding to each pixel value in the range of 10-245 can be obtained using the following formula:

[0077]

[0078] Where, k i P represents the slope corresponding to pixel value i. i is the number of pixels with the filtered pixel value i, and s is the offset distance. Optionally, the offset distance s can be a value greater than 5.

[0079] Step 103: Determine the minimum slope among the slopes corresponding to multiple pixel values.

[0080] It should be noted that the pixel value corresponding to the smallest slope among multiple pixel values ​​can be used as the feature termination position.

[0081] Optionally, in some embodiments of this disclosure, after obtaining the minimum slope, the pixel value corresponding to the minimum slope can be compared with the pixel value corresponding to the second minimum efficiency. If the pixel value corresponding to the second minimum efficiency is greater than the pixel value corresponding to the minimum slope, and the difference is greater than 50, it indicates that the features in the image are relatively obvious, and subsequent steps can be continued; otherwise, the brightness of the second image can be readjusted and the above steps can be repeated.

[0082] Step 104: Determine the range of the first pixel value based on the minimum slope.

[0083] In one implementation, when the background of the second image is white and the feature threshold is black, the range from the pixel value corresponding to the minimum slope to the maximum pixel value can be defined as the first pixel value range. When the background of the second image is black and the feature threshold is white, the range from the minimum pixel value to the pixel value corresponding to the minimum slope can be defined as the first pixel value range.

[0084] As an example, suppose in step 102, the number of first pixels for each pixel value in the range of 10-245 pixel values ​​is determined, and the minimum slope k in the range of 10-245 pixel values ​​is determined. min Corresponding pixel value It can be obtained using the following formula.

[0085]

[0086] When the background of the second image is white and the feature threshold is black, the range of the first pixel value is ( 245). When the background of the second image is black and the feature threshold is white, the range of the first pixel value is (10, ...). ).

[0087] Step 105: Sum the number of pixels for each pixel value within the first pixel value range based on the preset step distance to obtain the total number of pixels for each pixel value within the first pixel value range within the step distance range.

[0088] In one implementation, when the background of the second image is white and the feature threshold is black, the total number of pixels within the step range for each pixel value within the first pixel value range can be obtained by the following formula:

[0089]

[0090] Where d is the preset step size, T(i) is the total number of pixels with pixel value i within the first pixel value range and within the step size range d, and α is the step size weight.

[0091] When the background of the second image is black and the feature threshold is white, the total number of pixels within the step range for each pixel value in the first pixel value range can be obtained by the following formula:

[0092]

[0093] Where d is the preset step size, T(i) is the total number of pixels with pixel value i within the first pixel value range and within the step size range d, and α is the step size weight.

[0094] Optionally, the preset step size d can be selected from [5-10], and the step size weight α can be selected from [0.1-0.5]. By setting the preset step size, some noise interference can be eliminated, and the appearance and disappearance trends of features in the image can be preserved.

[0095] Step 106: Determine the pixel value corresponding to the minimum total number of pixels among the total number of pixels within the step range of each pixel value range as the first threshold.

[0096] The pixel value corresponding to the minimum sum of the number of pixels within the step range of each pixel value within the first pixel value range is the lowest valley position after selecting the first feature. This lowest valley position is used as the first threshold, so that the features in the image can be accurately extracted based on the first threshold.

[0097] As an example, when the background of the second image is white and the feature threshold is black, the first threshold th can be obtained by the following formula:

[0098]

[0099] When the background of the second image is black and the feature threshold is white, the first threshold th can be obtained by the following formula:

[0100]

[0101] By implementing embodiments of this disclosure, a first threshold is determined by referencing the pixel histogram of the material, so as to accurately extract features from the material image in subsequent detection tasks. Embodiments of this disclosure eliminate the need for manual debugging, significantly reducing manual debugging time. By standardizing the first threshold, the accuracy of material detection is improved.

[0102] Figure 3 This is a flowchart illustrating a method for determining a threshold number of pixels provided in an embodiment of this disclosure. Figure 3 As shown, the method for determining the pixel count threshold includes the following steps:

[0103] Step 301: Determine the second feature point in the second image based on the first threshold.

[0104] In one implementation, the second image can be binarized based on a first threshold to determine the second feature points. As an example, when the background of the second image is white and the feature threshold is black, pixels in the second image with pixel values ​​less than or equal to the first threshold can be identified as second feature points. When the background of the second image is black and the feature threshold is white, pixels in the second image with pixel values ​​greater than or equal to the first threshold can be identified as second feature points.

[0105] Step 302: Determine the second center position and the second centroid position of the second feature point.

[0106] Figure 4 This is a schematic diagram of a second feature point in a second image provided in an embodiment of this disclosure. For example... Figure 4 As shown, the second image includes multiple second feature points 401, thereby determining the second center position 402 and the second centroid position 403 of the second feature points 401.

[0107] Optionally, in some embodiments of this disclosure, in order not to affect the selection of the center position and the centroid position, the second image can be pre-filtered. For example, a 2D filter can be used to filter the image, and the filter size can be selected according to the actual situation. A larger value can be set to filter noise, and the increased calculation will not significantly affect the calculation time.

[0108] Step 303: Divide the second image into multiple regions based on the second center position and the second centroid position, and sample each region to obtain the second pixel.

[0109] In some embodiments of this disclosure, multiple regions containing second feature points can be constructed based on a preset length and width, centered on a second center position and a second centroid position, respectively. For example, a rectangle constructed around the second center position can cover most of the second feature points in the second image, while a rectangle constructed around the second centroid position can cover the second feature points in the second image that are more important for feature recognition. Since the types of second feature points included in different regions vary, different acquisition step sizes can be set for different regions, which can improve the processing speed and eliminate the need for full-point detection of the second image.

[0110] In one implementation, such as Figure 4 As shown, the second image can be used as the first region 411. A minimum rectangle centered at the second center position 402 is fitted, which includes all the second feature points 401, and this minimum rectangle is determined as the second region 412. Based on the distances h2 and w2 from the second centroid position 403 to the two nearest adjacent sides l1 and l2 of the second region 412, respectively, a second length 2h2 and a second width 2w2 are determined. Then, with the second centroid position 403 as the center, the second length 2h2 as the region length, and the second width 2w2 as the region width, a third region 413 is constructed.

[0111] Pixel sampling is performed using a first step distance in the first region 411, a second step distance in the second region 412, and a third step distance in the third region 413, thereby obtaining the second pixel. The first step distance is greater than or equal to the second step distance, and the second step distance is greater than or equal to the third step distance.

[0112] As an example, the first step spacing can be 5, the second step spacing can be 2, and the third step spacing can be 1. That is, in the first region 411, one pixel is sampled every 5 pixels as the second pixel, in the second region 412, one pixel is sampled every 2 pixels as the second pixel, and all pixels in the third region 413 are used as the second pixel.

[0113] Step 304: Determine the number of pixels containing the second feature point in the second pixel as the pixel number threshold.

[0114] By implementing the embodiments of this disclosure, the second image is divided into regions based on the center and centroid positions of the second feature points, and different sampling step sizes are assigned to different regions. This method eliminates the need for full-pixel detection of the image, and the resulting pixel count threshold can be used in subsequent detection tasks of the material to be detected, improving computational speed without affecting detection performance.

[0115] Figure 5 This is a schematic flowchart illustrating an image-based material detection method provided in an embodiment of this disclosure. Figure 5As shown, the image-based material detection method includes the following steps:

[0116] Step 501: Obtain the first image of the material to be inspected.

[0117] It should be noted that the material to be tested and the reference material are of the same type, and the first image is an image of the feature to be tested in the material to be tested.

[0118] Step 502: Determine the first feature point in the first image based on the first threshold.

[0119] The first threshold is a pixel value threshold used to extract image features. This first threshold is obtained based on a second image of the reference material, and its determination process can be referred to the aforementioned... Figure 1 The illustrated embodiment.

[0120] In one implementation, the first image can be binarized based on a first threshold to determine the first feature point. As an example, when the background of the first image is white and the feature threshold is black, pixels in the first image with pixel values ​​less than or equal to the first threshold can be identified as the first feature point. When the background of the second image is black and the feature threshold is white, pixels in the first image with pixel values ​​greater than or equal to the first threshold can be identified as the first feature point.

[0121] Step 503: Determine the first center position and the first centroid position of the first feature point.

[0122] The implementation method for this step can be referred to the above. Figure 3 The implementation of step 302 in the illustrated embodiment will not be described again here.

[0123] Step 504: Divide the first image into multiple regions based on the first center position and the first centroid position, and sample each region to obtain the first pixel.

[0124] In one implementation, the first image can be used as the first region, the smallest rectangle centered at the first center position and including all the first feature points can be determined as the second region, the first length 2h1 and the first width 2w1 can be determined according to the distances h1 and w1 from the first centroid position to the two nearest adjacent sides of the second region, and the third region can be constructed with the first centroid position as the center, the first length 2h1 as the region length, and the first width 2w1 as the region length.

[0125] Pixel sampling is performed using a first step distance in the first region, a second step distance in the second region, and a third step distance in the third region to obtain the first pixel. The first step distance is greater than or equal to the second step distance, and the second step distance is greater than or equal to the third step distance. This reduces the number of pixels detected in the first region, which does not include feature points, so even if noise interference exists in the first region, it will not significantly affect the final material detection result. By partitioning the first image and sampling based on a preset step distance, it can be ensured that important feature pixels are not ignored and the detection effect is not affected. It should be noted that the sampling step distance in the regions divided in the first image must be the same as the sampling step distance in the regions divided in the second image.

[0126] Step 505: Determine the first number of first feature points contained in the first pixel.

[0127] Step 506: Determine whether the material to be tested is qualified based on the first quantity and the pixel number threshold. The pixel number threshold is obtained based on the second image.

[0128] In one implementation, a first quantity can be compared with a pixel quantity threshold. If they match, the material to be tested is determined to be qualified. If they do not match, the material to be tested is determined to be unqualified.

[0129] In another implementation, the comparison similarity between the first image and the second image can be determined based on the number of first pixels and a pixel number threshold. Based on the comparison similarity and the judgment threshold, it is determined whether the material to be tested is qualified.

[0130] As an example, the similarity between the first and second images can be obtained using the following formula:

[0131]

[0132] Where Re is the similarity between the first image and the second image, N is the threshold for the number of pixels, and M is the number of pixels in the first image.

[0133] The comparison similarity Re is compared with the judgment threshold TH. If the comparison similarity Re is greater than or equal to the judgment threshold TH, the material to be tested is determined to be qualified. If the comparison similarity Re is less than the judgment threshold TH, the material to be tested is determined to be unqualified. The judgment threshold TH ranges from 0% to 100%. Optionally, the judgment threshold TH can be set to 60%, and this setting of the judgment threshold TH can be modified in subsequent testing.

[0134] By implementing the embodiments of this disclosure, feature points in the first image can be accurately extracted based on a first threshold obtained from a reference material, eliminating the need for manual debugging by personnel, saving debugging time, and improving feature extraction accuracy. Furthermore, by dividing the first image into regions based on the center and centroid positions of the first feature points and assigning different sampling step sizes to different regions, full-pixel detection of the image is unnecessary, thus improving computational speed while ensuring detection effectiveness.

[0135] Figure 6 This is a schematic diagram of an image-based material detection device provided in an embodiment of this application. Figure 6 As shown, the image-based material detection device includes: an acquisition module 601, a first determination module 602, a second determination module 603, a sampling module 604, a third determination module 605, and a detection module 606.

[0136] The acquisition module 601 is used to acquire the first image of the material to be detected.

[0137] The first determining module 602 is used to determine a first feature point in the first image based on a first threshold. The first threshold is a pixel value threshold used to extract image features, and it is obtained based on a second image of a reference material, wherein the reference material and the material to be detected are of the same type.

[0138] The second determining module 603 is used to determine the first center position and the first centroid position of the first feature point.

[0139] The sampling module 604 is used to divide the first image into multiple regions according to the first center position and the first centroid position, and to sample the multiple regions respectively to obtain the first pixel.

[0140] The third determining module 605 is used to determine the first number of first feature points contained in the first pixel.

[0141] The detection module 606 is used to determine whether the material to be detected is qualified based on a first quantity and a pixel number threshold. The pixel number threshold is obtained based on a second image.

[0142] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0143] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0144] To implement the above embodiments, this application also proposes an electronic device, including: a processor and a memory for storing processor-executable instructions. These instructions are executed by the processor to enable the processor to perform the aforementioned image-based material inspection method.

[0145] To implement the above embodiments, this application also proposes a non-transitory computer-readable storage medium, which, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to perform the aforementioned image-based material detection method.

[0146] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0147] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0148] Any process or method description in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or more executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.

[0149] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable media include: an electrical connection having one or more wires (electronic device), a portable computer disk drive (magnetic device), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Alternatively, the computer-readable medium may be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in a computer memory.

[0150] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0151] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.

[0152] Furthermore, the functional units in the various embodiments of this application can be integrated into a processing module, or each unit can exist physically separately, or two or more units can be integrated into a module. The integrated module can be implemented in hardware or as a software functional module. If the integrated module is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.

[0153] The storage medium mentioned above can be a read-only memory, a disk, or an optical disk, etc. Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of this application.

Claims

1. An image-based material detection method, characterized by, Includes the following steps: Acquire the first image of the material to be inspected; A first feature point in the first image is determined based on a first threshold; wherein, the first threshold is a pixel value threshold used to extract image features, and the first threshold is obtained based on a second image of a reference material, wherein the reference material and the material to be detected are of the same type. Determine the first center position and the first centroid position of the first feature point; The first image is divided into multiple regions based on the first center position and the first centroid position, and the multiple regions are sampled respectively to obtain the first pixel. Determine the first number of first feature points contained in the first pixel; Whether the material to be tested is qualified is determined based on the first quantity and the pixel number threshold; wherein, the pixel number threshold is obtained based on the second image; The first threshold is determined in the following way: A second image of the reference material is obtained, and a pixel histogram of the second image is obtained, wherein the horizontal axis of the pixel histogram is the pixel value, and the vertical axis is the number of pixels for each pixel value; The number of first pixels for each pixel value is determined based on the pixel histogram, and the discrete first derivative is calculated for the number of first pixels for each pixel value to obtain the slope corresponding to multiple pixel values. Determine the minimum slope among the slopes corresponding to the plurality of pixel values; The range of the first pixel value is determined based on the minimum slope; The number of pixels for each pixel value within the first pixel value range is summed based on a preset step size to obtain the total number of pixels for each pixel value within the first pixel value range within the step size range. The pixel value corresponding to the minimum total number of pixels among all pixel values ​​within the first pixel value range within the step range is determined as the first threshold. When the backgrounds of the first and second images are white and the feature threshold is black, determining the first pixel value range based on the minimum slope includes: determining the pixel value from the minimum slope to the maximum pixel value as the first pixel value range; or... When the background of the first image and the second image is black and the feature threshold is white, the step of determining the first pixel value range according to the minimum slope includes: determining the pixel value from the minimum pixel value to the pixel value corresponding to the minimum slope as the first pixel value range; The pixel count threshold is predetermined in the following manner: The second feature point in the second image is determined based on the first threshold; Determine the second center position and the second centroid position of the second feature point; The second image is divided into multiple regions based on the second center position and the second centroid position, and the multiple regions are sampled respectively to obtain the second pixel. The number of pixels containing the second feature point in the second pixel is determined as the pixel number threshold. The step of dividing the first image into multiple regions based on the first center position and the first centroid position includes: The first image is used as the first region; The smallest rectangle centered at the first center position and including the first feature point is defined as the second region; Based on the distance from the first centroid position to the two nearest adjacent sides of the second region, a first length and a first width are determined, and a third region is constructed with the first centroid position as the center, the first length as the region length, and the first width as the region length.

2. The method of claim 1, wherein, The step of determining the number of first pixels for each pixel value based on the pixel histogram includes: The number of pixels for each pixel value in the pixel histogram is filtered to obtain the first number of pixels for each pixel value.

3. The method of claim 1, wherein, The step of determining the number of first pixels for each pixel value based on the pixel histogram includes: Determine the background pixel values ​​in the pixel histogram; Determine the number of first pixels for each pixel value in the pixel histogram, excluding the background pixel value.

4. The method of claim 1, wherein, When the backgrounds of the first image and the second image are white and the feature threshold is black, determining the first feature point in the first image based on the first threshold includes: determining pixels in the first image whose pixel values ​​are less than or equal to the first threshold as the first feature point; or... When the background of the first image and the second image is black and the feature threshold is white, the step of determining the first feature point in the first image based on the first threshold includes: determining the pixel points in the first image whose pixel values ​​are greater than or equal to the first threshold as the first feature points.

5. The method of claim 1, wherein, The step of sampling the multiple regions to obtain the first pixel includes: Pixel sampling is performed using a first step distance in the first region, a second step distance in the second region, and a third step distance in the third region to obtain the first pixel. Wherein, the first step distance is greater than or equal to the second step distance, and the second step distance is greater than or equal to the third step distance.

6. The method of claim 1, wherein, The step of determining whether the material to be tested is qualified based on the number of the first pixel and the pixel number threshold includes: The comparison similarity between the first image and the second image is determined based on the first number of pixels and the pixel number threshold. Based on the comparison similarity and the judgment threshold, it is determined whether the material to be tested is qualified.

7. The method of claim 6, wherein, Based on the first number of pixels and the pixel number threshold, the comparison similarity between the first image and the second image is determined using the following formula: wherein, is a contrast similarity of the first image and the second image, is the pixel quantity threshold value, is the first pixel quantity.

8. An image-based material detection apparatus, characterized by, include: The acquisition module is used to acquire the first image of the material to be inspected; The first determining module is used to determine a first feature point in the first image based on a first threshold; wherein, the first threshold is a pixel value threshold for extracting image features, and the first threshold is obtained based on a second image of a reference material, wherein the reference material and the material to be detected are of the same type. The second determining module is used to determine the first center position and the first centroid position of the first feature point; The sampling module is used to divide the first image into multiple regions based on the first center position and the first centroid position, and to sample the multiple regions respectively to obtain the first pixel. The third determining module is used to determine the first number of first feature points contained in the first pixel. The detection module is used to determine whether the material to be detected is qualified based on the first quantity and the pixel number threshold; wherein the pixel number threshold is obtained based on the second image; The first threshold is determined in the following way: A second image of the reference material is obtained, and a pixel histogram of the second image is obtained, wherein the horizontal axis of the pixel histogram is the pixel value, and the vertical axis is the number of pixels for each pixel value; The number of first pixels for each pixel value is determined based on the pixel histogram, and the discrete first derivative is calculated for the number of first pixels for each pixel value to obtain the slope corresponding to multiple pixel values. Determine the minimum slope among the slopes corresponding to the plurality of pixel values; The range of the first pixel value is determined based on the minimum slope; The number of pixels for each pixel value within the first pixel value range is summed based on a preset step size to obtain the total number of pixels for each pixel value within the first pixel value range within the step size range. The pixel value corresponding to the minimum total number of pixels among all pixel values ​​within the first pixel value range within the step range is determined as the first threshold. When the backgrounds of the first and second images are white and the feature threshold is black, determining the first pixel value range based on the minimum slope includes: determining the pixel value from the minimum slope to the maximum pixel value as the first pixel value range; or... When the background of the first image and the second image is black and the feature threshold is white, the step of determining the first pixel value range according to the minimum slope includes: determining the pixel value from the minimum pixel value to the pixel value corresponding to the minimum slope as the first pixel value range; The pixel count threshold is predetermined in the following manner: The second feature point in the second image is determined based on the first threshold; Determine the second center position and the second centroid position of the second feature point; The second image is divided into multiple regions based on the second center position and the second centroid position, and the multiple regions are sampled respectively to obtain the second pixel. The number of pixels containing the second feature point in the second pixel is determined as the pixel number threshold. The step of dividing the first image into multiple regions based on the first center position and the first centroid position includes: The first image is used as the first region; The smallest rectangle centered at the first center position and including the first feature point is defined as the second region; Based on the distance from the first centroid position to the two nearest adjacent sides of the second region, a first length and a first width are determined, and a third region is constructed with the first centroid position as the center, the first length as the region length, and the first width as the region length.

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

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