Foreign matter detection method and device, electronic equipment and storage medium

By introducing a target grayscale difference recheck mechanism in foreign object detection, the problem of low accuracy caused by detection relying on machine learning results in the existing technology is solved, and the accuracy and reliability of foreign object detection are improved.

CN118735843APending Publication Date: 2024-10-01HANGZHOU HIKVISION DIGITAL TECHNOLOGY CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310350288.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-29
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

Existing foreign object detection methods rely on machine learning results and lack a re-inspection process, resulting in low detection accuracy and prone to missed detections and false detections.

Method used

By obtaining the target image of the product to be detected, the foreign object detection model is used for initial detection. If foreign objects are detected, further re-inspection is performed based on the target grayscale difference in the target area to determine the final detection result and improve detection accuracy.

Benefits of technology

The re-inspection mechanism improves the accuracy of foreign object detection, reduces missed detections and false detections, and enhances the reliability and accuracy of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118735843A_ABST
    Figure CN118735843A_ABST
Patent Text Reader

Abstract

The invention discloses a foreign matter detection method and device, electronic equipment and a storage medium. The method comprises the steps that a target picture of a to-be-detected product is acquired; detecting whether foreign matters exist in the to-be-detected product according to the target picture foreign matter detection model to obtain an initial detection result; under the condition that the initial detection result is that the foreign matter exists in the to-be-detected product, obtaining a target area where a foreign matter image in the target picture is located in the target picture; and according to the target gray scale difference value of the target area, obtaining a final detection result of whether the foreign matter exists in the to-be-detected product or not. According to the embodiment, the accuracy of foreign matter detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of image processing technology, and specifically relates to a foreign matter detection method, device, electronic device and storage medium. Background Art

[0002] In the industrial field, products usually need to be inspected before leaving the factory to screen out unqualified products with foreign matter inside. For example, detecting whether there are foreign matter such as metal, glass, ceramic, etc. inside the product is an important part of product quality control.

[0003] In the related art, in the process of detecting whether there are foreign objects in the product, foreign objects are usually placed in qualified products, and unqualified images and teaching data are collected. A small amount of data is virtual data constructed by pasting foreign object images on qualified products, and these data are used to complete the training of the machine learning model. In the actual deployment and application process, the machine learning-based model outputs the likelihood of the presence of foreign objects in each pixel as the judgment result.

[0004] However, the foreign body recognition algorithm of the above detection method completely relies on the results of machine learning, lacks a re-inspection process, is prone to missed detection and false detection problems, and the detection accuracy is not high. Summary of the invention

[0005] The embodiments of the present application provide a foreign body detection method, device, electronic device and storage medium to solve the problem that the foreign body detection process relies on the results of machine learning and the detection accuracy is not high.

[0006] In a first aspect, an embodiment of the present application provides a foreign body detection method, comprising:

[0007] Get the target image of the product to be inspected;

[0008] According to the target image and the foreign body detection model, detecting whether the product to be detected has foreign bodies, and obtaining an initial detection result;

[0009] When the initial detection result is that foreign matter exists in the product to be detected, obtaining a target area in the target image where an image of the foreign matter is located in the target image;

[0010] A final detection result of whether the product to be detected has foreign matter is obtained according to the target grayscale difference of the target area.

[0011] In a second aspect, the present application further provides a foreign body detection device, including:

[0012] The first acquisition module is used to acquire a target image of the product to be inspected;

[0013] A first detection module, configured to detect whether the product to be detected has foreign matter based on the target image and the foreign matter detection model, and obtain an initial detection result;

[0014] A second acquisition module is used to acquire a target area where an image of a foreign object in the target image is located in the target image when the initial detection result is that a foreign object exists in the product to be detected;

[0015] The second detection module is used to obtain a final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area.

[0016] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the method described in the first aspect.

[0017] In a fourth aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0018] The solution provided by the embodiment of the present application obtains a target image of the product to be detected; detects whether the product to be detected contains foreign matter based on the target image and the foreign matter detection model to obtain an initial detection result; when the initial detection result is that the product to be detected contains foreign matter, obtains the target area in the target image where the foreign matter image is located; and obtains the final detection result of whether the product to be detected contains foreign matter based on the target grayscale difference of the target area; firstly detects foreign matter through the foreign matter detection model, and then, when the initial detection result is that the product to be detected contains foreign matter, re-judges whether the product to be detected contains foreign matter based on the target grayscale difference of the target area where the foreign matter image is located in the target image. While ensuring the strong adaptability and detection capability of the model detection, the accuracy of whether the product to be detected contains foreign matter is guaranteed through re-inspection, thereby improving the accuracy of foreign matter detection and solving the problem that foreign matter identification completely relies on the result of machine learning and is prone to missed detection and false detection due to the lack of re-inspection process. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 It is a schematic diagram of the process of the foreign body detection method in the embodiment of the present application;

