A method for detecting foreign matter in an image

The image foreign object detection method through end-to-end training uses Faster R-CNN and RPN networks for feature extraction and fusion, which solves the problems of long time-consuming and low sensitivity of manual feature extraction in the existing technology, and achieves high accuracy and short detection time. Time-based foreign object recognition, especially in small target detection.

CN113989600BActive Publication Date: 2024-09-06SHANGHAI NORMAL UNIVERSITY
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202111140361.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-28
Publication Date
2024-09-06
Estimated Expiration
2041-09-28

Smart Images

  • Figure CN113989600B
    Figure CN113989600B
Patent Text Reader

Abstract

The present invention discloses a method, device and electronic device for detecting foreign bodies in images, wherein the method comprises the following steps: obtaining an image to be detected, and preprocessing the image to be detected in the spatial domain and the frequency domain respectively, annotating the preprocessed image and using it as a data set for a deep learning network; sending the data set to the feature extraction network of Faster R‑CNN to obtain a corresponding feature map; sending the generated feature map to the RPN network after adjusting the anchor point size and scale to generate a corresponding candidate area; mapping the candidate area to the last two layers of the feature extraction network and performing feature fusion, and inputting the feature fused vector into the fully connected layer to realize classification and regression. A method for detecting foreign bodies in images of the present invention abandons the manual feature extraction process, realizes end-to-end training, can accurately identify foreign bodies, has high accuracy, short detection time, strong anti-interference, retains more information in the feature fusion process, and has good small target detection effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and in particular to a method for detecting foreign matter in an image. Background Art

[0002] With the development of artificial intelligence technology, foreign body detection technology based on deep learning is widely used in industrial and food inspection fields. At present, many images have the characteristics of high noise, low contrast, and complex background, while foreign body targets account for a very low proportion of the entire image and there are problems such as occlusion. Most companies' foreign body detection instruments are based on traditional detection technology, manually extracting image features according to the characteristics of different data, and sending them to classifiers for detection. The detection sensitivity is low, the detection ability is poor, and there are problems such as missed detection and repeated detection. Summary of the invention

[0003] In view of the above-mentioned defects of the prior art, the technical problem to be solved by the present invention is that the existing image foreign body recognition requires a lot of time to manually extract image features of different foreign bodies, which has high labor and time costs, and the traditional detection technology takes a long time, has low sensitivity, and is difficult to distinguish foreign bodies, which easily leads to missed detection, false detection, etc., affecting the detection accuracy and precision measurement quality. The present invention provides an image foreign body detection method, which abandons the manual feature extraction process, realizes end-to-end training, can accurately identify foreign bodies, has high accuracy, short detection time, strong anti-interference, retains more information in the feature fusion process, and has good small target detection effect.

[0004] To achieve the above object, the present invention provides an image foreign body detection method, comprising the following steps:

[0005] Acquire an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, annotate the preprocessed image and use it as a data set for a deep learning network;

[0006] Send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map;

[0007] The generated feature map is sent to the RPN network after adjusting the anchor size and scale to generate the corresponding candidate region;

[0008] Map the candidate regions to the last two layers of the feature extraction network and perform feature fusion;

[0009] The feature fusion vector is input into the fully connected layer to achieve classification and regression.

[0010] Furthermore, an image to be detected is obtained, and the image to be detected is preprocessed in the spatial domain and the frequency domain respectively, and the preprocessed image is annotated and used as a data set of a deep learning network, specifically including:

[0011] The image to be detected is first enhanced by using a nonlinear grayscale transformation enhancement method;

[0012] Then the high frequency part is enhanced in the enhanced image;

[0013] Finally, the twice enhanced images are subjected to data enhancement through flipping, brightness enhancement, translation, splicing and other methods, and the obtained images are marked and used as data sets.

[0014] Furthermore, the dataset is sent to the feature extraction network of Faster R-CNN to obtain the corresponding feature map, which specifically includes:

[0015] The feature extraction network is ResNet-50, which is responsible for extracting the feature map corresponding to the image, and then using the extracted feature map as the input of the RPN network; the RPN network is responsible for generating region proposal boxes and performing bounding box regression to obtain the corresponding feature matrix, and finally each feature matrix is ​​uniformly scaled to a fixed size through the ROI pooling layer and passed to the classification regression network.

[0016] Furthermore, the generated feature map is sent to the RPN network after adjusting the anchor point size and scale to generate the corresponding candidate region, specifically:

[0017] The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network has three ratios {1:1, 1:2, 2:1}. Each anchor point generates 15 corresponding candidate regions in the original image.

[0018] Another preferred embodiment of the present invention provides an image foreign body detection device, comprising the following modules:

[0019] A preprocessing module is used to obtain an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, and annotate the preprocessed image and use it as a data set for a deep learning network;

[0020] The feature extraction module is used to send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map;

[0021] The generation module is used to send the generated feature map to the RPN network after adjusting the anchor point size and scale to generate the corresponding candidate region;

[0022] The fusion module is used to map the candidate regions to the last two layers of the feature extraction network and perform feature fusion.

[0023] The input module is used to input the feature fusion vector into the fully connected layer to achieve classification and regression.

[0024] Furthermore, the preprocessing module specifically includes:

[0025] A first enhancement unit is used to enhance the image to be detected by using a nonlinear grayscale transformation enhancement method;

[0026] A second enhancement unit is used to enhance the high frequency part in the image after further enhancement;

[0027] The third enhancement unit is used to perform data enhancement on the twice enhanced image by flipping, brightness enhancement, translation, splicing and other methods, and mark the obtained image as a data set.

[0028] Furthermore, the feature extraction module specifically includes:

[0029] The feature extraction unit uses a ResNet-50 network to extract the feature map corresponding to the image, and then uses the extracted feature map as the input of the RPN network.

[0030] The regression unit is used in the RPN network to generate region proposal boxes and perform bounding box regression to obtain the corresponding feature matrix. Finally, each feature matrix is ​​uniformly scaled to a fixed size through the ROI pooling layer and then passed to the classification regression network.

[0031] Furthermore, the generation module is specifically:

[0032] The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network has three ratios {1:1, 1:2, 2:1}. Each anchor point generates 15 corresponding candidate regions in the original image.

[0033] Another preferred embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in any one of the above is implemented.

[0034] Another preferred embodiment of the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to implement an image foreign body detection method as described in any one of the above when executed.

[0035] Technical Effects

[0036] The image foreign body detection method of the present invention abandons the manual feature extraction process, realizes end-to-end training, can accurately identify foreign bodies, has high accuracy, short detection time, strong anti-interference ability, retains more information in the feature fusion process, and has better small target detection effect.

[0037] The concept, specific structure and technical effects of the present invention will be further described below in conjunction with the accompanying drawings to fully understand the purpose, characteristics and effects of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a system framework schematic diagram of an image foreign body detection method according to a preferred embodiment of the present invention;

[0039] Figure 2 It is a schematic diagram of an image to be detected in a method for detecting foreign matter in an image according to a preferred embodiment of the present invention;

[0040] Figure 3 It is a schematic diagram of an enhanced result of an image to be detected in a method for detecting foreign matter in an image according to a preferred embodiment of the present invention;

[0041] Figure 4 It is a schematic diagram of the preprocessing result of an image to be detected of a method for detecting foreign matter in an image according to a preferred embodiment of the present invention;

[0042] Figure 5 It is a schematic diagram of the network structure of a Faster R-CNN algorithm of an image foreign body detection method according to a preferred embodiment of the present invention;

[0043] Figure 6 It is a schematic diagram of sending the generated feature map to the RPN network after adjusting the size and scale of the anchor point in a method for detecting foreign matter in an image according to a preferred embodiment of the present invention;

[0044] Figure 7 It is a schematic diagram of mapping the candidate area to the last two layers of the feature extraction network and performing feature fusion in an image foreign body detection method of a preferred embodiment of the present invention;

[0045] Figure 8 It is a schematic diagram of detection results of an image foreign body detection method according to a preferred embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.

