Edge detection, same edge line segment merging and edge detection method and device
By setting two sets of merging conditions and thresholds in the edge detection algorithm, the slight occlusion and radian edge of the edge of nearly straight objects in the image processing is solved, and higher detection accuracy and stability are achieved.
Patent Information
- Application Number
- CN202310862878.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-13
- Publication Date
- 2025-01-14
AI Technical Summary
Prior art In image processing and computer vision, edge detection algorithms are difficult to effectively deal with slight occlusion or blurring of light at the edges of nearly straight objects, as well as complex radian conditions at the edges of objects, resulting in disconnection or discontinuity of line segments.
Using a divide-and-conquer strategy, two sets of merge conditions and thresholds are set. The first merge condition is used to deal with slight occlusion or blurring, and the second merge condition is used to deal with radian edges, and the angle and distance thresholds are adjusted to ensure accuracy and stability.
It improves the adaptability and stability of the edge detection algorithm, and can effectively combine the broken line segments and radian edges of nearly straight objects, improving detection accuracy and adaptability.
Smart Images

Figure CN119313694A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing and computer vision, and in particular to an edge detection and edge segment merging and edge detection method, device, medium and equipment. Background Art
[0002] In many application scenarios of image processing and computer vision, it is necessary to detect the edges of nearly straight objects in a given image, such as detecting the four sides of a bank card in an image containing a bank card, or detecting the edge of a screen in an image containing a screen.
[0003] Edge detection algorithms generally perform line detection first and detect a series of line segments. If these detected line segments are not post-processed, the following problems will occur:
[0004] 1. The line segments are very fragmented, such as Figure 1 As shown, the line segments in the figure should be on a straight line, but many segments are obviously disconnected.
[0005] 2. In actual scenes, the edges of objects may be slightly blocked or partially blurred by light, which will cause the straight line to be disconnected at the blocked or blurred part, such as Figure 2 shown.
[0006] 3. In actual scenes, there may be complex situations where the edge of the object to be detected has a certain curvature. In this case, the detected line segments are segmented and not on a straight line. Figure 3 The curved edge of the curved bank card shown.
[0007] To solve the above problem, the detected line segments must be merged to obtain the edge of the nearly straight object. The existing method for merging line segments is: set a distance threshold and an angle threshold, and all line segments are judged whether to be merged based on the distance threshold and the angle threshold. When judging, the line segments are checked to see if they meet the distance threshold (the beginning and end of the two line segments must be close enough) and the angle threshold (the two line segments must be almost parallel) at the same time. If they meet both, they are merged into one line segment, otherwise no processing is performed.
[0008] However, the above-mentioned line segment merging method in the prior art cannot simultaneously meet the situation where the edge of a nearly straight object is slightly blocked or partially blurred by light, and the situation where the edge of the object has a certain curvature. Summary of the invention
[0009] In order to solve the defects of the prior art, the present application provides an edge detection and edge segment merging and edge detection method, device, medium and equipment, which improve the adaptability and stability of the edge detection algorithm while ensuring accuracy.
[0010] This application provides the following technical solutions:
[0011] In a first aspect, the present application provides a method for edge detection and edge segment merging, the method comprising:
[0012] Get a series of line segments obtained by edge detection;
[0013] Determine whether two line segments in the series of line segments meet the first merging condition or the second merging condition, and if so, merge the two line segments to obtain a merged line segment;
[0014] If the included angle between the two line segments is smaller than a set first angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set first distance threshold, then the first merging condition is satisfied;
[0015] If the included angle of the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, then the second merging condition is satisfied;
[0016] The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold.
[0017] Further, the two line segments include a target line segment and a line segment to be merged, and the determining whether two line segments in the series of line segments meet a first merging condition or a second merging condition, and if so, merging the two line segments to obtain a merged line segment, includes:
[0018] Sorting the series of line segments according to the starting point of each line segment in the series of line segments, and taking one of the sorted line segments as the target line segment;
[0019] The line segments within a set range after the target line segments are sorted are used as the line segments to be merged, each of the line segments to be merged is traversed, and it is determined whether the traversed line segments to be merged and the target line segments meet the first merging condition or the second merging condition;
[0020] If the first merging condition or the second merging condition is met, the target line segment is merged with the line segment to be merged, and the target line segment is updated as the merged line segment, and the process returns to the step of taking the line segments within the set range after the target line segment is sorted as the line segment to be merged, until all the line segments that can be merged in the series of line segments are merged to obtain the merged line segment;
[0021] If the angle between the line segment to be merged and the target line segment is less than a set first angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is less than a set first distance threshold, the first merging condition is met;
[0022] If the angle between the line segment to be merged and the target line segment is smaller than a set second angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set second distance threshold, the second merging condition is met.
[0023] Furthermore, the step of sorting the series of line segments according to the starting point of each line segment in the series of line segments also includes:
[0024] Each line segment is formatted, and the parameters of each line segment after formatting include the starting point, the end point, the angle with the positive direction of the horizontal axis, and the length.
[0025] Furthermore, the step of sorting the series of line segments according to the starting point of each line segment in the series of line segments includes:
[0026] The series of line segments are sorted according to the abscissa or ordinate of the starting point of each line segment in the series of line segments.
[0027] Furthermore, the distance between the endpoints of the line segment to be merged and the target line segment that are closest to each other is the distance between the end point of the target line segment and the starting point of the line segment to be merged;
[0028] and / or;
[0029] The starting point of the line segment after the line segment to be merged and the target line segment are merged is the starting point of the target line segment, and the end point is the end point of the line segment to be merged.
[0030] In a second aspect, the present application provides an edge detection and edge segment merging device, the device comprising:
[0031] A data acquisition module, used to acquire a series of line segments obtained by edge detection;
[0032] a merging judgment module, used to judge whether two line segments in the series of line segments meet the first merging condition or the second merging condition, and if so, merge the two line segments to obtain a merged line segment;
[0033] If the included angle between the two line segments is smaller than a set first angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set first distance threshold, then the first merging condition is satisfied;
[0034] If the included angle of the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, then the second merging condition is satisfied;
[0035] The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold.
[0036] Furthermore, the two line segments include a target line segment and a line segment to be merged, and the merge judgment module includes:
[0037] A sorting unit, used for sorting the series of line segments according to the starting point of each line segment in the series of line segments, and taking one of the sorted line segments as the target line segment;
[0038] A judging unit, configured to take the line segments within a set range after the target line segments are sorted as the line segments to be merged, traverse each of the line segments to be merged, and judge whether the traversed line segments to be merged and the target line segments meet a first merging condition or a second merging condition;
[0039] a merging unit, configured to merge the target line segment with the line segment to be merged if the first merging condition or the second merging condition is met, and update the target line segment to the merged line segment, and return to the judging unit until all the line segments that can be merged in the series of line segments are merged to obtain the merged line segment;
[0040] If the angle between the line segment to be merged and the target line segment is less than a set first angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is less than a set first distance threshold, the first merging condition is met;
[0041] If the angle between the line segment to be merged and the target line segment is smaller than a set second angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set second distance threshold, the second merging condition is met.
[0042] Furthermore, the device also includes:
[0043] The formatting module is used to format each line segment. The parameters of each line segment after formatting include the starting point, the end point, the angle with the positive direction of the horizontal axis, and the length.
[0044] Furthermore, the sorting unit is used to:
[0045] The series of line segments are sorted according to the abscissa or ordinate of the starting point of each line segment in the series of line segments.
[0046] Furthermore, the distance between the endpoints of the line segment to be merged and the target line segment that are closest to each other is the distance between the end point of the target line segment and the starting point of the line segment to be merged;
[0047] and / or;
[0048] The starting point of the line segment after the line segment to be merged and the target line segment are merged is the starting point of the target line segment, and the end point is the end point of the line segment to be merged.
[0049] In a third aspect, the present application provides a computer-readable storage medium for edge detection and edge line segment merging, comprising a memory for storing processor-executable instructions, which, when executed by the processor, implements the steps of the edge detection and edge line segment merging method described in the first aspect.
[0050] In a fourth aspect, the present application provides a device for edge detection and edge line segment merging, characterized in that it includes at least one processor and a memory storing computer-executable instructions, and when the processor executes the instructions, it implements the steps of the edge detection and edge line segment merging method described in the first aspect.
[0051] In a fifth aspect, the present application provides an edge detection method, the method comprising:
[0052] Perform edge detection on the image to be detected by using an edge detection algorithm to obtain a series of line segments;
[0053] Merging the line segments with the same edge in the series of line segments by the edge detection and edge line segment merging method to obtain the merged line segment;
[0054] The length of the merged line segment is compared with a set length threshold, and the merged line segments whose length is less than the length threshold are eliminated to obtain edge lines.
[0055] Further, when the edge line is merged according to the second merging condition, the edge line is translated outward by a set distance.
[0056] In a sixth aspect, the present application provides an edge detection device, the device comprising:
[0057] An edge detection module is used to perform edge detection on the image to be detected by using an edge detection algorithm to obtain a series of line segments;
[0058] A merging module, used for merging the line segments with the same edge in the series of line segments by using the edge detection and edge line segment merging method to obtain the merged line segment;
[0059] The elimination module is used to compare the length of the merged line segment with a set length threshold, eliminate the merged line segment whose length is less than the length threshold, and obtain the edge line.
[0060] Further, when the edge line is merged according to the second merging condition, the edge line is translated outward by a set distance.
[0061] In a seventh aspect, the present application provides a computer-readable storage medium for edge detection, comprising a memory for storing processor-executable instructions, wherein the instructions, when executed by the processor, implement the steps of the edge detection method described in the fifth aspect.
[0062] In an eighth aspect, the present application provides a device for edge detection, characterized in that it includes at least one processor and a memory storing computer-executable instructions, and when the processor executes the instructions, it implements the steps of the edge detection method described in the fifth aspect.
[0063] This application has the following beneficial effects:
[0064] The present application adopts a divide-and-conquer strategy to separately handle situations where the edges of nearly straight objects are slightly blocked or blurred and where the edges of objects have a certain curvature, set a first merging condition and a second merging condition, and set two sets of distance thresholds and angle thresholds. The first distance threshold of the first merging condition is larger and the first angle threshold is smaller, which is used to solve the situation where there are long missing line segments due to slight occlusion or blurring of the edges of nearly straight objects. The second distance threshold of the second merging condition is smaller and the second angle threshold is larger, which is used to solve the situation where the edges of objects have a certain curvature.
[0065] The present application adopts a divide-and-conquer strategy of setting the first merging condition and the second merging condition, which can improve the adaptability and stability of the edge detection algorithm while ensuring accuracy. Practical tests show that the present application has better accuracy and adaptability compared with the prior art method of one distance threshold and one angle threshold. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 A schematic diagram of a line segment with many disconnected sections obtained by edge detection;
[0067] Figure 2 A schematic diagram of a series of line segments output by an edge detection algorithm;
[0068] Figure 3 A schematic diagram of the line segments detected for the arc edge of the arc-shaped bank card;
[0069] Figure 4 A flowchart of the edge detection and edge segment merging method of the present application;
[0070] Figure 5 A schematic diagram of an edge detection and edge segment merging device of the present application;
[0071] Figure 6 A flow chart of the edge detection method of the present application;
[0072] Figure 7 is a schematic diagram of an edge detection device of the present application;
[0073] Figure 8 for Figure 2 Schematic diagram of the edge lines obtained after merging. DETAILED DESCRIPTION
[0074] In order to make the technical problems, technical solutions and advantages to be solved by the present application clearer, the technical solutions of the present application will be clearly and completely described below in conjunction with the drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0075] The present application embodiment provides a method for merging edge detection and edge segments. Figure 4 As shown, the method includes:
[0076] S100: Acquire a series of line segments obtained by edge detection.
[0077] The series of line segments described in this step are output by an edge detection algorithm. The present application does not limit the specific implementation of the edge detection algorithm. Exemplarily, the edge detection algorithm may be an LSD algorithm.
[0078] An example of the series of line segments is Figure 2 As shown, after obtaining the series of line segments, each line segment can also be formatted, and the parameters of each formatted line segment include the starting point, the end point, the angle with the positive direction of the horizontal axis, and the length. The starting point and the end point can be expressed in the form of coordinates, the length is the distance between the starting point and the end point, and the angle with the positive direction of the horizontal axis is the angle between the connecting line of the starting point and the end point and the positive direction of the horizontal axis. The angle can be expressed by the angle value of the connecting line and the positive direction of the horizontal axis, or by the slope of the connecting line.
[0079] S200: Determine whether two line segments in a series of line segments meet a first merging condition or a second merging condition, and if so, merge the two line segments to obtain a merged line segment.
[0080] If the angle between the two line segments is less than the first angle threshold and the distance between the closest endpoints of the two line segments is less than the first distance threshold, the first merging condition is satisfied. The angle between the two line segments can be calculated by the difference between the angles between the two line segments and the positive direction of the horizontal axis.
[0081] If the included angle of the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, the second merging condition is met.
[0082] The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold. In addition, the first angle threshold, the first distance threshold, the second angle threshold, and the second distance threshold are set according to factors such as the actual usage scenario, the size of the image to be detected, and interference items, so as to ensure that line segments that are not the same edge are not merged.
[0083] Generally, the values of the first angle threshold, the first distance threshold, the second angle threshold and the second distance threshold are all within a very small range to prevent line segments that are not the same edge from being merged. Exemplarily, the first angle threshold and the second angle threshold should generally not exceed 45°. Preferably, the value range of the first angle threshold can be 0-10°, and the value range of the second angle threshold can be 0-20°.
[0084] The first distance threshold and the second distance threshold should generally not exceed 1 / n of the width or height of the image to be detected to prevent line segments that are not the same edge from being merged. The specific value of 1 / n is set as needed, such as 1 / 5.
[0085] In addition, the first angle threshold, the first distance threshold, the second angle threshold and the second distance threshold can also be obtained based on a statistical method or based on deep learning model training, so that their values can ensure that line segments that are not the same edge are not merged. Preferably, the second angle threshold can also be calculated based on the statistical value of the angle between adjacent line segments of the arc edge.
[0086] In the prior art, a distance threshold and an angle threshold are set, and the detected line segments are checked in pairs to see whether they meet the distance threshold and the angle threshold at the same time, to determine whether the line segments are merged. The prior art line segment merging method cannot simultaneously meet both situation one and situation two, where situation one is: the edge of a nearly straight object is slightly blocked or partially blurred by light. Situation two is: the edge of the object has a certain curvature.
[0087] Because in case 1, the line segments on the same edge are disconnected due to occlusion or blur, and the line segments belonging to the same edge appear to be almost parallel but far apart from each other. In case 2, due to the curvature of the edge, the line segments belonging to the same arc edge appear to be close to each other but with a large angle.
[0088] If a distance threshold and an angle threshold are used to apply to the above two situations at the same time, so that the disconnected line segments belonging to the same edge in situation one and situation two can be merged, the distance threshold and the angle threshold must be set large enough at the same time, which will cause line segments that do not belong to the same edge to be mistakenly merged.
[0089] To solve the above problems, the present application adopts a divide-and-conquer strategy to handle Case 1 and Case 2 separately, set a first merging condition and a second merging condition, and set two sets of distance thresholds and angle thresholds. The first distance threshold of the first merging condition is larger and the first angle threshold is smaller, which is used to solve the situation in Case 1 where the edge of a nearly straight object is slightly blocked or blurred, resulting in a long missing line segment. The second distance threshold of the second merging condition is smaller and the second angle threshold is larger, which is used to solve the situation in Case 2 where the edge of the object has a certain curvature.
[0090] The present application adopts a divide-and-conquer strategy of setting the first merging condition and the second merging condition, which can improve the adaptability and stability of the edge detection algorithm while ensuring accuracy. Practical tests show that the present application has better accuracy and adaptability compared with the prior art method of one distance threshold and one angle threshold.
[0091] As an improvement of the embodiment of the present application, the two line segments involved in the merging include a target line segment and a line segment to be merged. Accordingly, a specific implementation of the aforementioned S200 includes:
[0092] S210: Sort the series of line segments according to the starting point of each line segment in the series of line segments, and use one of the sorted line segments as the target line segment.
[0093] When sorting, a series of line segments can be sorted according to the horizontal coordinate or vertical coordinate of the starting point of each line segment. After sorting, the target line segments can be selected in sequence according to the sorting order for merging. At the beginning, the first line segment after sorting can be selected as the target line segment. Of course, the target line segment can also be selected according to a set strategy instead of in order, and this application does not limit this.
[0094] S220: Segments within a set range after the target segment is sorted are used as the segment to be merged, each segment to be merged is traversed, and it is determined whether the traversed segment to be merged and the target segment meet the first merging condition or the second merging condition.
[0095] In this step, each time a target line segment is selected, the remaining line segments within a set range (the set range can be determined according to actual needs) after the target line segment is sorted are traversed as the line segments to be merged, and it is determined in turn whether the line segments to be merged and the target line segment meet the first merging condition or the second merging condition.
[0096] S230: If the first merging condition or the second merging condition is met, the target line segment is merged with the line segment to be merged, and the target line segment is updated to the merged line segment, and the process returns to the step S220, and the remaining line segments are continued to be traversed until all the line segments that can be merged in the series of line segments are merged to obtain a merged line segment.
[0097] The starting point of the line segment after the line segment to be merged is the starting point of the target line segment, and the end point is the end point of the line segment to be merged. The length of the merged line segment and the angle with the positive direction of the horizontal axis are calculated based on the starting point and end point of the merged line segment. The starting point, end point, length and angle with the positive direction of the horizontal axis of the target line segment are updated to the starting point, end point, length and angle with the positive direction of the horizontal axis of the merged line segment.
[0098] If the angle between the line segment to be merged and the target line segment is smaller than a set first angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set first distance threshold, the first merging condition is met.
[0099] If the angle between the line segment to be merged and the target line segment is smaller than a set second angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set second distance threshold, the second merging condition is met.
[0100] The distance between the endpoints of the line segment to be merged and the target line segment described in the present application is preferably the distance between the end point of the target line segment and the starting point of the line segment to be merged.
[0101] The embodiment of the present application also provides a device for merging edge detection and edge segments, such as Figure 5 As shown, the device comprises:
[0102] The data acquisition module 100 is used to acquire a series of line segments obtained by edge detection.
[0103] The merging judgment module 200 is used to judge whether two line segments in the series of line segments meet the first merging condition or the second merging condition. If so, the two line segments are merged to obtain a merged line segment.
[0104] If the included angle between the two line segments is smaller than a set first angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set first distance threshold, the first merging condition is met.
[0105] If the included angle of the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, the second merging condition is met.
[0106] The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold.
[0107] The present application adopts a divide-and-conquer strategy to separately handle situations where the edges of nearly straight objects are slightly blocked or blurred and where the edges of objects have a certain curvature, set a first merging condition and a second merging condition, and set two sets of distance thresholds and angle thresholds. The first distance threshold of the first merging condition is larger and the first angle threshold is smaller, which is used to solve the situation where there are long missing line segments due to slight occlusion or blurring of the edges of nearly straight objects. The second distance threshold of the second merging condition is smaller and the second angle threshold is larger, which is used to solve the situation where the edges of objects have a certain curvature.
[0108] The present application adopts a divide-and-conquer strategy of setting the first merging condition and the second merging condition, which can improve the adaptability and stability of the edge detection algorithm while ensuring accuracy. Practical tests show that the present application has better accuracy and adaptability compared with the prior art method of one distance threshold and one angle threshold.
[0109] As an improvement of the embodiment of the present application, the two line segments involved in the merger include a target line segment and a line segment to be merged. Accordingly, a specific implementation of the merger judgment module includes:
[0110] The sorting unit is used for sorting a series of line segments according to the starting point of each line segment in the series of line segments, and taking one of the sorted line segments as the target line segment.
[0111] The judging unit is used to take the line segments within the set range after the target line segments are sorted as the line segments to be merged, traverse each line segment to be merged, and judge whether the traversed line segment to be merged and the target line segment meet the first merging condition or the second merging condition.
[0112] The merging unit is used to merge the target line segment with the line segment to be merged if the first merging condition or the second merging condition is met, and update the target line segment to the merged line segment, and return to the judgment unit until all the line segments that can be merged in a series of line segments are merged to obtain a merged line segment.
[0113] If the angle between the line segment to be merged and the target line segment is less than a set first angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is less than a set first distance threshold, then the first merging condition is met;
[0114] If the angle between the line segment to be merged and the target line segment is smaller than a set second angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set second distance threshold, the second merging condition is met.
[0115] In one example, the device of the embodiment of the present application further includes:
[0116] The formatting module is used to format each line segment. The parameters of each line segment after formatting include the starting point, the end point, the angle with the positive direction of the horizontal axis, and the length.
[0117] When sorting, the aforementioned sorting unit may sort the series of line segments according to the abscissa or ordinate of the starting point of each line segment in the series of line segments.
[0118] As a preference, the distance between the endpoints of the aforementioned line segment to be merged and the target line segment that are closest to each other is the distance between the end point of the target line segment and the starting point of the line segment to be merged.
[0119] The starting point of the line segment after the line segment to be merged is merged with the target line segment is the starting point of the target line segment, and the end point is the end point of the line segment to be merged.
[0120] The device provided in the above embodiment, its implementation principle and the technical effect produced correspond to the embodiment of the above method one by one. For the sake of brief description, the part not mentioned in the embodiment of the device can refer to the corresponding content in the embodiment of the above method. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the modules and units described in the device can refer to the corresponding process in the embodiment of the above method, and will not be repeated here.
[0121] The present application also provides an edge detection method, such as Figure 6 As shown, the method includes:
[0122] S10: Perform edge detection on the image to be detected by using an edge detection algorithm to obtain a series of line segments.
[0123] The present application does not limit the specific implementation of the edge detection algorithm. Exemplarily, the edge detection algorithm may be an LSD algorithm.
[0124] S20: merging line segments with the same edge in a series of line segments by using the aforementioned edge detection same edge line segment merging method to obtain a merged line segment.
[0125] S30: Compare the length of the merged line segment with a set length threshold, and remove the merged line segment whose length is less than the length threshold to obtain an edge line.
[0126] An example of the obtained edge line is Figure 8As shown, according to the obtained edge line, the bank card and other targets can be cut out from the image to be detected, and subsequent recognition tasks can be performed.
[0127] For the case where the edge of the object is an arc curve, since the final edge line is a straight line, the arc part will be excluded. The arc part is the arc-shaped area surrounded by the start and end points of the straight edge line and the arc edge. For recognition scenarios such as bank cards, the arc part has no valid information and can be safely excluded.
[0128] For other scenes where the arc part contains valid information, the edge line can be appropriately moved outward through post-processing to achieve the effect of complete selection. Specifically, if the edge line is merged according to the second merging condition, it means that the actual edge of the object corresponding to the edge line is a curve. At this time, the edge line is translated outward by the set distance to achieve the effect of completely selecting the arc edge target.
[0129] The present application also provides an edge detection device, such as Figure 7 As shown, the device comprises:
[0130] The edge detection module 10 is used to perform edge detection on the image to be detected by using an edge detection algorithm to obtain a series of line segments.
[0131] The merging module 20 is used to merge the line segments with the same edge in a series of line segments by using the edge detection and edge line segment merging method to obtain a merged line segment.
[0132] The elimination module 30 is used to compare the length of the merged line segment with a set length threshold, and eliminate the merged line segment whose length is less than the length threshold to obtain an edge line.
[0133] To completely select the arc-shaped target, when the edge lines are merged according to the second merging condition, the edge lines are translated outward by a set distance.
[0134] The device provided in the above embodiment, its implementation principle and the technical effect produced correspond to the embodiment of the above method one by one. For the sake of brief description, the part not mentioned in the embodiment of the device can refer to the corresponding content in the embodiment of the above method. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the modules and units described in the device can refer to the corresponding process in the embodiment of the above method, and will not be repeated here.
[0135] The edge detection and edge line segment merging method / edge detection method described in the above embodiments provided by the present application can implement business logic through a computer program and record it on a storage medium, and the storage medium can be read and executed by a computer to achieve the effect of the scheme described in the method embodiment of this specification. Therefore, the embodiment of the present application also provides a computer-readable storage medium for edge detection and edge line segment merging / edge detection, including a memory for storing processor-executable instructions, and when the instructions are executed by the processor, the steps of the edge detection and edge line segment merging method / edge detection method including the above embodiments are implemented.
[0136] The storage medium may include a physical device for storing information, which is usually a medium that digitizes the information and then stores it in an electrical, magnetic or optical manner. The storage medium may include: a device that stores information in an electrical energy manner, such as various memories, such as RAM, ROM, etc.; a device that stores information in a magnetic energy manner, such as a hard disk, a floppy disk, a magnetic tape, a magnetic core memory, a magnetic bubble memory, a USB flash drive; a device that stores information in an optical manner, such as a CD or a DVD. Of course, there are other readable storage media, such as quantum memory, graphene memory, etc.
[0137] The storage medium described above may also include other implementation methods according to the description of the method embodiment. The implementation principle and technical effects produced by this embodiment are the same as those of the aforementioned method embodiment. For details, please refer to the description of the relevant method embodiment, and no further description will be given here.
[0138] The embodiment of the present application also provides a device for edge detection and edge line segment merging / edge detection, which may be a separate computer, or may include an actual operating device using one or more of the methods or one or more of the embodiments of the present specification. The device for edge detection and edge line segment merging / edge detection may include at least one processor and a memory storing computer executable instructions, and when the processor executes the instructions, any one or more of the steps of the edge detection and edge line segment merging method / edge detection method are implemented.
[0139] The device described above may also include other implementation methods according to the description of the method embodiment. The implementation principle and technical effects produced by this embodiment are the same as those of the aforementioned method embodiment. For details, please refer to the description of the relevant method embodiment, and no further description will be given here.
[0140] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A method for merging edge segments by edge detection, characterized in that: The method comprises: Get a series of line segments obtained by edge detection; Determine whether two line segments in the series of line segments meet the first merging condition or the second merging condition, and if so, merge the two line segments to obtain a merged line segment; If the included angle between the two line segments is smaller than a set first angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set first distance threshold, then the first merging condition is satisfied; If the included angle of the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, then the second merging condition is satisfied; The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold.
2. The edge detection and edge segment merging method according to claim 1, characterized in that: The two line segments include a target line segment and a line segment to be merged, and the determining whether two line segments in the series of line segments meet a first merging condition or a second merging condition, and if so, merging the two line segments to obtain a merged line segment, comprises: Sorting the series of line segments according to the starting point of each line segment in the series of line segments, and taking one of the sorted line segments as the target line segment; The line segments within a set range after the target line segments are sorted are used as the line segments to be merged, each of the line segments to be merged is traversed, and it is determined whether the traversed line segments to be merged and the target line segments meet the first merging condition or the second merging condition; If the first merging condition or the second merging condition is met, the target line segment is merged with the line segment to be merged, and the target line segment is updated as the merged line segment, and the process returns to the step of taking the line segments within the set range after the target line segment is sorted as the line segment to be merged, until all the line segments that can be merged in the series of line segments are merged to obtain the merged line segment; If the angle between the line segment to be merged and the target line segment is less than a set first angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is less than a set first distance threshold, the first merging condition is met; If the angle between the line segment to be merged and the target line segment is smaller than a set second angle threshold and the distance between the closest endpoints of the line segment to be merged and the target line segment is smaller than a set second distance threshold, the second merging condition is met.
3. The edge detection and edge segment merging method according to claim 2, characterized in that: The step of sorting the series of line segments according to the starting point of each line segment in the series of line segments also includes: Each line segment is formatted, and the parameters of each line segment after formatting include the starting point, the end point, the angle with the positive direction of the horizontal axis, and the length.
4. The edge detection and edge segment merging method according to claim 3, characterized in that: The step of sorting the series of line segments according to the starting point of each line segment in the series of line segments comprises: The series of line segments are sorted according to the abscissa or ordinate of the starting point of each line segment in the series of line segments.
5. The edge detection and edge segment merging method according to claim 3, characterized in that: The distance between the endpoints closest to the line segment to be merged and the target line segment is the distance between the end point of the target line segment and the starting point of the line segment to be merged; and / or; The starting point of the line segment after the line segment to be merged and the target line segment are merged is the starting point of the target line segment, and the end point is the end point of the line segment to be merged.
6. An edge detection and edge segment merging device, characterized in that: The device comprises: A data acquisition module, used to acquire a series of line segments obtained by edge detection; a merging judgment module, used to judge whether two line segments in the series of line segments meet the first merging condition or the second merging condition, and if so, merge the two line segments to obtain a merged line segment; If the included angle between the two line segments is smaller than a set first angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set first distance threshold, then the first merging condition is satisfied; If the angle between the two line segments is smaller than a set second angle threshold and the distance between the closest endpoints of the two line segments is smaller than a set second distance threshold, the second merging condition is satisfied; The first angle threshold is smaller than the second angle threshold, and the first distance threshold is larger than the second distance threshold.
7. A computer-readable storage medium for edge detection and edge segment merging, characterized in that: It comprises a memory for storing processor executable instructions, and when the instructions are executed by the processor, the steps of the edge detection and edge line segment merging method according to any one of claims 1 to 5 are implemented.
8. A device for edge detection and edge segment merging, characterized in that: The method comprises at least one processor and a memory storing computer executable instructions, wherein when the processor executes the instructions, the steps of the edge detection and edge line segment merging method described in any one of claims 1 to 5 are implemented.
9. An edge detection method, characterized in that: The method comprises: Perform edge detection on the image to be detected by using an edge detection algorithm to obtain a series of line segments; Merging the line segments with the same edge in the series of line segments by the edge detection same edge line segment merging method according to any one of claims 1 to 5 to obtain the merged line segment; The length of the merged line segment is compared with a set length threshold, and the merged line segments whose length is less than the length threshold are eliminated to obtain edge lines.
10. The edge detection method according to claim 9, characterized in that: When the edge lines are merged according to the second merging condition, the edge lines are translated outward by a set distance.
Citation Information
Cited By
Stay cable segmentation method, device and equipment for unmanned aerial vehicle shooting and medium
CN121414773A