[0020] Figure 2 is a schematic diagram of obtaining a target image of a product to be detected in an embodiment of the present application;

[0021] Figure 3It is a schematic diagram of the step-by-step training of the model in the embodiment of the present application;

[0022] Figure 4 is a schematic diagram of a process for obtaining a first training sample set in an embodiment of the present application;

[0023] Figure 5 is a schematic structural diagram of a foreign body detection device provided in an embodiment of the present application;

[0024] Figure 6 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0026] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0027] The foreign body detection method provided in the embodiment of the present application is described in detail below through specific embodiments and their application scenarios in conjunction with the accompanying drawings.

[0028] Figure 1 A foreign body detection method provided by an embodiment of the present invention is shown. The method can be executed by an electronic device, and the electronic device may include: a server and / or a terminal device. In other words, the method can be executed by software or hardware installed in the electronic device, and the method includes the following steps:

[0029] Step 101: Obtain a target image of the product to be inspected.

[0030] Specifically, when acquiring the target image of the product to be inspected, an X-ray image of the product to be inspected may be acquired, that is, the X-ray image is determined as the target image.

[0031] Specifically, Figure 2As shown, in this embodiment, an X-ray device can be installed at a suitable position above the product conveyor belt, and relevant parameters such as the current and voltage of the X-ray device can be adjusted according to the characteristics of the product to be detected and the degree of absorption of X-rays, and a sensor can be installed below the conveyor belt to detect whether the product to be detected passes through the conveyor belt. In the application process, taking the product to be detected as food as an example, the product to be detected can be placed on the conveyor belt, and the product to be detected moves in the conveying direction of the conveyor belt (the direction of the arrow in the figure), and during the movement, the X-rays emitted by the X-ray device are irradiated on the product to be detected, and an X-ray image of the product to be detected is obtained.

[0032] In addition, it should be noted that the products to be tested can be food, daily necessities, industrial products, etc., and are not specifically limited here.

[0033] Step 102: Based on the target image and the foreign body detection model, detect whether the product to be detected has foreign bodies to obtain an initial detection result.

[0034] Specifically, the present embodiment can pre-train a foreign body detection model, and input the target image into the foreign body detection model to detect whether there are foreign objects in the product to be inspected, and obtain an initial detection result; of course, feature data can also be extracted from the target image first, and the feature data can be input into the foreign body detection model to obtain an initial detection result.

[0035] In addition, the initial detection result may include whether there is a foreign object in the product to be detected. It should be noted that, in this embodiment, a confidence threshold may be pre-set, and the initial detection result is determined by the confidence threshold.

[0036] The foreign body detection model is used to detect whether the product to be inspected has foreign bodies, thereby ensuring the detection efficiency of the product to be inspected.

[0037] Step 103: When the initial detection result is that foreign matter exists in the product to be detected, a target area in the target image where the image of the foreign matter is located is obtained.

[0038] Specifically, since objects of different thicknesses and materials absorb X-rays to different degrees, the grayscale of the image of the part of the product mixed with foreign matter is usually different from that of the normal part. Therefore, when the initial test result shows that there is foreign matter in the product to be tested, the target area where the foreign matter image is located in the target image can be obtained to provide a basis for the final result of the subsequent judgment of whether there is foreign matter in the product to be tested.

[0039] In addition, specifically, after the target image of the product to be inspected passes through the foreign body detection model, a confidence matrix can be obtained, and the foreign body pixels can be identified through the confidence threshold. At this time, the connected domain of the identified foreign body pixels can be found, and the area corresponding to the connected domain in the target image, that is, the target area, can be found.

[0040] Step 104: Obtain a final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area.

[0041] Specifically, in this step, the final detection result of whether the product to be inspected contains foreign matter can be obtained according to the target grayscale difference of the target area, that is, the product to be inspected is detected again to determine whether foreign matter exists, thereby realizing the re-detection process of whether the product to be inspected contains foreign matter and improving the detection accuracy.

[0042] In this way, this embodiment first uses the foreign matter detection model to detect whether there are foreign matters in the product to be detected, and then, when the initial detection result is that there are foreign matters in the product to be detected, the initial detection result is re-judged through the target grayscale difference of the target area where the foreign matter image is located in the target image. While ensuring the strong adaptability and detection capability of the model detection, the accuracy of foreign matter detection is improved, and the problem of foreign matter identification relying entirely on the results of machine learning and the lack of a re-inspection process that easily leads to missed detections and false detections is solved.

[0043] In addition, before detecting whether the product to be detected has foreign matter based on the target image and the foreign matter detection model and obtaining the initial detection result, it is necessary to train the foreign matter detection model. Specifically, in one embodiment, the following steps may be included:

