Target detection method, electronic device and computer readable storage medium
By moving the detection box on the grayscale image to be detected and using the average value of the grayscale value difference to determine the target pixel, the problem of poor accuracy in manually screening the target to be detected is solved, and higher detection accuracy is achieved.
Patent Information
- Application Number
- CN202210494887.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-07
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2042-05-07
AI Technical Summary
In existing technologies, manual screening of targets for testing results in missed detections and false detections, leading to poor detection accuracy.
By moving the detection box on the grayscale image to be detected, the difference in grayscale value between the center pixel and the reference pixel is determined. Using a preset detection method, the target pixel within the target detection box is determined, and the target to be detected is judged based on the average value of the grayscale value difference.
It improves the detection accuracy of the target and reduces missed detections and false detections.
Smart Images

Figure CN115100101B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a target detection method, an electronic device and a computer readable storage medium. BACKGROUND
[0002] With the continuous improvement of many industry standards, the quality requirements for various commodities, goods and food are increasingly improved, among which, the foreign matter content is gradually valued as one of the standards for rating the quality. Any kind of commodity, goods or food is the to-be-detected object, and the foreign matter is the to-be-measured target in the to-be-detected object. In the prior art, in addition to manually screening the to-be-measured target in the to-be-detected object, the to-be-detected image corresponding to the image is also used to artificially screen whether the to-be-measured target exists in the image. However, the visual fatigue of the human eye still leads to missed detection and false detection, so that the accuracy of detecting the to-be-measured target is poor. Therefore, how to improve the accuracy of detecting the to-be-measured target becomes a problem to be solved. SUMMARY
[0003] The technical problem solved by the present application is to provide a target detection method, an electronic device and a computer readable storage medium, which can improve the accuracy of detecting the to-be-measured target.
[0004] To solve the above technical problem, the first aspect of the present application provides a target detection method, comprising: obtaining a to-be-detected gray image of a to-be-detected object; moving a detection frame on the to-be-detected gray image by a sliding step, detecting the gray value of each pixel in each detection frame to obtain at least one target pixel; wherein each detection frame includes a center pixel and a reference pixel located at the periphery of the center pixel, the target pixel is the center pixel whose gray value difference with each reference pixel is greater than a gray threshold value, and the gray value of the target pixel in the detection frame is less than the gray value of the reference pixel; determining a to-be-measured target in the to-be-detected object based on the target pixel meeting a preset detection condition; wherein the preset detection condition includes that the average value of all gray value differences corresponding to the target pixel in the detection frame exceeds a detection threshold.
[0005] To solve the above technical problem, the second aspect of the present application provides an electronic device, which comprises a memory and a processor coupled with each other, wherein the memory stores program data, and the processor calls the program data to execute the method of the first aspect.
[0006] To solve the above technical problem, the third aspect of the present application provides a computer storage medium having program data stored thereon, wherein the program data is executed by a processor to implement the method of the first aspect.
[0007] The scheme is characterized in that: after obtaining the to-be-detected gray image of the to-be-detected object, the detection frame is moved on the to-be-detected gray image by a sliding step, wherein each detection frame includes a center pixel and reference pixels located at the periphery of the center pixel, and it is determined whether the center pixel in the detection frame meets the condition of being a target pixel, the target pixel being a center pixel in the detection frame whose difference in gray value from each reference pixel is greater than a gray threshold value, and the pixel value of the target pixel in the detection frame being less than the gray value of the reference pixel, that is, the gray value of the target pixel in the detection frame is greatly different from the gray value of the surrounding reference pixels, and the gray value of the target pixel is small, so that the target pixel is a dark point in the detection frame, and it is determined whether the average value of all gray value differences in the detection frame meets a detection threshold value, so as to judge and screen out the target pixel meeting the preset detection condition and having a large difference from the reference pixel, and then determine the to-be-detected target in the to-be-detected object. The average value of the gray value differences can reflect the difference of the target pixel in the detection frame from each reference pixel, and when the average value of the gray value differences is greater than the detection threshold value, it indicates that the target pixel meeting the preset condition is obviously different from the reference pixel. Based on the target pixel meeting the preset detection condition, the to-be-detected target in the to-be-detected object is determined, which can effectively improve the accuracy of detecting the to-be-detected target. BRIEF DESCRIPTION OF DRAWINGS
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor. Among them:
[0009] Figure 1 is a flowchart of an embodiment of the target detection method of the present application;
[0010] Figure 2 is Figure 1 is an application scenario diagram of an embodiment corresponding to step S102 in
[0011] Figure 3 is a flowchart of another embodiment of the target detection method of the present application;
[0012] Figure 4 is Figure 3 is an application scenario diagram of an embodiment corresponding to step S301 in
[0013] Figure 5 is a structural diagram of an embodiment of the electronic device of the present application;
[0014] Figure 6 is a structural diagram of an embodiment of the computer readable storage medium of the present application. Detailed Implementation
[0015] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0016] In this paper, the terms "system" and "network" are often used interchangeably. The term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this paper means two or more.
[0017] The target detection method provided in this application can be used to detect various commodities, goods and food as objects to be detected, thereby detecting the target to be detected in the object to be detected, including but not limited to foreign objects in various commodities, goods and food.
[0018] Please see Figure 1 , Figure 1 This is a flowchart illustrating one embodiment of the target detection method of this application, which includes:
[0019] S101: Obtain the grayscale image of the object to be detected.
[0020] Specifically, a grayscale image to be detected is obtained for the object to be detected, wherein the grayscale image to be detected can be the initial grayscale image of the object to be detected or the initial grayscale image after preprocessing.
[0021] In one application, the initial grayscale image of the object to be detected, acquired by the acquisition device, is used as the grayscale image to be processed. If the contrast of the grayscale image to be processed meets the contrast range, then the grayscale image to be processed is used as the grayscale image to be detected; otherwise, image preprocessing is performed on the grayscale image to be processed to obtain the grayscale image to be detected whose contrast meets the contrast range. Here, contrast is a measurement of the different brightness levels between the brightest white and the darkest black in an image; a larger difference range indicates a higher contrast, and a smaller difference range indicates a lower contrast.
[0022] In an application scenario, a to-be-processed gray image collected by a collection device for a to-be-detected object is obtained, the to-be-processed gray image that does not satisfy a preset contrast range is adjusted by a preset scaling degree, and a to-be-detected gray image that satisfies the contrast range is obtained, so that the to-be-detected gray image is clearer than a dark part of the to-be-processed gray image, and the quality of the to-be-detected gray image is improved.
[0023] In another application scenario, a to-be-processed gray image collected by a collection device for a to-be-detected object is obtained, the to-be-processed gray image is filtered to reduce noise in the to-be-processed gray image, a filtered gray image is obtained to reduce noise interference, the filtered gray image that does not satisfy a preset contrast range is adjusted by a preset scaling degree, and a to-be-detected gray image that satisfies the contrast range is obtained, so that the to-be-detected gray image is clearer than a dark part of the filtered gray image, and the quality of the to-be-detected gray image is improved.
[0024] In a specific application scenario, the collection device is an X-ray machine, and the X-ray is an electromagnetic wave with a wavelength less than a preset wavelength. The to-be-processed gray image of the to-be-detected object is collected by the X-ray machine. The to-be-detected object is food, and the X-ray machine can perform non-destructive collection on the to-be-detected object. Therefore, the image collection can be completed without moving the food, which is a fragile object, multiple times. The to-be-processed gray image is filtered and adjusted in contrast based on the above application mode, and the to-be-detected gray image of the to-be-detected object is obtained.
[0025] S102: Move the detection frame on the to-be-detected gray image by a sliding step, detect the gray values of the pixels in each detection frame, and obtain at least one target pixel. Each detection frame includes a center pixel and a reference pixel located at the periphery of the center pixel. The target pixel is the center pixel whose gray value difference from each reference pixel is greater than a gray threshold value. The gray value of the target pixel in the detection frame is less than the gray value of the reference pixel.
[0026] Specifically, the sliding step includes an interval corresponding to at least one pixel. The detection frame is moved on the to-be-detected gray image according to the sliding step, so that the detection frame scans in a raster manner to traverse all pixels on the to-be-detected gray image.
[0027] Please refer to Figure 2 , Figure 2 is Figure 1 the application scenario of an embodiment corresponding to step S102 in FIG. 7. The detection size of the detection frame is taken as an example of 7x7. When the detection frame is moved once, the pixel at the positive center of the detection frame is taken as the center pixel, and the pixels around the center pixel are taken as the reference pixels. The reference pixels at least include the pixels in the outermost circle of the detection frame, which correspond to Figure 2 In FIG. 7, T is a target pixel, and P1-P24 are reference pixels.
[0028] Further, in each detection frame, it is judged whether the gray value of each reference pixel minus the gray value of the center pixel is greater than the gray threshold value, if the gray value of all reference pixels in the detection frame minus the gray value of the center pixel is greater than the gray threshold value, the center pixel in the corresponding detection frame is taken as the target pixel. Wherein, the gray value refers to the depth of the pixel in the gray image, generally ranging from 0 to 255, white is 255, black is 0, that is, the gray value of the target pixel and the surrounding reference pixels in the detection frame is greatly different, and the gray value of the target pixel is smaller, then the target pixel is the dark point in the detection frame.
[0029] Preferably, the detection frame is a square, the side length of the detection frame corresponding to the detection size is an odd number in the pixel dimension, and then when the detection frame moves, the number of pixels in the detection frame is odd, so as to facilitate the determination of the position of the center pixel, and the sliding step corresponds to the interval corresponding to one pixel, so as to comprehensively scan the pixels on the gray image to be detected, and all the pixels except the edge pixels on the gray image to be detected can be taken as the center pixel when the detection frame moves, wherein the edge pixels include the pixels located within the preset interval close to the edge of the gray image to be detected, and the preset interval is related to the detection size of the detection frame.
[0030] In an application mode, the detection frame corresponds to a detection size, and the size relationship between the gray value difference between the reference pixel and the center pixel and the gray threshold value is compared in the detection frame to determine whether the center pixel is the target pixel, so as to quickly determine the relatively dark point in the gray image to be detected.
[0031] In another application mode, the detection frame corresponds to multiple detection sizes, and the size relationship between the gray value difference between the reference pixel and the center pixel and the gray threshold value is compared in the detection frame of different sizes to determine whether the center pixel is the target pixel, so as to determine the target pixel from the dimension of multiple detection sizes, and improve the detection accuracy of the target to be detected of different sizes.
[0032] In a specific application scenario, the gray value range is from 0 to 255, the detection frame is moved on the gray image to be detected by a sliding step, the sliding step is an interval corresponding to one pixel, the gray threshold value is 10, after moving the detection frame once, it is judged whether the gray value difference of all reference pixels relative to the center pixel in the current detection frame is greater than the gray threshold value, wherein the gray value difference is obtained based on the gray value of the reference pixel minus the gray value of the center pixel, and when the gray value difference of all reference pixels relative to the center pixel in the detection frame is greater than the gray threshold value, the corresponding center pixel is taken as the target pixel. In other specific application scenarios, the gray threshold value can also be a value in other gray value range, which is not limited in the present application.
[0033] S103: determining a target to be detected in the object to be detected based on the target pixel satisfying the preset detection condition, wherein the preset detection condition comprises that an average value of all gray value differences corresponding to the target pixel in the detection frame exceeds a detection threshold.
[0034] Specifically, it is determined whether the target pixel satisfies the preset detection condition, and based on the position corresponding to the target pixel in the gray scale image to be detected, the actual position corresponding to the target to be detected in the object to be detected is determined.
[0035] Further, the greater the gray value difference between the target pixel and the reference pixel, the darker the target pixel relative to the reference pixel. Therefore, the average value of the gray value differences between the target pixel and all reference pixels in the detection frame can reflect the difference degree of the target pixel relative to each reference pixel in the detection frame. When the target pixel satisfies the preset detection condition, the target pixel is a dark point that is obviously distinguished from the surrounding pixels.
[0036] In an application mode, the average value of the gray value differences between the target pixel and all reference pixels in the detection frame corresponding to the target pixel is determined, the size relationship between the average value and the detection threshold is compared, and based on the target pixel with the average value greater than the detection threshold in the gray scale image to be detected, the actual position corresponding to the target to be detected in the object to be detected is determined.
[0037] In another application mode, the average value of the gray value differences between the target pixel and all reference pixels in the detection frame corresponding to the target pixel is determined, whether the target pixel satisfies the preset detection condition is determined based on the relationship between the average value and the detection threshold, the position corresponding to the target pixel satisfying the preset detection condition is marked in the gray scale image to be detected, and the position of the target to be detected in the object to be detected is determined according to the proportion of the gray scale image to be detected.
[0038] In a specific application scenario, the target to be detected is a foreign matter in food, and the foreign matter is a small black block visible to the naked eye. Therefore, the target to be detected includes an object with a size smaller than a preset size in the object to be detected, and the local gray value of the target to be detected is smaller than a preset value. The average value of the gray value differences between the target pixel and all reference pixels in the detection frame corresponding to the target pixel is determined, and the target pixel satisfying the preset detection condition is determined based on the average value and the detection threshold. Therefore, the position corresponding to the target pixel satisfying the preset detection condition in the gray scale image to be detected is marked, that is, the position obviously darker in the gray scale image to be detected is marked, and the actual position corresponding to the target to be detected in the object to be detected is determined, so as to improve the accuracy of detecting the target to be detected.
[0039] The above scheme, after obtaining the to-be-detected gray image of the to-be-detected object, moves the detection frame on the to-be-detected gray image by a sliding step, wherein each detection frame includes a center pixel and a reference pixel located at the periphery of the center pixel, and it is determined whether the center pixel in the detection frame meets the condition of being a target pixel, the target pixel being a center pixel in the detection frame whose gray value difference with each reference pixel is greater than a gray threshold value, and the pixel value of the target pixel in the detection frame being less than the gray value of the reference pixel, that is, the gray value of the target pixel and the gray value of the surrounding reference pixel in the detection frame are both greatly different, and the gray value of the target pixel is small, so the target pixel is a dark point in the detection frame. It is determined whether the target pixel meets the condition that the average value of all gray value differences in the detection frame exceeds a detection threshold value, so as to judge and select the target pixel meeting the preset detection condition which is greatly different from the reference pixel, and further determine the to-be-detected target in the to-be-detected object. The average value of the gray value difference can reflect the difference degree of the target pixel in the detection frame relative to each reference pixel, and when the average value of the gray value difference is greater than the detection threshold value, it indicates that the target pixel meeting the preset condition is obviously different from the reference pixel. Based on the target pixel meeting the preset detection condition, the to-be-detected target in the to-be-detected object is determined, which can effectively improve the accuracy of detecting the to-be-detected target.
[0040] Please refer to Figure 3 , Figure 3 is a flowchart of another embodiment of the target detection method of the present application, which comprises:
[0041] S301: obtaining a to-be-processed gray image collected by a collection device for a to-be-detected object, and performing filtering processing on the to-be-processed gray image to obtain a filtered gray image.
[0042] Specifically, the collection device includes an emission module capable of emitting electromagnetic waves with a wavelength less than a preset wavelength, the collection device collects a gray image corresponding to the to-be-detected object as the to-be-processed gray image, and performs filtering processing on the to-be-processed gray image to reduce interference on the to-be-processed gray image and obtain the filtered gray image.
[0043] Optionally, the collection device is an X-ray machine, and the to-be-processed gray image is obtained by using the X-ray machine to collect an image of the to-be-detected object.
[0044] Further, due to the reasons of system hardware, there are often a large amount of noise in the initial gray image collected by part of the collection devices, and therefore it is preferred to perform filtering processing on the to-be-processed gray image to reduce noise interference and improve the accuracy of target detection.
[0045] In an application mode, the gray-scale image to be processed is filtered to obtain a filtered gray-scale image, including: moving the filter frame on the gray-scale image to be processed by a sliding step, extracting the pixels in the filter frame as the pixels to be filtered; using the median of the gray-scale values of all the pixels to be filtered in each filter frame to replace the corresponding gray-scale value of the pixel at the center position in the corresponding filter frame to obtain the filtered gray-scale image.
[0046] Specifically, refer to Figure 4 , Figure 4 is Figure 3 corresponding to step S301 in an embodiment of the application scene schematic diagram, the sliding step includes at least one pixel corresponding interval, in the gray-scale image to be detected according to the sliding step moving filter frame, the pixel in the filter frame as the pixel to be filtered, corresponding in Figure 4 filter frame is a dotted frame in the dotted frame, wherein the pixel is the pixel to be filtered, the gray-scale value of the pixel to be filtered in the filter frame is sorted according to the value, thereby obtaining the median of the gray-scale value corresponding to all the pixels to be filtered in the filter frame, using the median to replace the gray-scale value of the pixel at the center position in the filter frame, corresponding in Figure 4 the median is used to replace the gray-scale value of the pixel at the center position in the filter frame in Figure 4 , wherein, when the filter frame moves on the gray-scale image to be processed by the sliding step, the median is used to replace the gray-scale value of the pixel at the center position in the filter frame after each movement, so as to realize the median filtering, wherein the median filtering has good filtering effect on isolated noise pixels and impulse noise, can maintain the edge characteristics of the image, reduce the probability of significant blur of the image, and the filter frame used in the median filtering and the detection frame used subsequently can move according to the sliding step, which facilitates the use of the same processing mode for filtering and detection, and reduces the implementation difficulty of the whole process.
[0047] Further, the filter frame corresponds to a preset filter size, and the number of pixels to be filtered extracted from the filter frame based on the preset filter size is odd. Wherein, in order to determine the median in the filter frame and the pixel to be replaced by the median, the number of pixels to be filtered in the filter frame is odd, therefore the filter frame is preferably a square, and the length of the side of the filter size corresponding to the filter frame in the pixel dimension is odd.
[0048] In a specific application scenario, the filter frame is a square with a filter size of 3x3, so that the number of pixels to be filtered in each filter frame is 9, and the median of the pixels to be filtered is used to replace the gray-scale value of the pixel at the center of the filter frame. Wherein, it can be understood that the minimum filter size corresponding to the filter frame is 3x3, of course, in other application scenarios, the filter frame can also be a square with an odd length of the side, which is not limited in the present application.
[0049] S302: adjust the contrast of the filtered gray image according to a preset stretching degree, and perform contrast compensation on the filtered gray image after the contrast adjustment to obtain a to-be-detected gray image.
[0050] Specifically, the gray value of the to-be-detected target is usually small. In order to make the imaging of the to-be-detected target more obvious, the contrast of the filtered gray image is adjusted once according to a preset stretching degree, and the filtered gray image after the adjustment is subjected to contrast compensation, so that the to-be-detected gray image with better imaging effect of the to-be-detected target is obtained, and the accuracy of detecting the to-be-detected target is improved.
[0051] In an application mode, the gray values of the filtered gray image are adjusted based on the ratio of the average value of the gray values of all pixels in the filtered gray image to the gray values of the pixels in the filtered gray image, and an adjustment factor matched with the preset stretching degree, so that the contrast of the filtered gray image is adjusted within the preset stretching degree to obtain a stretched gray image; the stretched gray image is subjected to normalization processing, and the stretched gray image after the normalization processing is subjected to gamma correction, and the corrected stretched gray image is subjected to inverse normalization processing to obtain the to-be-detected gray image.
[0052] Specifically, the average value of the gray values corresponding to all pixels in the filtered gray image is determined, wherein the average value of the gray values is the average value of the gray values of all pixels in the filtered gray image, and the adjusted pixel is determined based on the ratio of the average value of the gray values to the gray value of each pixel and the adjustment factor. The above process is represented by the following formula:
[0053]
[0054] Wherein, f(i,j) represents a pixel in the filtered gray image, g(i,j) represents a pixel after contrast adjustment, m represents the average value of the gray values, E represents an adjustment factor matched with the preset stretching degree, and the value of the adjustment factor can change the degree of contrast stretching, wherein the value of the adjustment factor is 0.8, 1.2 or 1.6, or other self-defined numerical values.
[0055] Further, based on the accuracy of numerical calculation, the stretched gray image is subjected to normalization processing to unify the dimension of numerical processing. The above process is represented by the following formula:
[0056]
[0057] Wherein, the value range of f(i,j) is between 0-255, and the increment of 0.5 is set to facilitate the processing of 0 value.
[0058] Further, the stretched gray image after normalization is subjected to gamma correction, wherein the gamma correction can increase the contrast of the part with low gray value of the image and reduce the contrast of the part with high gray value of the image. The above process is expressed by the following formula:
[0059]
[0060] wherein r represents a correction parameter related to the gamma correction.
[0061] Further, the stretched gray image after correction is subjected to inverse normalization to obtain the detected gray image. The above process is expressed by the following formula:
[0062] g(i,j)=f(i,j)×256-0.5 (4)
[0063] wherein the above formula represents the process of inverse normalization, thereby obtaining the final detected gray image.
[0064] S303: Moving the detection frame of different detection sizes on the detected gray image by a sliding step, respectively, comparing the size relationship between the gray value difference between the reference pixel and the center pixel and the gray threshold in each detection frame, and obtaining at least one target pixel.
[0065] Specifically, the detection frame corresponds to a plurality of detection sizes, and the number of pixels in the detection frame corresponding to any detection size is odd, so that the center pixel in any detection size can be determined.
[0066] Further, the following steps are performed for each detection frame of each detection size: moving the detection frame on the detected gray image by a sliding step, detecting the gray value of the pixels in each detection frame of the same size, and obtaining at least one target pixel. Each detection frame includes a center pixel and a reference pixel located in the periphery of the center pixel, and the detection process includes comparing the size relationship between the gray value difference between the reference pixel and the center pixel and the gray threshold in each detection frame, and defining the center pixel with a gray value difference greater than the gray threshold as a target pixel.
[0067] It should be noted that, due to the uncertainty of the size and brightness of the target to be detected, by setting detection frames of different detection sizes, multi-scale pixel features can be extracted from the detected gray image, thereby improving the probability of obtaining target pixels of the target to be detected of different sizes mapped on the detected gray image.
[0068] Optionally, the detection frame is a square, the length of the side corresponding to the detection size of the detection frame in the pixel dimension is an odd number, and the length of the side corresponding to different detection sizes is any odd number between 7 and 27.
[0069] In a specific application scenario, the detection frame corresponds to five detection sizes, and the side lengths corresponding to the detection sizes are 7, 11, 17, 21 and 27 respectively. In other application scenarios, the number of detection sizes corresponding to the detection frame and the side lengths corresponding to the detection sizes can be customized based on the application scenario, and the present application does not make specific limitations thereto.
[0070] S304: determining at least one response value corresponding to the target pixel based on the gray value difference of the target pixel relative to the reference pixel in the detection frame corresponding to the at least one detection size, wherein the response value is the average of all gray value differences of the target pixel in the detection frame corresponding to the detection size.
[0071] Specifically, in the detection frame corresponding to different detection sizes, the target pixel detected for the same target to be detected may be the same pixel or different pixels. Therefore, the detection frame corresponding to at least one detection size of the target pixel is determined, the gray value difference of the reference pixel relative to the target pixel in the detection frame corresponding to the target pixel is determined, the average value corresponding to all gray value differences in the detection frame is obtained, and the average value is taken as the response value corresponding to the target pixel. If the target pixel corresponds to the detection frame of multiple detection sizes, the target pixel corresponds to multiple response values. The above process is represented by the following formula:
[0072]
[0073] wherein h and w represent the length and width of the gray scale image to be detected, k represents the side length of the detection frame, P i represents the reference pixel in the detection frame, T j represents the target pixel in the detection frame, and 4(k-1) represents the number of reference pixels. For details, please refer to Figure 2 .
[0074] Further, for the sliding frame of different detection sizes, at least one response value corresponding to each target pixel can be obtained, and the response value reflects the difference between the target pixel and the reference pixel.
[0075] S305: matching one response value for the target pixel as the target response value based on the selection rule.
[0076] Specifically, when the target pixel corresponds to multiple response values, one response value is matched for the target pixel as the target response value of the target pixel according to the selection rule, and when the target pixel corresponds to one response value, the corresponding response value is taken as the target response value of the target pixel.
[0077] Optionally, the selection rule is set to select the response value with the largest value as the target response value, so that the target pixel corresponds to a single response value.
[0078] S306: determining the target to be detected in the object to be detected based on the position of the target pixel corresponding to the target response value exceeding the detection threshold, wherein the detection threshold is related to the detection size of the detection frame corresponding to the target response value.
[0079] Specifically, the detection frames of different detection sizes are provided with respective corresponding detection thresholds, wherein the detection thresholds can be set based on application scenarios, and the detection thresholds are generally positively correlated with the detection sizes, and of course all the detection thresholds corresponding to the detection sizes can be set as the same value.
[0080] Further, before determining the target to be detected in the object to be detected based on the position of the target pixel corresponding to the target response value exceeding the detection threshold, the method further comprises: in response to any target pixel in a preset range including other target pixels, taking the target pixel with the maximum target response value as the only target pixel in the preset range.
[0081] Specifically, the size and brightness of the target to be detected are uncertain, and especially a single larger target to be detected can correspond to a target pixel in a detection frame of different detection sizes, and the target pixels corresponding to the single larger target to be detected are probably adjacent in position. Even if the target pixels adjacent in position correspond to different targets to be detected, the actual positions of the multiple targets to be detected corresponding to the target pixels adjacent in position are also probably adjacent. In actual application, after the position of one target to be detected is determined, the adjacent target to be detected can also be quickly located. Therefore, when any target pixel in a preset range includes other target pixels, the target pixel with the maximum target response value is taken as the only target pixel in the preset range, so as to perform non-maximum suppression on multiple target pixels corresponding to the same target to be detected, or perform non-maximum suppression on target pixels corresponding to multiple targets adjacent in position, and select the target pixel with the maximum response value in the preset range, that is, the target pixel with the most obvious difference, so as to improve the efficiency and accuracy of detecting the target to be detected.
[0082] Further, based on the relationship between the response value and the detection threshold, it is determined whether the target pixel meets the preset detection condition, the position of the target pixel corresponding to the target response value exceeding the detection threshold is marked in the gray scale image to be detected, and the position of the target to be detected is determined in the object to be detected according to the proportion of the gray scale image to be detected.
[0083] In this embodiment, the gray-scale image to be processed is filtered to reduce noise interference, thereby obtaining a filtered gray-scale image. The contrast of the filtered gray-scale image is adjusted according to a preset scaling degree, and the contrast of the adjusted filtered gray-scale image is compensated, thereby obtaining a detected gray-scale image with better imaging effect of the target to be detected, improving the accuracy of detecting the target to be detected. A detection frame of multiple detection sizes is used to determine a target pixel on the detected gray-scale image, and a target response value corresponding to the target pixel is determined. The difference between the target pixel and a reference pixel is fed back through the target response value, and then the target to be detected in the detected object is determined based on the position of the target pixel whose target response value exceeds a detection threshold, thereby improving the accuracy of detecting the target to be detected.
[0084] Please refer to Figure 5 , Figure 5 is a structural schematic diagram of an embodiment of an electronic device of the present application. The electronic device 50 includes a memory 501 and a processor 502 coupled to each other. The memory 501 stores program data (not shown in the figure), and the processor 502 invokes the program data to implement the method in any of the above embodiments. For details, please refer to the detailed description of the above method embodiments, which will not be repeated here.
[0085] Please refer to Figure 6 , Figure 6 is a structural schematic diagram of an embodiment of a computer readable storage medium of the present application. The computer readable storage medium 60 stores program data 600, which is executed by a processor to implement the method in any of the above embodiments. For details, please refer to the detailed description of the above method embodiments, which will not be repeated here.
[0086] It should be noted that the units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the present embodiment.
[0087] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0088] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0089] The above is only the embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent flow transformation using the content of the specification and drawings, or direct or indirect application in other related technical fields, is also included in the patent protection scope of the present application.
Claims
1. A target detection method, characterized in that, The method includes: Obtain the grayscale image of the object to be detected; A detection box is moved along the grayscale image to be detected by a sliding step size, and the grayscale value of the pixels within each detection box is detected to obtain at least one target pixel; wherein, each detection box includes a center pixel and reference pixels located around the center pixel, and the target pixel is the center pixel within the detection box whose grayscale value difference with each reference pixel is greater than a grayscale threshold, and the grayscale value of the target pixel within the detection box is less than the grayscale value of the reference pixels; the detection box corresponds to multiple detection sizes; Based on target pixels that meet preset detection conditions, the target to be detected in the object to be detected is determined; wherein, the preset detection conditions include: the average value of all grayscale value differences corresponding to the target pixel within the detection frame exceeds a detection threshold; The step of determining the target to be tested in the object to be detected based on target pixels that meet preset detection conditions includes: determining at least one response value corresponding to the target pixel based on the gray value difference of each target pixel relative to the reference pixel within a detection frame of at least one detection size; wherein the response value is the average of all gray value differences of the target pixel within the detection frame of the corresponding detection size; matching a response value to the target pixel based on a selection rule as a target response value; and determining the target to be tested in the object to be detected based on the position of the target pixel whose target response value exceeds the detection threshold; wherein the detection threshold is related to the detection size of the detection frame corresponding to the target response value.
2. The target detection method according to claim 1, characterized in that, The process of obtaining the grayscale image of the object to be detected includes: A grayscale image to be processed is acquired by the acquisition device for the object to be detected, and the grayscale image to be processed is filtered to obtain a filtered grayscale image. The contrast of the filtered grayscale image is adjusted according to a preset scaling factor, and contrast compensation is performed on the filtered grayscale image after the contrast adjustment to obtain the grayscale image to be detected.
3. The target detection method according to claim 2, characterized in that, The step of filtering the grayscale image to be processed to obtain a filtered grayscale image includes: Move the filter box on the grayscale image to be processed by a sliding step size, and extract the pixels within the filter box as the pixels to be filtered. The grayscale image is obtained by replacing the grayscale value of the pixel at the center position of the corresponding filter box with the median grayscale value of all the pixels to be filtered within each filter box.
4. The target detection method according to claim 3, characterized in that, in, The filter box corresponds to a preset filter size, and the number of pixels to be filtered extracted from the filter box based on the preset filter size is an odd number.
5. The target detection method according to claim 2, characterized in that, The process of adjusting the contrast of the filtered grayscale image by a preset scaling factor and then performing contrast compensation on the adjusted grayscale image to obtain the grayscale image to be detected includes: Based on the ratio of the mean gray value of the filtered grayscale image to the gray value of each pixel in the filtered grayscale image, and an adjustment factor that matches the preset scaling factor, the gray value of each pixel in the filtered grayscale image is adjusted, thereby adjusting the contrast of the filtered grayscale image within the preset scaling factor to obtain a stretched grayscale image. The stretched grayscale image is normalized, and the normalized stretched grayscale image is gamma corrected. The corrected stretched grayscale image is then inversely normalized to obtain the grayscale image to be detected.
6. The target detection method according to claim 1, characterized in that, The step of moving the detection box on the grayscale image to be detected by a sliding step size, detecting the grayscale value of the pixels within each detection box, and obtaining at least one target pixel includes: On the grayscale image to be detected, detection boxes of different detection sizes are moved by sliding steps. Within each detection box, the grayscale value difference between the reference pixel and the center pixel is compared with the grayscale threshold to obtain at least one target pixel. The number of pixels within the detection box corresponding to any detection size is odd.
7. The target detection method according to claim 6, characterized in that, Before determining the target to be detected in the object to be detected based on the position of the target pixel whose target response value exceeds the detection threshold, the method further includes: In response to any target pixel having other target pixels within a preset range, the target pixel with the largest target response value is selected as the single target pixel within the preset range.
8. An electronic device, characterized in that, include: A memory and a processor are coupled to each other, wherein the memory stores program data, and the processor invokes the program data to perform the method as described in any one of claims 1-7.
9. A computer-readable storage medium storing program data thereon, characterized in that, When the program data is executed by the processor, the method as described in any one of claims 1-7 is implemented.
Citation Information
Patent Citations
Thermal infrared imager and real-time automatic blind pixel detection processing method
CN111612773A