[0047] In the following description, specific details such as specific internal procedures and techniques are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.

[0048] Embodiment 1

[0049] like Figure 1 As shown, an embodiment of the present invention provides an image foreign body detection method, comprising the following steps:

[0050] First, obtain an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, annotate the preprocessed image and use it as a data set for the deep learning network;

[0051] Second, send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map;

[0052] Third, the generated feature map is sent to the RPN network after adjusting the anchor point size and scale to generate the corresponding candidate region;

[0053] Fourth, map the candidate regions to the last two layers of the feature extraction network and perform feature fusion;

[0054] Fifth, the feature fused vector is input into the fully connected layer to achieve classification and regression.

[0055] Specifically, a specific example is given below to illustrate the steps of the present invention.

[0056] First, the image to be detected is preprocessed before foreign body recognition, and the image is enhanced by combining the spatial domain with the frequency domain. Figure 2 shown.

[0057] First, the original image is enhanced by a nonlinear grayscale transformation method, namely a logarithmic transformation enhancement method. The enhancement result is as follows: Figure 3 As shown:

[0058]

[0059] In the above formula, g(x,y) is the grayscale pixel value after transformation, G b , G a are the upper and lower limits of the grayscale range after transformation, F b , F a are the maximum and minimum values ​​of the grayscale distribution before transformation.

[0060] Then, the high-frequency part of the logarithmic enhanced image is enhanced, and the processing result is as follows: Figure 4 As shown;

[0061] Finally, the processed foreign body images are enhanced by flipping, brightness enhancement, translation, splicing and other methods, and the obtained images are marked and used as data sets;

[0062] Second, send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map.

[0063] Among them, the network structure of the Faster R-CNN algorithm is as follows Figure 5 As shown in the figure, it mainly consists of three parts: feature extraction network, RPN network and classification regression network. The feature extraction network is ResNet-50, which is responsible for extracting the feature map corresponding to the image, and then using the extracted feature map as the input of the RPN network; the RPN network is responsible for generating region proposal boxes and performing bounding box regression to obtain the corresponding feature matrix, and finally each feature matrix is ​​uniformly scaled to a fixed size (7×7) through the ROI pooling layer and then passed to the classification regression network.

[0064] Third, the generated feature map is sent to the RPN network after adjusting the anchor size and scale ( Figure 6 ), generate the corresponding candidate regions.

[0065] The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network has three ratios {1:1, 1:2, 2:1}. Each anchor point generates 15 corresponding candidate regions in the original image. The loss is calculated according to the RPN loss function to obtain the vertex coordinates of each candidate region.

[0066] RPN loss function L({p i},{t i}) can be expressed as:

[0067]

[0068] Among them, L cls (p i ,p i * ) and L reg (t i ,t i * ) are the classification loss and bounding box regression loss respectively, which are defined as shown in formula (2) and formula (3):

[0069] L cls (p i ,p i * )=-[p i * log(p i )+(1-p i * )log(1-p i )] (2)

[0070]

[0071]

[0072] p i is the probability that the i-th anchor point is the true label; when the i-th anchor point is a positive sample, p i * is 1, otherwise it is 0; t i is the predicted regression parameter of the i-th bounding box; N cls is the number of samples in a batch; N reg is the number of pixels in the feature map; t i * is the true bounding box regression parameter corresponding to the i-th anchor point; λ is the balance parameter.

[0073] Fourth, map the candidate regions to the last two layers of the feature extraction network and perform feature fusion.

[0074] like Figure 7 As shown in the figure, the candidate region generated by RPN is mapped to the feature layers generated by the Conv5 layer and the Conv4 layer of the feature extraction network to obtain the feature maps of the candidate region on these two layers. Then, a fixed-size feature vector is obtained through the ROI Pooling layer and L2 regularization for feature fusion.