[0044] A first training sample set is obtained, wherein the first training sample set includes a first image sample of the product to be detected and a label indicating whether the first image sample includes a foreign body image; a preset image detection model is trained using the first training sample set to obtain the foreign body detection model.

[0045] Specifically, in this embodiment, an image detection model may be pre-set, and then the image detection model may be trained using a first training sample set, thereby obtaining a foreign body detection model.

[0046] It should be noted that the image detection model can identify the content in the picture.

[0047] In addition, since the first training sample set includes the first picture sample of the product to be inspected, after the image detection model is trained with the first training sample set, the obtained foreign body detection model has high-precision detection capabilities for the product to be inspected and can accurately identify foreign bodies, thereby ensuring the detection accuracy of the foreign body detection model.

[0048] In addition, in one embodiment, before the preset image detection model is trained by the first training sample set to obtain the foreign body detection model, it is necessary to determine the image detection model; at this time, in one embodiment, the following steps may be included:

[0049] Acquire an image recognition model and a second training sample set, wherein the second training sample set includes a second picture sample of a similar object and a label of whether the second picture sample includes an image of a foreign object, and the similar object is a product whose similarity to the product to be detected is greater than a preset value;

[0050] The image recognition model is trained using the second training sample set to obtain the image detection model.

[0051] Specifically, the image recognition model can recognize the content in the image. It should be noted that the image recognition model can be a conventional supervised convolutional neural network model, and can be obtained by training with unclassified image data, which can include, for example, face images, vehicle images, etc. In this way, the image recognition model is obtained by training with unclassified image data, which expands the scope of the training data and enables the image recognition model to have the ability to recognize the content in the image. Of course, the image recognition model can also be an existing model, which is not specifically limited here.

[0052] In addition, specifically, the second training sample set includes second picture samples of similar objects and labels of whether the second picture samples include images of foreign objects. Similar objects are products whose similarity to the product to be detected is greater than a preset value. Since there are many categories of products similar to the product to be detected and this part of the picture samples is public data, the number of second picture samples in the second training sample set is guaranteed, and the source range of the second picture samples is expanded.

[0053] The image recognition model is trained by the second training sample set to obtain the image detection model, thereby optimizing the image recognition model through training samples related to the product to be detected, so that the trained image detection model has foreign body detection capability and can be used for rough foreign body recognition.

[0054] In this way, Figure 3As shown, this embodiment firstly optimizes the image recognition model through training samples related to the product to be detected based on the image recognition model to obtain the image detection model, and then trains the image detection model through a first training sample set including a first picture sample of the product to be detected to obtain a foreign body detection model, which realizes that through multi-level model tuning and the combination of public data and picture sample data of the product to be detected, the model capacity can be fully utilized and the model learning ability can be brought into play, so that a small-scale network model can also have high-precision foreign body recognition capabilities, while reducing computing resources and time consumption, and ensuring the foreign body detection performance of the foreign body detection model. In addition, through the multi-level model tuning strategy, only a small amount of good product picture data is required to obtain a model with high recognition accuracy, which is beneficial to the model in actual production, reducing the deployment time, thereby reducing the loss caused by the stagnation of the product production line during the training process.

[0055] In addition, in one embodiment, Figure 4 As shown, when obtaining the first training sample set, the following steps may be included:

[0056] Step 401: Acquire a target foreign object image from a preset foreign object library.

[0057] Specifically, in this embodiment, a foreign body library may be pre-built, and the foreign body library includes a variety of foreign body images. For example, as an example, the foreign body image may include metal balls, debris, etc., which is not specifically limited here.

[0058] In addition, specifically, the foreign body images in the foreign body library can be collected and accumulated by X-ray equipment.

[0059] It should be noted that this step occurs in each network training iteration, and the type and quantity of foreign matter selected in each network training process may be different.

[0060] Step 402: Obtain a first good product image from a preset good product library of products to be inspected.

[0061] Specifically, the good product library is provided with good product pictures of the products to be inspected, wherein the good product pictures in the good product library are pictures that do not include foreign body images.

[0062] It should be noted that the good product image can also be obtained and collected through X-ray equipment.

[0063] In addition, this step occurs in each network training iteration, and the first good product image selected during each network training process can be different. The first good product image can be used to generate foreign body image samples.

[0064] Step 403: Fusing the target foreign body image and the first good product image to obtain a foreign body image sample.

[0065] Specifically, by fusing the target foreign body image and the first good product image to obtain a foreign body image sample, the label of the foreign body image sample is that the foreign body image is included in the foreign body image sample, thereby realizing the fusion generation of the foreign body image sample. In this way, by fusion generation close to the real sample data, the unsupervised problem is converted into a supervised problem, and the model detection accuracy is guaranteed. In addition, since the foreign body image sample is generated by fusion, the proportion of foreign body image samples in the training data can be controlled by adjusting the probability of generating foreign body image samples, thereby solving the problem of unbalanced sample categories.

