Image detection method, computer device and machine-readable storage medium
By performing edge detection and fitting on the target image and selecting the target edge signal area, the problem of large arc detection error in the prior art is solved, and the detection accuracy and efficiency are improved.
Patent Information
- Application Number
- CN202411075690.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-07
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-08-07
AI Technical Summary
The prior art has the problem of large detection errors in arc detection, especially in short arcs, which lead to large signal noise due to fewer pixels, making it difficult to achieve sufficient sensitivity and specificity.
By performing edge detection on the target image, an initial edge signal region consisting of multiple connected gradient change extreme values is obtained, and the target edge signal region is selected based on predetermined rules for fitting, reducing the calculation amount and reducing fitting errors, and improving detection Accuracy.
The accuracy and efficiency of arc detection are improved, the calculation amount is reduced, and the fitting error is reduced, so that arcs can be detected more accurately in low-diversity images.
Smart Images

Figure CN118587267B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of target detection technology, and in particular to an image detection method, a computer device, and a machine-readable storage medium. Background Art
[0002] Arc detection is an important technical branch in the field of graphics and image processing. It is mainly used for the process of detecting and fitting arcs in images. Short arcs usually have relatively large signal noise due to fewer pixels, which poses certain challenges to the accuracy of detection and fitting. Many algorithms that have been proposed are difficult to achieve sufficient sensitivity and specificity in industrial application scenarios. In related technologies, arcs are generally detected based on fitting errors by means of segmented fitting. However, the arc detection error of the segmented fitting method is related to the size of the segments, and in order to improve the accuracy, the segments are generally smaller, but this will bring about the problem of large amount of calculation and long calculation time. Therefore, most of the related technologies for arc detection in images have the problem of large detection errors. Summary of the invention
[0003] The present application provides an image detection method, a computer device and a machine-readable storage medium, which improve the accuracy of arc detection in an image, so as to at least partially solve the above-mentioned technical problems.
[0004] In order to achieve the above object, according to a first aspect of the present application, an image detection method is provided, comprising:
[0005] Perform edge detection on the target image to obtain an initial edge signal region composed of multiple connected gradient extreme value regions;
[0006] selecting a target edge signal region from the initial edge signal region based on a predetermined rule;
[0007] The target edge signal area is fitted to obtain the target arc in the target image.
[0008] Optionally, edge detection is performed on the target image to obtain an initial edge signal region composed of a plurality of connected gradient change extreme value regions, including:
[0009] Perform edge detection on the target image to obtain the first pixel point where multiple connected gradient change extreme values are located in the target image;
[0010] Traversing the first pixel points in sequence, and determining neighboring pixel points of each first pixel point based on a set neighborhood range;
[0011] The neighboring pixel points that meet the edge characteristics in the neighboring pixel points are used as the second pixel points;
[0012] An area formed by the first pixel point and the second pixel point is determined as an initial edge signal area.
[0013] Optionally, taking a neighboring pixel point that meets the edge feature among the neighboring pixel points as the second pixel point includes:
[0014] Determine in turn whether the signal-to-noise ratio of the neighboring pixels of each first pixel is greater than or equal to a set signal-to-noise ratio threshold;
[0015] If the signal-to-noise ratio of the neighboring pixel is greater than or equal to the set signal-to-noise ratio threshold, the neighboring pixel is used as the second pixel of the first pixel;
[0016] The signal-to-noise ratio threshold is set to the half-peak height of the first pixel.
[0017] Optionally, selecting a target edge signal region from the initial edge signal region based on a predetermined rule includes:
[0018] Get the ratio setting range of the target length and the target width of the initial edge signal area;
[0019] Receive an initial ratio value input by a user based on detection requirements;
[0020] If the initial ratio value is within the ratio setting range, the initial ratio value is determined as the target ratio value;
[0021] A target edge signal region is selected from the initial edge signal regions based on the target ratio value.
[0022] Optionally, selecting a target edge signal region from the initial edge signal region according to the target ratio value includes:
[0023] Determine whether the ratio of the target length to the target width of the initial edge signal area is greater than or equal to the target ratio;
[0024] If the ratio of the target length to the target width of the initial edge signal region is greater than or equal to the target ratio, the initial edge signal region is determined as the target edge signal region.
[0025] Optionally, fitting the target edge signal region to obtain a target arc in the target image includes:
[0026] The target edge signal area is fitted based on the target diameter range to obtain the target arc in the target image.
[0027] Optionally, fitting the target edge signal region based on the target diameter range to obtain a target arc in the target image includes:
[0028] All pixel points in the target edge signal area are fitted by the least square method to obtain the initial diameter of the initial arc and the fitting error;
[0029] Determine whether the initial diameter is within the target diameter range and whether the fitting error is within the set error range;
[0030] If the initial diameter is within the target diameter range and the fitting error is within the set fitting error range, determine whether the initial arc cannot be extended;
[0031] If the initial arc cannot be extended, the initial arc is determined as the target arc.
[0032] Optionally, determining whether the initial arc cannot be extended includes:
[0033] Determine whether the initial arc has no intersection with other target edge signal areas in the target image;
[0034] If the initial arc has no intersection with other target edge signal regions in the target image, it is determined that the initial arc cannot be extended.
[0035] Optionally, the method further comprises:
[0036] Get the diameter setting range of the target arc;
[0037] Receiving an initial diameter range input by a user based on detection requirements;
[0038] If the initial diameter range is within the diameter setting range, the initial diameter range is determined as the target diameter range.
[0039] According to a second aspect of the present application, a computer device is provided, comprising:
[0040] a memory configured to store instructions; and
[0041] The processor is configured to call instructions from the memory and implement the above-mentioned image detection method when executing the instructions.
[0042] According to a third aspect of the present application, a machine-readable storage medium is provided, on which instructions are stored, and when the instructions are executed by a processor, the processor is configured to perform the above-mentioned image detection method.
[0043] In summary, the present application first performs edge detection on the target image to obtain an initial edge signal region composed of multiple connected gradient change extreme value regions, and then selects the target edge signal region from the initial edge signal region based on a predetermined rule, and fits the target edge signal region to obtain the target arc in the target image. In this way, the edge detection of the present application obtains an edge signal region containing a gradient change extreme value region. Compared with the situation in the related art where only edges composed of a single pixel are generally detected, resulting in a large fitting error, the present application selects the target edge signal in the initial edge signal region, and the target edge signal region has a certain width. In the arc fitting process, the gradient change extreme value regions within a certain range can be regarded as the arc of the same circle. In this way, not only the amount of calculation is reduced, but also the arc fitting error can be reduced, thereby improving the accuracy of arc detection.
[0044] Other features and advantages of the present application will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 It is a flow chart of an image detection method provided in an embodiment of the present application;
[0047] Figure 2 is a schematic diagram of a gradient of a target image provided in an embodiment of the present application;
[0048] Figure 3 is a schematic diagram of a first pixel point obtained based on high-density edge detection provided in an embodiment of the present application;
[0049] Figure 4 is a schematic diagram of an initial edge signal area provided in an embodiment of the present application;
[0050] Figure 5 is a schematic diagram of an initial arc provided in an embodiment of the present application;
[0051] Figure 6 It is a flowchart of an image detection method provided in a specific embodiment of the present application;
[0052] Figure 7 is a structural schematic diagram of an image detection device provided in an embodiment of the present application;
[0053] Figure 8 It is a structural block diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] 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 only 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 those skilled in the art without creative work are within the scope of protection of this application.
[0055] In the description of the present application, it should be understood that the terms "first" and "second" are used only for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined. In the present application, the word "exemplary" is used to mean "used as an example, illustration or description". Any embodiment described as "exemplary" in the present application is not necessarily interpreted as being more preferred or more advantageous than other embodiments. In order to enable any technician in the field to implement and use the present application, the following description is given. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present application can also be implemented without using these specific details. In other examples, well-known structures and processes will not be elaborated in detail to avoid unnecessary details that make the description of the present application obscure. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in the present application.
[0056] The application scenario of the image detection method in the embodiment of the present application may include a computer device for the image detection method, and the computer device may be integrated with an image detection device to run the image detection method and its readable storage medium to execute the steps of the image detection method. The image detection method may be a method for detecting arcs in a target image, especially for low-diversity images with fewer changes or features. For example, a type of workpiece with a low-diversity surface that often appears in industrial application scenarios. The target image is an image of a workpiece with a low-diversity surface. It should be noted that the application scenario of the embodiment of the present application is not limited to the arc detection of workpiece images in the above-mentioned industrial scenarios, but can also be arc detection in other low-diversity images.
[0057] It can be understood that the computer equipment in the application scenario, or the devices included in the computer equipment, does not constitute a limitation on the embodiments of the present application. That is, the number of devices and types of devices included in the application scenario of the image detection method, or the number of devices and types of devices included in each device, do not affect the overall implementation of the technical solution in the embodiments of the present application, and can all be regarded as equivalent replacements or derivatives of the technical solution claimed to be protected in the embodiments of the present application.
[0058] The computer device in the embodiment of the present application may be an independent device, or a device network or device cluster composed of devices. For example, the computer device described in the embodiment of the present application includes but is not limited to a computer, a network host, a single network device, a plurality of network devices, or a cloud device composed of a plurality of devices. The cloud device is composed of a large number of computers or network devices based on cloud computing.
[0059] Based on the application scenario of the above image detection method, an embodiment of the image detection method is proposed. The following is a detailed description with reference to the accompanying drawings. Figure 1 , Figure 1 1 is a flow chart of an image detection method provided in an embodiment of the present application. In an embodiment of the present application, the image detection method may include the following steps 101-103, which are described in detail below.
[0060] Step 101: Perform edge detection on the target image to obtain an initial edge signal region composed of a plurality of connected gradient extreme value regions.
[0061] Step 102: Select a target edge signal region from the initial edge signal region based on a predetermined rule.
[0062] Step 103: Fit the target edge signal region to obtain a target arc of the target image.
[0063] In the embodiment of the present application, the target image refers to the image to be detected for arcs, especially for low-diversity images with few changes or features. For example, a type of workpiece with low-diversity surface that often appears in industrial application scenarios. After the input target image is obtained, the target image can be preprocessed, such as grayscale, noise reduction, etc., to obtain a grayscale image for edge detection.
[0064] The feature differences between each point of the low-diversity image are small, and the relevant target detection technology generally only detects the edge composed of a single pixel, which easily leads to a large fitting error. It is difficult to achieve sufficient sensitivity and specificity for such low-diversity images. Therefore, the edge detection in the embodiment of the present application is to detect the edge signal area containing the gradient change extreme value area of the target image. The edge signal area refers to a connected area composed of multiple gradient change extreme value areas obtained by edge detection. A target image may include one or more edge signal areas. In these edge signal areas, not all edge signal areas meet the fitting conditions. For example, if the length of the edge signal area is too short, the arc fitting conditions are not met. Therefore, in the embodiment of the present application, the edge signal area obtained by edge detection is the initial edge signal area. It is also necessary to further screen based on predetermined rules to select the target edge signal area that meets the fitting conditions. Among them, the predetermined rule refers to the rule for selecting the target edge signal area that meets the fitting conditions. For example, when the initial edge signal area is too short, the fitting conditions are not met, and the initial edge signal needs to be eliminated. This can reduce the number of fittings of the target edge signal area and improve the quality and efficiency of subsequent fitting of the edge signal area.
[0065] Traditional edge detection algorithms usually filter the image and calculate the grayscale difference between pixels to detect the edge, which is easily affected by noise and interference. Therefore, in an example of the present application, the edge of the target image can be detected by gradient change high-density edge detection. In addition to detecting the gradient change extreme value, high-density edge detection also needs to determine whether the density requirement meets the edge characteristics. If the density is less than the set density threshold, it means that the pixel point corresponding to the gradient change extreme value cannot be determined here. If the density is greater than or equal to the set density threshold, it means that the pixel point corresponding to the gradient change extreme value here. Determine the pixel point corresponding to the gradient change extreme value in the target image through high-density edge detection. Then determine the edge signal area based on the pixel point corresponding to the gradient change extreme value and the field pixel point that meets the edge characteristics. In this way, the edge signal area is an area with a certain width including multiple connected gradient change extreme value pixel points, which can make the fitting algorithm better adapt to the actual shape of the edge during the arc fitting process. In this way, the fitting error of the arc can be reduced. Furthermore, by detecting edge signal regions with a certain width, the pixel points corresponding to the extreme value of the gradient change and the region composed of the pixel points that meet the conditions in the neighborhood pixel points can be used as the edge of the same arc, so that the amount of calculation can be reduced when the circles are subsequently merged.
[0066] The edge detection in the embodiment of the present application obtains an edge signal area containing an extreme gradient change area. Compared with the related art that generally only detects edges composed of single pixels, resulting in a large fitting error, the embodiment of the present application selects the target edge signal in the initial edge signal area by setting a threshold, and the target edge signal area has a certain width. In the arc fitting process, the gradient change extreme area within a certain range can be regarded as the arc of the same circle. In this way, not only the amount of calculation is reduced, but also the arc fitting error can be reduced, thereby improving the accuracy of arc detection.
[0067] In order to ensure the accuracy of arc detection, the embodiment of the present application can also customize the set threshold of arc detection. Among them, the set threshold refers to the range of arc detection set according to the detection requirements of the user. Based on the set threshold, the target edge signal area that meets the fitting conditions in the initial edge signal area can be screened, and the target edge signal area can be fitted, thereby excluding the initial edge signal area that does not meet the fitting conditions and the target edge signal area that does not meet the target arc conditions after fitting. In this way, the calculation amount of arc detection is greatly reduced and the accuracy of arc detection is improved.
[0068] In an embodiment of the present application, the threshold value may include a target diameter range and a target ratio value. The target diameter range and the target ratio value are determined based on the setting value input by the user, wherein the target diameter range is used to limit the range of the target edge signal area that can be fitted. The target ratio value is used to limit the diameter range that meets the target arc condition after fitting. For example, the target diameter range is set to [100,200] to indicate that the diameter of the arc after fitting is between 100 pixels and 200 pixels.
[0069] In one example, assuming that the resolution of the target image is m×n (m, n are positive integers, and m≥n), for example, for a 5-megapixel resolution of m×n=2430×2060, the maximum detectable arc diameter that can be calculated is 3597025, and the center of this circle is far beyond the boundary of the target image. Therefore, the user needs to set the target diameter range. Specifically, the imaging limit resolution of an optical microscope is about 0.2μm, and the resolution of the human eye is 0.2mm, which limits the theoretical minimum detectable arc diameter of visual detection. The arc in the target image comes from actual devices such as compasses, and the radius of the circle corresponding to the arc does not exceed 2m. In other words, both in actual metric units and in theoretical conditions, the diameter range of the target arc spans 4 orders of magnitude. Therefore, it is necessary to limit the diameter setting range to improve the accuracy of arc detection. The target ratio value refers to the range where the ratio of the target length to the target width of the initial edge signal area is located. For example, a target ratio value of 4 means that the ratio threshold of the target length to the target width of the initial edge signal area is 4, and it must be greater than or equal to 4 to be determined as a target edge signal that meets the fitting conditions. The target length is the farthest distance between pixels in the initial edge signal region, and the target width is the narrowest width of pixels other than the endpoints in the initial edge signal region in the horizontal and vertical directions.
[0070] However, since the pixel values of each target image are different, the corresponding ideal limit range is also different. Therefore, in order to make the initial parameters input by the user effective, the diameter setting range of the target arc and the ratio setting range of the target length and target width of the initial edge signal area can be determined first. The diameter setting range refers to the extreme value range of the diameter of the arc that can be detected theoretically at the resolution of the target image. For example, for the target image with a resolution of m×n=2430×2060 mentioned above, the initial diameter range input by the user cannot exceed 3597025. The ratio setting range refers to the extreme value range of the length-to-width ratio of the initial edge signal area that can be fitted theoretically. Since at least three points are required to determine a circle, the minimum value in the ratio setting range is at least 3. If the user does not set this value, the default target ratio value is 3. If the ratio exceeds a certain value, the detection accuracy of the arc will not be affected by the length-to-width ratio, and it is also easy to cause the detection accuracy of the arc to be low. Therefore, an upper limit value of the ratio can also be set, for example, it can be set to 10.
[0071] When receiving the initial diameter range and initial ratio value input by the user based on the detection requirements, it is necessary to compare the initial diameter range with the diameter setting range, and compare the initial ratio value with the ratio setting range. Among them, the initial diameter range and the initial ratio value are the setting value of the diameter range and the setting value of the ratio input by the user. If the initial diameter range is within the diameter setting range, the initial diameter range can be determined as the target diameter range. Conversely, if the initial diameter range is not within the diameter setting range, it can be automatically adjusted to the maximum value of the diameter setting range based on the maximum value in the initial diameter range input by the user, or the user can be prompted to re-set the initial diameter range.
[0072] Similarly, if the initial scale value is within the scale setting range, it means that the scale value set by the user can meet the fitting conditions. At this time, the initial scale value can be determined as the target scale range. On the contrary, if the initial scale value is not within the scale setting range, it can be automatically adjusted to a scale value within the scale setting range based on the initial scale value input by the user, or the user can be prompted to reset the initial scale value. Finally, the target diameter range and the target scale value are determined as the set thresholds of the target image.
[0073] In step 101 of the embodiment of the present application, edge detection can be performed on the target image to obtain the first pixel point where multiple connected gradient change extreme values are located in the target image. Then, the first pixel points are traversed in sequence, and the neighborhood pixel points of each first pixel point are determined based on the set neighborhood range. Next, the neighborhood pixel points that meet the edge features in the neighborhood pixel points are used as the second pixel points. Finally, the area composed of the first pixel point and the second pixel point is determined as the initial edge signal area.
[0074] In an embodiment of the present application, the edge of the target image can be detected by gradient change high-density edge detection. Specifically, a gradient operator (such as a sobel gradient operator) can be applied to calculate the gradient value of each pixel in the target image, thereby obtaining the gradient amplitude and gradient direction of each pixel. For each pixel, by checking the relationship between the gradient amplitude of the pixel and its adjacent pixel along the gradient direction, it is determined whether the gradient change value corresponding to the pixel is a gradient change extreme value. If the gradient change value corresponding to the pixel is a gradient change extreme value, the pixel is determined as the first pixel. Then, based on the set neighborhood range, the neighborhood pixel corresponding to each first pixel can be determined. For example, if the set neighborhood range is 1, it means that the 8 neighborhoods around the first pixel are used as the neighborhood pixel corresponding to the first pixel. By traversing each first pixel of the target image in turn, a plurality of regions consisting of the first pixel and the neighborhood pixel within the set range of the first pixel can be obtained.
[0075] Figure 2is a schematic diagram of a gradient of a target image provided in an embodiment of the present application, Figure 3 is a schematic diagram of a first pixel point obtained based on high-density edge detection provided in an embodiment of the present application, Figure 4 is a schematic diagram of an edge signal area provided in an embodiment of the present application. Figure 2 , Figure 3 and Figure 4 ,by Figure 2 Take the target image shown as an example, Figure 2 There are multiple connected areas composed of extreme values of gradient changes in the image. In the high-density edge detection algorithm, the extreme value of gradient change can be determined based on the set density threshold. For example, if the set density threshold is 3, the density of the extreme value of gradient change must be greater than or equal to 3 to be determined as the extreme value of gradient change. In this way, outliers can be excluded and the accuracy of edge detection can be improved. Therefore, Figure 2 The area with a gradient value of 255 in can be the first pixel point obtained based on high-density edge detection, and the area composed of multiple connected first pixel points can be as follows: Figure 3 Assume that the neighborhood range is set to 2, then for each first pixel with a gradient value of 255, the 8-neighborhood and 16-neighborhood of the first pixel in the target image are both used as neighborhood pixels, and we can get Figure 4 The connected area composed of the first pixel point and its neighboring pixel points is shown.
[0076] However, not all neighborhood pixels are pixels in the edge area. Therefore, it is necessary to exclude the neighborhood pixels that do not meet the edge characteristics. In this way, the range of the initial edge signal area can be determined more accurately, thereby reducing the error in the subsequent fitting process and improving the accuracy of arc detection. Among them, the neighborhood pixels that do not meet the edge characteristics can be excluded in a variety of ways. For example, the neighborhood pixels that do not meet the edge characteristics can be excluded based on the signal-to-noise ratio of the neighborhood pixels or by similarity method.
[0077] The following is an example of determining edge features based on the signal-to-noise ratio of neighborhood pixels. In the embodiment of the present application, the signal-to-noise ratio threshold can be set to determine whether the signal-to-noise ratio of the neighborhood pixel meets the edge feature. Specifically, the signal-to-noise ratio threshold can be set based on each first pixel obtained by edge detection. The set signal-to-noise ratio threshold is used to eliminate neighborhood pixels with a low signal-to-noise ratio. In an example, the half-peak height of each first pixel can be determined as the set signal-to-noise ratio threshold of the first pixel. Then, it is determined in turn whether the signal-to-noise ratio of the neighborhood pixel in each first pixel is greater than or equal to the set signal-to-noise ratio threshold. If the signal-to-noise ratio of the neighborhood pixel is greater than or equal to the set signal-to-noise ratio threshold, the neighborhood pixel is used as the second pixel of the first pixel. Among them, the second pixel is a neighborhood pixel that meets the edge feature among the neighborhood pixels of each first pixel. On the contrary, if the signal-to-noise ratio of the neighborhood pixel is less than the set signal-to-noise ratio threshold, it means that the neighborhood pixel does not meet the edge feature and cannot be used as the second pixel, so the neighborhood pixel is excluded.
[0078] by Figure 2 For example, it can be determined that the pixel with a gradient value of 0 in the neighborhood pixel does not meet the edge feature, so the neighborhood pixel needs to be removed. Assuming that the half-peak height of the first pixel is used as the signal-to-noise ratio threshold, take 15 in the third column and fifth row in the upper left corner as an example. The minimum background value around the first pixel is 0, the relative peak value is 255-0=255, and the half-peak height is 127.5, while 15 is much lower than 127.5. Therefore, the pixel with a gradient value of 15 needs to be removed. In this way, the connected edge signal area may be divided into two or more parts, so the edge extension judgment needs to be performed later.
[0079] In step 102 of the embodiment of the present application, a target edge signal region can be selected from the initial edge signal region based on the target ratio value. Specifically, it can be determined whether the ratio of the target length to the target width of the initial edge signal region is greater than or equal to the target ratio value. If the ratio of the target length to the target width of the initial edge signal region is greater than or equal to the target ratio value, it means that the initial edge signal region meets the fitting condition, and therefore, the initial edge signal region can be determined as the target edge signal region. For example, assuming that the target image obtains 5 initial edge signal regions through edge detection, and the set target ratio value is 3, then the ratio of the target length and the target width of each initial edge signal region is obtained in turn, if they are 1, 1, 2, 4, and 5 respectively. Then the initial edge signal regions with ratio values of 4 and 5 can be retained as the target edge signal regions for fitting. In this way, the initial edge signal regions that do not meet the fitting conditions can be excluded, the amount of calculation is reduced, and the efficiency of arc fitting is improved.
[0080] In step 103 of the embodiment of the present application, the target edge region can be fitted based on the target diameter range to obtain the target arc in the target image. Specifically, the pixel points in the target edge signal region can be fitted by the least square method to obtain the initial arc, the initial diameter corresponding to the initial arc, and the fitting error in the fitting. In the fitting process of the initial arc, the tangential direction and the normal direction represent the change of the initial arc in different directions, and the tangential direction represents the direction of the initial arc in the local area, which can reflect the curvature and direction of the initial arc. The normal direction represents the change of the initial arc in the direction perpendicular to the tangential direction. In order to fit the arc more accurately, in one example, a first weight associated with the tangential direction and a second weight associated with the normal direction can be set. Since there may be noise or abnormal points in the fitting process, these abnormal points are prone to large errors in the normal direction, so a smaller second weight can be applied to reduce the influence of the error in the normal direction on the fitting result. Then, based on the first weight and the second weight, the target edge signal region is fitted by the least square method to obtain the initial arc. In this way, the fitting accuracy of the initial arc can be improved.
[0081] Then, it is determined whether the initial diameter of the initial arc is within the target diameter range and whether the fitting error is within the set error range. The set error range is obtained by converting the initial ratio value. If the initial diameter is within the target diameter range and the fitting error is within the set fitting error range, it means that the initial arc meets the conditions of the target arc. However, if the target image includes multiple target edge signal areas, there may be a target edge signal area that is the same circle as the target edge signal area corresponding to the current initial arc but is not a connected area. Therefore, it is necessary to further determine whether the current initial arc can continue to extend in the target image.
[0082] In an embodiment of the present application, it can be determined first whether the initial arc has no intersection with other target edge signal areas in the target image. If the initial arc has no intersection with other target edge signal areas in the target image, it can be determined that the initial arc cannot be extended. Specifically, the equation of the circle corresponding to the initial arc can be obtained based on the initial arc, and the coordinates of the pixel points included in the other target edge signal areas are matched with the equation of the circle. If they can match, it means that the extension lines of the other target edge signal areas and the initial arc are represented by the intersection, and the initial arc can be extended. Therefore, the pixel points corresponding to the initial arc can be merged with the pixel points of the intersection. If they cannot match, it means that the initial arc cannot be extended.
[0083] If the initial arc cannot be extended, the initial arc is determined as the target arc. At this time, the detection result of the target arc can be output, for example, the arc pixel set, arc length, center position, circle diameter, least squares error and other parameters of the target arc are output, so that the user can obtain the currently detected target arc and its related parameters. Among them, the arc pixel set is a strip area, the arc length is the calculated value of the target arc after fitting, the center position is based on the image coordinate system established by the user for coordinate display, the diameter of the circle can be calculated in pixels, and the least squares error reflects the credibility of the fitting result.
[0084] If the initial arc can be extended, the pixel points in the target edge signal area belonging to the same circle as the initial arc are merged with the pixel points in the initial arc, and steps 101 to 103 are repeated until the fitted initial arc cannot be extended, and the initial arc is determined as the target arc.
[0085] Figure 5 is a schematic diagram of an initial arc provided in an embodiment of the present application. Figure 5 The positions indicated by the arrows are all initial arcs. The initial arcs that do not meet the conditions can be eliminated from the initial arcs according to the target diameter range and fitting error. Figure 5 Most of the initial arcs in the "depressed area" are selected, and the remaining initial arcs numbered 1, 2, and 3 can be used as candidate target arcs. Then, it is further determined whether the initial arcs numbered 1, 2, and 3 cannot be extended. If the initial arc numbered 2 cannot be extended, it can be used as a target arc, and the target arc and the corresponding detection result are output. If the extension line of the initial arc numbered 1 intersects with the initial arc numbered 3, the pixel point set corresponding to the initial arc numbered 1 and the intersecting pixel point set in the initial arc numbered 3 are merged and refitted until the fitted initial arc cannot be extended. In this way, the initial arcs that do not meet the set threshold can be excluded, and the target arcs belonging to the same circle can be merged, thereby reducing the amount of calculation, making the output target arc more accurate, and improving the efficiency of arc detection.
[0086] Figure 6 is a flowchart of an image detection method provided in a specific embodiment of the present application. Figure 6 In a specific embodiment, the image detection method may include the following steps 601-609, which are described in detail below.
[0087] 601. Obtain an input target image.
[0088] 602. Determine a target diameter range and a target ratio value according to the target image.
[0089] 603. Scan the target image using a gradient-variation high-density edge detection algorithm to obtain an initial edge signal region.
[0090] 604. Obtain a target edge signal region based on the target ratio value.
[0091] 605. Fit the target edge signal region by the least square method to obtain an initial arc.
[0092] 606. Determine whether the diameter of the initial arc is within the target diameter range and whether the fitting error is within the set error range. If so, proceed to step 607; otherwise, return to step 605 to perform fitting of the next target edge signal region.
[0093] 607. Determine whether the initial arc cannot be extended. If not, proceed to step 608; if yes, proceed to step 609.
[0094] 608 . After merging the target edge signal regions intersecting with the initial arc extension line, return to step 605 and fit the merged target edge signal regions.
[0095] 609. Use the initial arc as a target arc, and output detection parameters of the target arc.
[0096] The embodiment of the present application changes the target of edge detection in arc detection, regards the edge as a gradient density area with a fuzzy width, and regards the neighboring pixels greater than or equal to the set signal-to-noise ratio threshold as the second pixel that characterizes the edge pixel. The area consisting of the first pixel corresponding to the extreme value of the gradient change in the target image and the adjacent second pixel is determined as the edge signal area. By changing the edge representation and algorithm target from a single pixel to an edge signal area with a certain width, the fitting algorithm can be better adapted to the actual shape of the edge during the arc fitting process, which can reduce the fitting error of the arc and thus improve the accuracy of arc detection. Moreover, in the process of arc fitting, the initial arc of the fitting is judged based on the set threshold, and the arc that does not meet the detection requirements can be abandoned in time, effectively saving the amount of calculation. In addition, the initial arcs belonging to the same circle are merged by judging the edge extension, so that the amount of calculation is reduced while maintaining the accuracy. In this way, the accuracy and efficiency of arc detection can be greatly improved.
[0097] See also Figure 7 , Figure 77 is a schematic diagram of the structure of an image detection device 700 provided in an embodiment of the present application. In an embodiment of the present application, the image detection device 700 may include a detection module 701, a selection module 702 and a fitting module 703. The detection module 701 is used to perform edge detection on a target image to obtain an initial edge signal region composed of a plurality of connected gradient change extreme value regions. The selection module 702 is used to select a target edge signal region from the initial edge signal region based on a predetermined rule. The fitting module 703 is used to fit the target edge signal region to obtain a target arc in the target image.
[0098] Among them, the detection module 701, the selection module 702 and the fitting module 703 can be used to respectively execute steps 101-103 in the embodiments corresponding to the above-mentioned image detection method. For the specific implementation methods of these modules and more details, please refer to the corresponding method part, which will not be repeated here.
[0099] Figure 8 is a structural block diagram of a computer device provided in an embodiment of the present application. Figure 8 The embodiment of the present application provides a computer device 800, including a memory 810 and a processor 820. The memory 810 is configured to store instructions. The processor 820 is configured to call instructions from the memory 810 and implement the above-mentioned image detection method when executing the instructions.
[0100] An embodiment of the present application also provides a machine-readable storage medium, on which instructions are stored. When the instructions are executed by a processor, the processor is configured to perform the above-mentioned image detection method.
[0101] Since the instructions stored in the computer device and the machine-readable storage medium can execute the steps in any image detection method provided in the embodiments of the present application, the beneficial effects that can be achieved by any image detection method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0102] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0103] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0104] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0106] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0107] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0108] Computer readable media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated communication signals and carrier waves.
[0109] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0110] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0111] The embodiments, implementation methods and related technical features of the present application can be combined and replaced with each other without conflict.
[0112] The above are only preferred embodiments of the present application and do not constitute any form of limitation to the present application. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present application without departing from the content of the technical solution of the present application are still within the scope of the technical solution of the present application.
Claims
1. An image detection method, characterized in that: include: Performing edge detection on the target image to obtain first pixel points where multiple connected gradient change extreme values are located in the target image; Traversing the first pixel points in sequence, and determining neighboring pixel points of each of the first pixel points based on a set neighborhood range; Using the neighboring pixel points that meet the edge feature among the neighboring pixel points as the second pixel points; Determine an area formed by the first pixel point and the second pixel point as an initial edge signal area; Obtaining a setting range of a ratio of a target length to a target width of the initial edge signal region; Receive an initial ratio value input by a user based on detection requirements; If the initial ratio value is within the ratio setting range, determining the initial ratio value as the target ratio value; selecting a target edge signal region from the initial edge signal region based on the target ratio value; The target edge signal region is fitted to obtain a target arc in the target image.
2. The image detection method according to claim 1, characterized in that: The taking the neighboring pixel points that meet the edge feature among the neighboring pixel points as the second pixel points includes: Determine in sequence whether the signal-to-noise ratio of each of the neighboring pixels of the first pixel is greater than or equal to a set signal-to-noise ratio threshold; If the signal-to-noise ratio of the neighborhood pixel point is greater than or equal to the set signal-to-noise ratio threshold, use the neighborhood pixel point as the second pixel point of the first pixel point; The set signal-to-noise ratio threshold is the half-peak height of the first pixel.
3. The image detection method according to claim 1, characterized in that: The selecting a target edge signal region from the initial edge signal region based on the target ratio value comprises: Determine whether a ratio of a target length to a target width of the initial edge signal region is greater than or equal to the target ratio; If the ratio of the target length to the target width of the initial edge signal region is greater than or equal to the target ratio, the initial edge signal region is determined as the target edge signal region.
4. The image detection method according to claim 1, characterized in that: The step of fitting the target edge signal region to obtain a target arc in the target image includes: The target edge signal region is fitted based on the target diameter range to obtain a target arc in the target image.
5. The image detection method according to claim 4, characterized in that: The step of fitting the target edge signal region based on the target diameter range to obtain a target arc in the target image includes: Fitting all pixel points in the target edge signal area by the least square method to obtain an initial diameter of the initial arc and a fitting error; Determine whether the initial diameter is within the target diameter range and whether the fitting error is within a set error range; If the initial diameter is within the target diameter range and the fitting error is within the set fitting error range, determining whether the initial arc cannot be extended; If the initial arc cannot be extended, the initial arc is determined as the target arc.
6. The image detection method according to claim 5, characterized in that: The determining whether the initial arc cannot be extended includes: Determine whether the initial arc has no intersection with other target edge signal areas in the target image; If the initial arc has no intersection with other target edge signal regions in the target image, it is determined that the initial arc cannot be extended.
7. The image detection method according to claim 4, characterized in that: Also includes: Obtaining a diameter setting range of the target arc; Receiving an initial diameter range input by a user based on detection requirements; If the initial diameter range is within the diameter setting range, the initial diameter range is determined as the target diameter range.
8. A computer device, characterized in that: include: a memory configured to store instructions; as well as A processor is configured to call the instructions from the memory and implement the image detection method according to any one of claims 1 to 7 when executing the instructions.
9. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores instructions, which, when executed by a processor, enable the processor to be configured to perform the image detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Arc screen body AA area grabbing method and device, electronic equipment and storage medium
CN116912276A