[0075] Fifth, the feature fusion vector is input into the fully connected layer to achieve classification and regression. Figure 8 As shown in the figure. The detection results show that after using the original image and the frequency domain image as a data set and using the feature fusion method, the detection accuracy of each type of foreign body can reach 99% at best. The location and category of the foreign body in each image can be accurately detected, and the accuracy is higher than the original method. At the same time, the detection speed after adding feature fusion is 6 frames / s, which is basically the same as the 7 frames / s of the original method, which can improve the detection accuracy while basically maintaining the detection speed.

[0076] The invention discloses an image foreign body detection method, which abandons the manual feature extraction process, realizes end-to-end training, and can accurately identify foreign bodies. The image preprocessing method increases the contrast between the image and the background, enhances the image detail features, and the feature fusion method can retain more image detail information, and the small target detection effect is better. After image preprocessing and feature fusion, the algorithm accuracy rate is increased from the original 84.4% to 97.9%, and the detection speed meets the industrial production requirements, and the robustness is strong.

[0077] Embodiment 2

[0078] This embodiment provides an image foreign body detection device, including the following modules:

[0079] A preprocessing module is used to obtain an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, and annotate the preprocessed image and use it as a data set for a deep learning network;

[0080] The feature extraction module is used to send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map;

[0081] The generation module is used to send the generated feature map to the RPN network after adjusting the anchor point size and scale to generate the corresponding candidate region;

[0082] The fusion module is used to map the candidate regions to the last two layers of the feature extraction network and perform feature fusion.

[0083] The input module is used to input the feature fusion vector into the fully connected layer to achieve classification and regression.

[0084] The preprocessing module specifically includes:

[0085] A first enhancement unit is used to enhance the image to be detected by using a nonlinear grayscale transformation enhancement method;

[0086] A second enhancement unit is used to enhance the high frequency part in the image after further enhancement;

[0087] The third enhancement unit is used to perform data enhancement on the twice enhanced image by flipping, brightness enhancement, translation, splicing and other methods, and mark the obtained image as a data set.

[0088] The feature extraction module specifically includes:

[0089] The feature extraction unit uses a ResNet-50 network to extract the feature map corresponding to the image, and then uses the extracted feature map as the input of the RPN network.

[0090] The regression unit is used in the RPN network to generate region proposal boxes and perform bounding box regression to obtain the corresponding feature matrix. Finally, each feature matrix is ​​uniformly scaled to a fixed size through the ROI pooling layer and then passed to the classification regression network.

[0091] The specific generation modules are:

[0092] The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network has three ratios {1:1, 1:2, 2:1}. Each anchor point generates 15 corresponding candidate regions in the original image.

[0093] The device of this embodiment is used to implement an image foreign body detection method in Embodiment 1. Its implementation method is the same as that of Embodiment 1. The specific implementation details are shown in Embodiment 1 and will not be repeated here.

[0094] Embodiment 3

[0095] Another embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any one of the above methods is implemented.

[0096] The computer device of this embodiment includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned image foreign body detection method embodiments are implemented. Alternatively, when the processor executes the computer program, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0097] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the computer device.

[0098] The computer device may be a desktop computer, a notebook computer, a palm computer, a cloud server, etc. The computer device may include, but is not limited to, a processor and a memory.

[0099] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0100] The memory may be an internal storage unit of the computer device, such as a hard disk or memory of the computer device. The memory may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device. Furthermore, the memory may include both an internal storage unit and an external storage device of the computer device. The memory is used to store the computer program and other programs and data required by the computer device. The memory may also be used to temporarily store data that has been output or is to be output.

[0101] Another preferred embodiment of the present invention provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to implement an image foreign body detection method as described in any one of the above when executed.

[0102] The preferred specific embodiments of the present invention are described in detail above. It should be understood that a person skilled in the art can make many modifications and changes based on the concept of the present invention without creative work. Therefore, any technical solution that can be obtained by a person skilled in the art through logical analysis, reasoning or limited experiments based on the concept of the present invention on the basis of the prior art should be within the scope of protection determined by the claims.

Claims