[0066] In one embodiment, in order to ensure the diversity of foreign objects, when the target foreign object image and the first good product image are fused to obtain a foreign object image sample, the part of the target foreign object image except the background can be randomly transformed, and the random transformation includes shape transformation and / or grayscale transformation; the randomly transformed target foreign object image and the first good product image are fused to obtain a foreign object image sample.

[0067] Specifically, the shape transformation may include transformations such as flipping, rotation, scaling, and cropping, and the grayscale transformation may include transformations such as linear transformation, filtering transformation, and noise transformation. In addition, this embodiment only performs random transformations on the target foreign body image except for the background, that is, the random transformation is only effective for foreign bodies and does not transform the background, thereby ensuring the learnability of the background and the diversity of foreign bodies during the training process, thereby ensuring the generalization ability of the model.

[0068] In addition, it should be noted that in each network training iteration, the part of the target foreign object image except the background can be randomly transformed, and the specific transformation method and transformation parameters of each iteration can be different, thereby ensuring the diversity of foreign objects.

[0069] In addition, in one embodiment, when the target foreign body image and the first good product image are fused to obtain a foreign body image sample, the following steps may be included:

[0070] The target foreign body image and the first good product image are fused by the following formula to obtain a foreign body image sample;

[0071] P=G1÷M×G2×a;wherein,

[0072] P represents the data corresponding to the foreign body image sample, G1 represents the grayscale value of each pixel in the target foreign body image, G2 represents the grayscale value of each pixel at the fitting position of the target foreign body image in the first good product image, M represents the maximum pixel value of the preset pixel interval, and a represents the preset coefficient.

[0073] It should be noted that the pixel value in the preset pixel interval may be a value assigned by a computer. For example, image processing software usually uses 8 bits to represent a pixel, so the preset pixel interval is 0 to 255. At this time, M represents the maximum pixel value in the preset pixel interval, that is, the value of M is 255. In addition, the preset coefficient may be an attenuation coefficient, which may vary according to changes in the current environment.

[0074] In this way, through the above nonlinear fusion method, the authenticity of the foreign body image samples obtained by fusion is made higher, thereby ensuring the authenticity of the foreign body image samples.

[0075] Step 404: Determine the foreign body image sample and the second good product image as the first image samples to obtain the first training sample set.

[0076] The second good product picture includes at least part of the pictures in the good product library except the first good product picture.

[0077] In this way, the generated foreign body sample images and at least part of the images in the good product library except the first good product image together constitute the first training sample set, so that the accuracy of network training can be guaranteed when the network is trained through the first training sample set.

[0078] In addition, specifically, during the foreign body detection process, if the foreign body detection model identifies a foreign body from the data, the product corresponding to the data is judged as a product with foreign bodies; otherwise, the product to be detected is judged as a good product, that is, a product without foreign bodies. Although the foreign body detection model has a high foreign body recognition accuracy in most scenarios, in order to further improve the foreign body recognition accuracy and solve the problem of missed detection or too many false detections in a very small number of scenarios, this embodiment can judge the initial detection results again.

[0079] Since objects of different thicknesses and materials have different degrees of absorption of X-rays, the grayscale of the image of the part mixed with foreign matter in the product is usually different from the grayscale of the normal part. Therefore, this embodiment can use the grayscale difference parameter to determine whether there is foreign matter in the product to be inspected, thereby realizing the re-inspection process of foreign matter.

[0080] Specifically, in one embodiment, according to the target grayscale difference of the target area, the target grayscale difference needs to be determined before determining the final detection result of whether the product to be inspected contains foreign matter. The process may include the following steps:

[0081] Arrange the grayscale of the target area in order and divide it into three segments, and obtain a first average grayscale value of a middle segment of the three segments;

[0082] Extending the edge of the target area outward by a preset number of pixels to obtain an extended area, and acquiring a second average grayscale value of the extended area;

[0083] The absolute value of the difference between the second average grayscale value and the first average grayscale value is determined as the target grayscale difference.

[0084] Specifically, in this embodiment, the grayscale of the target area can be arranged in order and divided into three segments, wherein the three segments can be obtained by average division, or the difference in the number of grayscale values ​​in the three segments can be controlled within a certain range. In addition, by obtaining the first average grayscale value of the middle segment among the three segments, the influence of the edge being too light and the internal being too dark is eliminated.

[0085] In addition, the expansion area is obtained by expanding the edge of the target area outward by a preset number of pixels, thereby achieving expansion of the target area through a dilation operation.

[0086] By determining the absolute value of the difference between the second average grayscale value and the first average grayscale value of the extended area as the target grayscale difference, the validity of the target grayscale difference is ensured.

[0087] In addition, in one embodiment, when obtaining the final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area, the following situations may be included:

[0088] First, when the target grayscale difference is greater than or equal to a preset maximum grayscale difference, determining that the final detection result is that foreign matter exists in the product to be detected.

[0089] Specifically, if the target grayscale difference is greater than or equal to the preset maximum grayscale difference, it is considered that there is a foreign object in the target area, and the foreign object confidence can be set to the highest. At this time, the final detection result can be determined as the presence of foreign objects in the product to be detected, that is, the initial detection result is maintained unchanged.

[0090] Second, when the target grayscale difference is less than or equal to a preset minimum grayscale difference, the final detection result is determined to be that no foreign matter exists in the product to be detected.

[0091] Specifically, if the target grayscale difference is less than or equal to the preset minimum grayscale difference, it is considered that there is no foreign matter in the target area, and the foreign matter confidence can be set to the lowest. At this time, the final detection result can be determined as no foreign matter exists in the product to be detected.

[0092] It should be noted that the preset maximum grayscale difference is greater than the preset minimum grayscale difference. Of course, the preset minimum grayscale difference is greater than 0, and the preset maximum grayscale difference is less than 255.

[0093] It should be noted that if the preset maximum grayscale difference is 255 and the preset minimum grayscale difference is 0, it is considered that there is no need to determine the final detection result, that is, the initial detection result is directly used.

[0094] Third: When the target grayscale difference is less than the preset maximum grayscale difference and greater than the preset minimum grayscale difference, the final detection result of whether there are foreign objects in the product to be detected is determined based on the initial detection result and the area of ​​the target area.

[0095] Specifically, when the target grayscale difference is between the preset maximum grayscale difference and the preset minimum grayscale difference, the target area can be considered to be questionable. At this time, the confidence result corresponding to the initial detection result is retained, and the final detection result of whether there are foreign objects in the product to be inspected is determined based on the initial detection result and the area of ​​the target area.

[0096] In one embodiment, when determining the final detection result of whether the product to be detected contains foreign matter according to the initial detection result and the area of ​​the target area, the following steps may be included:

[0097] When the foreign matter confidence corresponding to the initial detection result is greater than a preset confidence threshold, and the area of ​​the region is greater than a preset area threshold, it is determined that foreign matter exists in the product to be detected;

[0098] When the foreign matter confidence corresponding to the initial detection result is less than or equal to a preset confidence threshold, and / or the area of ​​the region is less than or equal to a preset area threshold, it is determined that no foreign matter exists in the product to be detected.

[0099] Specifically, if the foreign matter confidence is greater than the preset confidence threshold, and the area of ​​the target area is greater than the preset area threshold, it is determined that there is foreign matter in the product to be inspected, that is, the final detection result is the same as the initial detection result; otherwise, it is determined that there is no foreign matter in the product to be inspected, and the final detection result is different from the initial detection result.

[0100] In this way, this embodiment realizes the re-detection process of whether there are foreign objects in the product to be detected through the above method, and this detection method is different from the foreign object detection model detection method, which avoids confusion between the initial detection results and the final detection results, and ensures the detection efficiency while ensuring the detection accuracy.

[0101] like Figure 2 As shown, this embodiment provides a foreign body detection system, which includes an X-ray device, a conveyor belt and a sensor;

[0102] The conveyor belt is used to convey the product to be inspected;

[0103] The sensor is arranged at the bottom of the conveyor belt, and is used to detect whether the product to be detected passes through the conveyor belt;

[0104] The X-ray device is arranged above the conveyor belt, and is used to emit X-rays to a preset area of ​​the conveyor belt, and obtain a target image of the product to be inspected when the X-rays are irradiated onto the product to be inspected;

[0105] The X-ray device is provided with a processor, which is used to detect whether there is a foreign object in the product to be inspected according to the target image and the foreign object detection model to obtain an initial detection result; when the initial detection result is that there is a foreign object in the product to be inspected, obtain the target area where the foreign object image in the target image is located in the target image; and obtain the final detection result of whether there is a foreign object in the product to be inspected according to the target grayscale difference of the target area.

[0106] Specifically, in this embodiment, an X-ray device can be installed at a suitable position above the conveyor belt, and relevant parameters such as the current and voltage of the X-ray device can be adjusted according to the absorption degree of the product to be inspected to the X-ray, and a sensor can be installed below the conveyor belt to detect whether the product to be inspected passes through the conveyor belt. In this way, the product to be inspected is placed on the conveyor belt, and the product to be inspected moves in the conveying direction of the conveyor belt (the direction of the arrow in the figure) as the object moving direction, and during the movement, when the X-rays emitted by the X-ray device irradiate the product to be inspected, the X-ray device obtains an X-ray image of the product to be inspected.

[0107] In addition, a processor is provided in the X-ray device, and the processor can execute the various processes and beneficial effects of the above-mentioned foreign body detection method embodiment, which will not be described again here to avoid repetition.