1. A method for detecting foreign matter in an image, characterized in that: The following steps are involved: Acquire an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, annotate the preprocessed image and use it as a data set for a deep learning network; Send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map; specifically including: The feature extraction network is ResNet-50, which is responsible for extracting the feature map corresponding to the image, and then using the extracted feature map as the input of the RPN network; the RPN network is responsible for generating region proposal boxes and performing bounding box regression to obtain the corresponding feature matrix, and finally each feature matrix is ​​uniformly scaled to a fixed size through the ROI pooling layer and then passed to the classification regression network; The generated feature map is sent to the RPN network after adjusting the anchor size and scale to generate the corresponding candidate region, specifically: The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network with three ratios {1:1, 1:2, 2:1} generates 15 corresponding candidate regions in the original image for each anchor point; Map the candidate region to the last two layers of the feature extraction network and perform feature fusion. Specifically, map the candidate region generated by RPN to the feature layers generated by the Conv5 and Conv4 layers of the feature extraction network to obtain the feature maps of the candidate region on these two layers; then obtain a fixed-size feature vector through the ROI Pooling layer and L2 regularization for feature fusion; The feature fusion vector is input into the fully connected layer to achieve classification and regression.

2. The image foreign body detection method according to claim 1, characterized in that: Obtain an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, and annotate the preprocessed image and use it as a data set for the deep learning network, specifically including: The image to be detected is first enhanced by using a nonlinear grayscale transformation enhancement method; Then the high frequency part is enhanced in the enhanced image; Finally, the twice enhanced images are subjected to data enhancement through flipping, brightness enhancement, translation, and splicing methods, and the obtained images are marked and used as data sets.

3. An image foreign body detection device, characterized in that: Includes the following modules: A preprocessing module is used to obtain an image to be detected, and preprocess the image to be detected in the spatial domain and the frequency domain respectively, and annotate the preprocessed image and use it as a data set for a deep learning network; The feature extraction module is used to send the data set to the feature extraction network of Faster R-CNN to obtain the corresponding feature map; the feature extraction module specifically includes: The feature extraction unit uses a ResNet-50 network to extract the feature map corresponding to the image, and then uses the extracted feature map as the input of the RPN network. The regression unit is used in the RPN network to generate region proposal boxes and perform bounding box regression to obtain the corresponding feature matrix. Finally, each feature matrix is ​​uniformly scaled to a fixed size through the ROI pooling layer and then passed to the classification regression network. The generation module is used to send the generated feature map to the RPN network after adjusting the anchor point size and scale to generate the corresponding candidate area; the generation module is specifically: The RPN anchor point size and scale are {32, 64, 128, 256, 512}, and the RPN network with three ratios {1:1, 1:2, 2:1} generates 15 corresponding candidate regions in the original image for each anchor point; The fusion module is used to map the candidate region to the last two layers of the feature extraction network and perform feature fusion. The candidate region generated by the RPN is mapped to the feature layers generated by the Conv5 layer and the Conv4 layer of the feature extraction network to obtain the feature mapping of the candidate region on these two layers. The fixed-size feature vector is obtained through the ROI Pooling layer and L2 regularization respectively for feature fusion. The input module is used to input the feature fusion vector into the fully connected layer to achieve classification and regression.

4. The image foreign body detection device according to claim 3, characterized in that: The preprocessing module specifically includes: A first enhancement unit is used to enhance the image to be detected by using a nonlinear grayscale transformation enhancement method; A second enhancement unit is used to enhance the high frequency part in the image after further enhancement; The third enhancement unit is used to perform data enhancement on the twice enhanced image by flipping, brightness enhancement, translation, and splicing methods, and mark the obtained image as a data set.

5. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 2 is implemented.

6. A computer-readable storage medium storing a computer program, characterized in that: The computer program enables a computer to implement an image foreign body detection method according to any one of claims 1 to 2 when executed.

Citation Information

Patent Citations

  • Vehicle-mounted video target detection method based on deep learning

    CN109977812A

  • Crack image detection method based on Faster R-CNN parameter migration

    CN110211097A

  • Road crack identification method based on deep learning

    CN110321815A

  • KR20210100937A