[0108] Figure 5 A foreign body detection device provided by an embodiment of the present invention is shown, and the device includes:

[0109] The first acquisition module 501 is used to acquire a target image of the product to be detected;

[0110] The first detection module 502 is used to detect whether the product to be detected has foreign matter according to the target image and the foreign matter detection model, and obtain an initial detection result;

[0111] The second acquisition module 503 is used to acquire the target area where the image of the foreign object in the target image is located in the target image when the initial detection result is that the product to be detected has foreign matter;

[0112] The second detection module 504 is used to obtain a final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area.

[0113] In one embodiment, the second detection module 504 is used to determine that the final detection result is that foreign matter exists in the product to be detected when the target grayscale difference is greater than or equal to the preset maximum grayscale difference; to determine that the final detection result is that no foreign matter exists in the product to be detected when the target grayscale difference is less than or equal to the preset minimum grayscale difference; and to determine the final detection result of whether foreign matter exists in the product to be detected based on the initial detection result and the area area of ​​the target area when the target grayscale difference is less than the preset maximum grayscale difference and greater than the preset minimum grayscale difference; wherein the preset maximum grayscale difference is greater than the preset minimum grayscale difference.

[0114] In one embodiment, the second detection module 504 is used to determine that there are foreign objects in the product to be detected when the foreign object confidence corresponding to the initial detection result is greater than a preset confidence threshold and the area of ​​the region is greater than a preset area threshold; and to determine that there are no foreign objects in the product to be detected when the foreign object confidence corresponding to the initial detection result is less than or equal to the preset confidence threshold and / or the area of ​​the region is less than or equal to the preset area threshold.

[0115] The foreign body detection device provided in the embodiment of the present application can achieve Figure 1-4 To avoid repetition, the various processes implemented by the method embodiment are not described here.

[0116] It should be noted that the embodiments of the foreign object detection device in this specification and the embodiments of the foreign object detection method in this specification are based on the same inventive concept. Therefore, the specific implementation of the embodiments of the foreign object detection device can refer to the implementation of the aforementioned corresponding embodiments of the foreign object detection method, and the repeated parts will not be repeated.

[0117] The foreign body detection device in the embodiment of the present application can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0118] The foreign body detection device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0119] Based on the same technical concept, an embodiment of the present application further provides an electronic device, which is used to execute the above-mentioned foreign body detection method. Figure 6 A schematic diagram of the structure of an electronic device for implementing various embodiments of the present application. The electronic device may have relatively large differences due to different configurations or performances, and may include a processor (processor) 610, a communication interface (Communications Interface) 620, a memory (memory) 630 and a communication bus 640, wherein the processor 610, the communication interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call a computer program stored in the memory 630 and executable on the processor 610 to perform the following steps:

[0120] Get the target image of the product to be inspected;

[0121] According to the target image and the foreign body detection model, detecting whether the product to be detected has foreign bodies, and obtaining an initial detection result;

[0122] When the initial detection result is that foreign matter exists in the product to be detected, obtaining a target area in the target image where an image of the foreign matter is located in the target image;

[0123] A final detection result of whether the product to be detected has foreign matter is obtained according to the target grayscale difference of the target area.

[0124] In one embodiment, the method further includes: obtaining a first training sample set, wherein the first training sample set includes a first image sample of the product to be detected and a label of whether the first image sample includes a foreign object image; and training a pre-set image detection model through the first training sample set to obtain the foreign object detection model.

[0125] In one embodiment, before the preset image detection model is trained by the first training sample set to obtain the foreign object detection model, it also includes: acquiring an image recognition model and a second training sample set, wherein the second training sample set includes a second picture sample of a similar object and a label of whether the second picture sample includes a foreign object image, and the similar object is a product whose similarity with the product to be detected is greater than a preset value; training the image recognition model by the second training sample set to obtain the image detection model.

[0126] In one embodiment, obtaining the first training sample set includes: obtaining a target foreign object image from a preset foreign object library, wherein the foreign object library includes a plurality of foreign object images; obtaining a first good product picture from a preset good product library of products to be inspected, wherein the good product pictures in the good product library are pictures that do not include foreign object images; fusing the target foreign object image and the first good product picture to obtain a foreign object picture sample, the label of the foreign object picture sample being that the foreign object picture sample includes a foreign object image; determining the foreign object picture sample and a second good product picture as the first picture sample to obtain the first training sample set, wherein the second good product picture includes at least part of the pictures in the good product library except the first good product picture.

[0127] In one embodiment, the fusion of the target foreign object image and the first good product image to obtain a foreign object image sample includes: randomly transforming the portion of the target foreign object image excluding the background, wherein the random transformation includes a shape transformation and / or a grayscale transformation; and fusing the randomly transformed target foreign object image and the first good product image to obtain a foreign object image sample.

[0128] In one embodiment, the step of fusing the target foreign body image and the first good product image to obtain a foreign body image sample includes: fusing the target foreign body image and the first good product image to obtain a foreign body image sample according to the following formula: P = 1 ÷ M × G2 × a; wherein,

[0129] P represents the data corresponding to the foreign body image sample, G1 represents the grayscale value of each pixel in the target foreign body image, G2 represents the grayscale value of each pixel at the fitting position of the target foreign body image in the first good product image, M represents the maximum pixel value of the preset pixel interval, and a represents the preset coefficient.

[0130] In one embodiment, before obtaining the final detection result of whether the product to be inspected contains foreign matter based on the target grayscale difference of the target area, the method further includes: arranging the grayscale of the target area in order and dividing it into three segments, and obtaining the first average grayscale value of the middle segment of the three segments; expanding the edge of the target area outward by a preset number of pixels to obtain an extended area, and obtaining the second average grayscale value of the extended area; and determining the absolute value of the difference between the second average grayscale value and the first average grayscale value as the target grayscale difference.

[0131] In one embodiment, the final detection result of whether the product to be inspected has foreign matter is obtained based on the target grayscale difference of the target area, including: when the target grayscale difference is greater than or equal to a preset maximum grayscale difference, determining that the final detection result is that the product to be inspected has foreign matter; when the target grayscale difference is less than or equal to a preset minimum grayscale difference, determining that the final detection result is that the product to be inspected does not have foreign matter; when the target grayscale difference is less than the preset maximum grayscale difference and greater than the preset minimum grayscale difference, determining the final detection result of whether the product to be inspected has foreign matter based on the initial detection result and the area area of ​​the target area; wherein the preset maximum grayscale difference is greater than the preset minimum grayscale difference.

[0132] In one embodiment, the final detection result of whether the product to be inspected has foreign matter is determined based on the initial detection result and the area of ​​the target area, including: when the foreign matter confidence corresponding to the initial detection result is greater than a preset confidence threshold, and the area of ​​the target area is greater than a preset area threshold, determining that the product to be inspected has foreign matter; when the foreign matter confidence corresponding to the initial detection result is less than or equal to the preset confidence threshold, and / or the area of ​​the target area is less than or equal to the preset area threshold, determining that the product to be inspected does not have foreign matter.

[0133] The specific execution steps can refer to the various steps of the above-mentioned foreign body detection method embodiment, and can achieve the same technical effect. To avoid repetition, they will not be repeated here.

[0134] It should be noted that the electronic devices in the embodiments of the present application include: servers, terminals, or other devices except terminals.

[0135] The above electronic device structure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. For example, the input unit may include a graphics processing unit (GPU) and a microphone, and the display unit may be configured with a display panel in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit includes a touch panel and at least one of other input devices. The touch panel is also called a touch screen. Other input devices may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a mouse, and a joystick, which will not be repeated here.

[0136] The memory can be used to store software programs and various data. The memory may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory may include a volatile memory or a non-volatile memory, or the memory may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct memory bus random access memory (DRRAM).

[0137] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to the operating system, user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor.

[0138] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned foreign body detection method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0139] The processor is a processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0140] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0141] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0142] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

Claims

1. A foreign body detection method, characterized in that: include: Get the target image of the product to be inspected; According to the target image and the foreign body detection model, detecting whether the product to be detected has foreign bodies, and obtaining an initial detection result; When the initial detection result is that foreign matter exists in the product to be detected, obtaining a target area in the target image where an image of the foreign matter is located in the target image; A final detection result of whether the product to be detected has foreign matter is obtained according to the target grayscale difference of the target area.

2. The foreign body detection method according to claim 1, characterized in that: Before the detection of whether the product to be detected has foreign matter based on the target image and the foreign matter detection model and obtaining the initial detection result, the method further includes: Acquire a first training sample set, wherein the first training sample set includes a first image sample of the product to be detected and a label indicating whether the first image sample includes a foreign body image; The foreign body detection model is obtained by training a preset image detection model using the first training sample set.

3. The foreign body detection method according to claim 2, characterized in that: Before the preset image detection model is trained by the first training sample set to obtain the foreign body detection model, the method further includes: Acquire an image recognition model and a second training sample set, wherein the second training sample set includes a second picture sample of a similar object and a label of whether the second picture sample includes an image of a foreign object, and the similar object is a product whose similarity to the product to be detected is greater than a preset value; The image recognition model is trained using the second training sample set to obtain the image detection model.

4. The foreign body detection method according to claim 2, characterized in that: The obtaining of the first training sample set comprises: Acquire a target foreign body image from a preset foreign body library, wherein the foreign body library includes a plurality of foreign body images; Acquire a first good product image from a preset good product library of the product to be inspected, wherein the good product image in the good product library is an image that does not include an image of a foreign object; The target foreign body image and the first good product image are merged to obtain a foreign body image sample, wherein the label of the foreign body image sample is that the foreign body image sample includes the foreign body image; The foreign body picture sample and the second good product picture are determined as the first picture samples to obtain the first training sample set, and the second good product picture includes at least part of the pictures in the good product library except the first good product picture.

5. The foreign body detection method according to claim 4, characterized in that: The step of fusing the target foreign body image and the first good product image to obtain a foreign body image sample includes: Performing random transformation on the part of the target foreign body image except the background, wherein the random transformation includes shape transformation and / or grayscale transformation; The randomly transformed target foreign body image and the first good product image are fused to obtain a foreign body image sample.

6. The foreign body detection method according to claim 4, characterized in that: The step of fusing the target foreign body image and the first good product image to obtain a foreign body image sample includes: The target foreign body image and the first good product image are fused by the following formula to obtain a foreign body image sample; P=G1÷M×G2×a;wherein, P represents the data corresponding to the foreign body image sample, G1 represents the grayscale value of each pixel in the target foreign body image, G2 represents the grayscale value of each pixel at the fitting position of the target foreign body image in the first good product image, M represents the maximum pixel value of the preset pixel interval, and a represents the preset coefficient.

7. The foreign matter detection method according to claim 1, characterized in that: Before obtaining the final detection result of whether the product to be detected contains foreign matter according to the target grayscale difference of the target area, the method further includes: Arrange the grayscale of the target area in order and divide it into three segments, and obtain a first average grayscale value of a middle segment of the three segments; Extending the edge of the target area outward by a preset number of pixels to obtain an extended area, and acquiring a second average grayscale value of the extended area; The absolute value of the difference between the second average grayscale value and the first average grayscale value is determined as the target grayscale difference.

8. The foreign matter detection method according to claim 1, characterized in that: The step of obtaining a final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area includes: When the target grayscale difference is greater than or equal to a preset maximum grayscale difference, determining that the final detection result is that foreign matter exists in the product to be detected; When the target grayscale difference is less than or equal to a preset minimum grayscale difference, determining that the final detection result is that there is no foreign matter in the product to be detected; When the target grayscale difference is less than the preset maximum grayscale difference and greater than the preset minimum grayscale difference, determining a final detection result of whether the product to be detected contains foreign matter according to the initial detection result and the area of ​​the target area; Wherein, the preset maximum grayscale difference is greater than the preset minimum grayscale difference.

9. The foreign matter detection method according to claim 8, characterized in that: The final detection result of whether the product to be detected has foreign matter is determined according to the initial detection result and the area of ​​the target area, including: When the foreign matter confidence corresponding to the initial detection result is greater than a preset confidence threshold, and the area of ​​the region is greater than a preset area threshold, it is determined that foreign matter exists in the product to be detected; When the foreign matter confidence corresponding to the initial detection result is less than or equal to a preset confidence threshold, and / or the area of ​​the region is less than or equal to a preset area threshold, it is determined that no foreign matter exists in the product to be detected.

10. A foreign body detection device, characterized in that: include: The first acquisition module is used to acquire a target image of the product to be inspected; A first detection module, configured to detect whether the product to be detected has foreign matter based on the target image and the foreign matter detection model, and obtain an initial detection result; A second acquisition module is used to acquire a target area where an image of a foreign object in the target image is located in the target image when the initial detection result is that a foreign object exists in the product to be detected; The second detection module is used to obtain a final detection result of whether the product to be detected has foreign matter according to the target grayscale difference of the target area.

11. A foreign body detection system, characterized in that: Includes X-ray equipment, conveyor belts and sensors; The conveyor belt is used to convey the product to be inspected; The sensor is arranged at the bottom of the conveyor belt, and is used to detect whether the product to be detected passes through the conveyor belt; The X-ray device is arranged above the conveyor belt, and is used to emit X-rays to a preset area of ​​the conveyor belt, and obtain a target image of the product to be inspected when the X-rays are irradiated onto the product to be inspected; The X-ray device is provided with a processor, which is used to detect whether there is a foreign object in the product to be inspected according to the target image and the foreign object detection model to obtain an initial detection result; when the initial detection result is that there is a foreign object in the product to be inspected, obtain the target area where the foreign object image in the target image is located in the target image; and obtain the final detection result of whether there is a foreign object in the product to be inspected according to the target grayscale difference of the target area.

12. An electronic device, characterized in that: It includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the foreign body detection method according to any one of claims 1 to 9.

13. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by the processor, the steps of the foreign matter detection method according to any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Lithium battery coating defect detection method, system and device and storage medium

    CN109613000A

  • Intelligent visual detection system of foreign matters and bubbles in liquid based on deep learning algorithm

    CN110687132A

  • Container defect detection method and device

    CN111709948A

  • Transfer learning method for classification based on one-dimensional periodic signals

    CN115099279A