A straight line detection method, system, image processing device, and storage medium

By using rectangular detection frames and least squares method in image processing, parallel straight lines intersect the edge contour, the problems of low linear detection efficiency and waste of resources in the prior art are solved, and fast and accurate linear acquisition is achieved.

CN114359316BActive Publication Date: 2025-08-05HANS LASER TECH IND GRP CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111546725.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-16
Publication Date
2025-08-05
Estimated Expiration
2041-12-16

AI Technical Summary

Technical Problem

In the prior art, all straight lines in the image are inefficient in detection and resource waste, so users cannot quickly and accurately obtain the straight lines they need.

Method used

By obtaining the to-process image of the target object and the rectangular detection box set by the user, the target image is cropped and a parallel straight line intersects with the edge contour, the target line corresponding to the target intersection point is obtained by using the least squares method.

Benefits of technology

It reduces the calculation amount of image processing, accurately obtains the straight lines needed by users, avoids waste of resources, and improves detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114359316B_ABST
    Figure CN114359316B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention discloses a straight line detection method, system, image processing device, and storage medium. The straight line detection method includes: obtaining a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, cropping the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtaining an edge contour of the target object according to the target image; generating a set of parallel straight lines according to two wide sides of the rectangular detection frame, the set of parallel straight lines being parallel to the two wide sides and having equal lengths; performing an intersection operation between the set of parallel straight lines and the edge contour to obtain an intersection point set, and selecting target intersection points in the intersection point set that meet a preset requirement; and obtaining a target straight line corresponding to the target intersection points by using the least squares method. The present invention can improve work efficiency and avoid waste of resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to a straight line detection method, system, image processing device, and storage medium. Background Art

[0002] In industrial applications, the detection of images with given shapes is a common type of problem, and straight line detection is one of the most common detection cases in shape images, such as the detection of the frames of mobile phones in the 3C industry, the detection of welding seams in sheet metal welding, and the edge detection of non-arc-shaped industrial parts, etc.

[0003] However, when currently performing straight line detection on an image, all the straight lines in the image are shown, and the user cannot quickly and accurately obtain the straight lines they need. Moreover, the resources and time consumed for calculating all the straight lines in the image are relatively large, not only with low efficiency but also prone to resource waste. Summary of the Invention

[0004] The technical problem to be solved by the present invention is that when all the straight lines in the image are shown, the user cannot quickly and accurately obtain the straight lines they need, which not only has low efficiency but is also prone to resource waste. In view of the above-mentioned defects of the prior art, a straight line detection method, system, image processing device, and storage medium are provided.

[0005] The technical solution adopted by the present invention to solve its technical problems is as follows: A straight line detection method includes the following steps:

[0006] Obtain a to-be-processed image including a target object and a rectangular detection frame set by the user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain the edge contour of the target object according to the target image;

[0007] Generate a set of parallel straight lines according to the two wide sides of the rectangular detection frame, and the set of parallel straight lines is parallel to the two wide sides and has the same length;

[0008] Perform an intersection operation on the set of parallel straight lines and the edge contour to obtain an intersection point set, and select target intersection points in the intersection point set that meet the preset requirements;

[0009] Use the least squares method to obtain the target straight line corresponding to the target intersection points.

[0010] Among them, the step of the user setting the rectangular detection frame for the to-be-processed image includes:

[0011] Obtain the rectangular parameters of the rectangular detection frame set by the user, and generate the rectangular detection frame according to the rectangular parameters. The rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame, as well as the length information and spacing information of the wide sides;

[0012] The step of generating a set of parallel lines according to the two wide sides of the rectangular detection frame includes:

[0013] Generating a set of equally spaced parallel lines according to the spacing information and the two wide sides.

[0014] Among them, the step of selecting target intersection points that meet the preset requirements from the intersection point set includes:

[0015] Calculating the distance between each intersection point and the starting point of the line where it is located, obtaining candidate intersection points that meet the preset requirements on each line, and the preset requirements include the maximum distance or the minimum distance;

[0016] Screening out the target intersection points from the candidate intersection points by using the maximum consensus sampling method.

[0017] Among them, the step of screening out the target intersection points from the candidate intersection points by using the maximum consensus sampling method includes:

[0018] Arbitrarily selecting two of the candidate intersection points to generate a candidate line, calculating the residuals between the remaining candidate intersection points and the candidate line, and taking the remaining candidate intersection points with residuals less than the preset residual threshold as the inliers of the candidate line;

[0019] Obtaining all candidate lines that can be generated by the candidate intersection points, obtaining the number of inliers and the inlier point set of each candidate line;

[0020] Taking the candidate intersection points in the inlier point set of the candidate line whose number of candidate inliers meets the preset requirements as the target intersection points;

[0021] Among them, the preset requirements include the maximum number of inliers or the proportion of the number of inliers to the number of candidate intersection points being greater than the preset proportion threshold.

[0022] Among them, the step of obtaining the edge contour of the target object from the target image includes:

[0023] Performing filtering processing and edge detection processing on the target image to obtain an edge image including the edge contour of the target object.

[0024] Among them, before the step of performing an intersection operation between the set of parallel lines and the edge contour, it includes:

[0025] Setting the gray values of the pixels in the edge image that are not in the area corresponding to the rectangular detection frame of the target image to 0, and obtaining the mask image of the target object.

[0026] After the step of obtaining the target line corresponding to the target intersection point by using the least squares method, the following steps are included:

[0027] Calculate the line intersection points of the target line and the rectangular detection frame, and obtain at least one of the starting point, midpoint, end point, fitting point array of the target line, and the angle with the X-axis according to the line intersection points.

[0028] The technical solution adopted by the present invention to solve its technical problems is: a line detection system, including the following modules:

[0029] An edge module, configured to obtain a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain the edge contour of the target object according to the target image;

[0030] A line module, configured to generate a set of parallel lines according to two wide sides of the rectangular detection frame, and the set of parallel lines is parallel to the two wide sides and has the same length;

[0031] An intersection module, configured to perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set, and select a target intersection point that meets a preset requirement from the intersection point set;

[0032] A target module, configured to obtain a target line corresponding to the target intersection point by using the least squares method.

[0033] The technical solution adopted by the present invention to solve its technical problems is: a computer device, including a memory and a processor, where the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the following steps:

[0034] Obtain a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain the edge contour of the target object according to the target image;

[0035] Generate a set of parallel lines according to two wide sides of the rectangular detection frame, and the set of parallel lines is parallel to the two wide sides and has the same length;

[0036] Perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set, and select a target intersection point that meets a preset requirement from the intersection point set;

[0037] Obtain a target line corresponding to the target intersection point by using the least squares method.

[0038] The technical solution adopted by the present invention to solve its technical problems is: a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to execute the following steps:

[0039] Obtain a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain an edge contour of the target object according to the target image;

[0040] Generate a set of parallel lines according to two wide sides of the rectangular detection frame, and the set of parallel lines is parallel to the two wide sides and has the same length;

[0041] Perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set, and select target intersection points in the intersection point set that meet a preset requirement;

[0042] Use the least squares method to obtain a target line corresponding to the target intersection points.

[0043] Compared with the prior art, the beneficial effects of a line detection method provided by an embodiment of the present invention are at least as follows: The line detection method can accurately obtain the lines of the target object by obtaining a to-be-processed image including the target object and a rectangular detection frame set by the user for the to-be-processed image, reducing the amount of computation for image processing. Generate a set of parallel lines according to two wide sides of the rectangular detection frame, perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set, and the intersection point set is located on the contour line of the target object. Select target intersection points in the intersection point set that meet a preset requirement, and the preset requirement can make the target intersection points located on the lines required by the user. Then use the least squares method to obtain the target line corresponding to the target intersection points, so that the lines required by the user can be selected and displayed from the contour edge of the target object without calculating the remaining lines, effectively reducing the amount of calculation and avoiding resource waste, and the user can also quickly and accurately obtain the required lines. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0045] Among them:

[0046] Figure 1 is a flowchart of a line detection method in an image in an embodiment of the present invention;

[0047] Figure 2 It is a schematic diagram of a rectangular detection frame in an embodiment of the present invention;

[0048] Figure 3 It is a schematic diagram of the positional relationship between a target image and a rectangular detection frame in an embodiment of the present invention;

[0049] Figure 4 It is a schematic diagram of a target image in an embodiment of the present invention;

[0050] Figure 5 It is a schematic diagram of a set of parallel lines in an embodiment of the present invention;

[0051] Figure 6 It is a schematic diagram of an intersection point set in an embodiment of the present invention;

[0052] Figure 7 It is a schematic flowchart of a line detection method in another embodiment of the present invention;

[0053] Figure 8 It is a schematic diagram of an edge image in an embodiment of the present invention;

[0054] Figure 9 It is a schematic diagram of a pickling film image in an embodiment of the present invention;

[0055] Figure 10 It is a schematic diagram of candidate intersection points in an embodiment of the present invention;

[0056] Figure 11 It is a schematic diagram of candidate intersection points in another embodiment of the present invention;

[0057] Figure 12 is Figure 10 A schematic diagram of the target intersection points and target lines corresponding to the candidate intersection points in;

[0058] Figure 13 is Figure 11 A schematic diagram of the target intersection points and target lines corresponding to the candidate intersection points in;

[0059] Figure 14 It is a schematic structural diagram of a line detection system in an embodiment of the present invention;

[0060] Figure 15 It is a schematic structural diagram of a computer device in an embodiment of the present invention;

[0061] Figure 16 It is a schematic structural diagram of a storage medium in an embodiment of the present invention. Specific embodiments

[0062] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0063] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of a method for detecting a straight line in an image in an embodiment of the present invention. The method for detecting a straight line in an image of the present invention includes the following steps:

[0064] S101: Obtain a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain the edge contour of the target object according to the target image.

[0065] In a specific implementation scenario, obtain a to-be-processed image including a target object. Since the to-be-processed image processing includes not only the target object but also interference contents such as the background and other objects. To reduce interference and the amount of computation, it is necessary to select the area corresponding to the target object. In this implementation scenario, the user sets a rectangular detection frame on the to-be-processed image so that the target object is located within the rectangular detection frame. Please refer to Figure 2 , Figure 2 which is a schematic diagram of a rectangular detection frame in an embodiment of the present invention. In this implementation scenario, an initial rectangular detection frame can be displayed on the to-be-processed image, and the user can drag the initial rectangular detection frame, or any one of the sides, vertices, and midpoints of the rectangular detection frame according to the shape of the target object and its position in the to-be-processed image, so as to change the position, size, and shape of the initial rectangular detection frame to obtain a target rectangular detection frame.

[0066] In this implementation scenario, cropping the to-be-processed image according to the rectangular detection frame to obtain a target image can be performed by cropping along the edge of the rectangular detection frame, or by obtaining the minimum bounding rectangle of the rectangular detection frame for cropping, where one of the long side and the short side of the minimum bounding rectangle is in the horizontal direction and the other is in the vertical direction. Please refer to Figure 3 , Figure 3 which is a schematic diagram of the positional relationship between the target image and the rectangular detection frame in an embodiment of the present invention, where the dashed box is the rectangular detection frame and the solid line box is the edge of the target image.

[0067] Crop the to-be-processed image according to the rectangular detection frame to obtain a target image. Please refer to Figure 4 , Figure 4It is a schematic diagram of the target image in an embodiment of the present invention. By performing edge detection on the target image, the edge contour of the target object can be obtained. In other implementation scenarios, in order to improve the accuracy of the contour, the target image can be subjected to Gaussian filtering and then edge detection. The operator for edge detection can be any one of Roberts, Sobel, Prewitt, Laplacian, Log / Marr, Canny, Kirsch, and Nevitia.

[0068] S102: Generate a set of parallel lines according to the two wide sides of the rectangular detection frame. The set of parallel lines is parallel to the two wide sides and has the same length.

[0069] In a specific implementation scenario, a set of parallel lines is generated according to the two wide sides of the rectangular detection frame. The set of parallel lines is parallel to the two wide sides and has the same length. The starting line and the ending line of the set of parallel lines are the two wide sides of the rectangular detection frame. Please refer to Figure 5 , Figure 5 It is a schematic diagram of a set of parallel lines in an embodiment of the present invention. The spacing between the parallel lines is equal and is set by the user.

[0070] S103: Perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set, and select the target intersection points that meet the preset requirements from the intersection point set.

[0071] In a specific implementation scenario, perform an intersection operation on the set of parallel lines and the edge contour to obtain an intersection point set. Please refer to Figure 6 , Figure 6 It is a schematic diagram of the intersection point set in an embodiment of the present invention. As can be seen from Figure 6 , there are some points in the intersection point set that are not on the line, and the lines on which the points in the intersection point set are located are not the same straight line. The user can set the screening conditions according to the desired line, so as to select the target intersection points from the intersection point set. For example, select the intersection points within the preset coordinate range as the target intersection points, or select the intersection points located on the same straight line as the target intersection points.

[0072] S104: Use the least squares method to obtain the target line corresponding to the target intersection points.

[0073] In a specific implementation scenario, use the least squares method to obtain the target line corresponding to the target intersection points. Obtain the target intersection point set (x i , y i ), i = 1, 2,... m, where m is the number of target intersection points. Assume the fitted line is y = kx + b, and calculate the parameters k and b in the fitted line according to the following formula.

[0074]

[0075]

[0076] In other implementation scenarios, for the convenience of users, after obtaining the target straight line, calculate the intersection points of the target straight line and the straight lines of the rectangular detection frame, and obtain at least one of the starting point, midpoint, end point, fitting point array of the target straight line, and the included angle with the X-axis according to the intersection points of the straight lines.

[0077] As can be seen from the above description, in this embodiment, obtaining the to-be-processed image including the target object and the rectangular detection frame set by the user for the to-be-processed image can accurately obtain the straight line of the target object, reduce the computational amount of image processing, generate a set of parallel straight lines according to the two wide sides of the rectangular detection frame, perform an intersection operation between the set of parallel straight lines and the edge contour to obtain an intersection point set, the intersection point set is located on the contour line of the target object, select the target intersection points that meet the preset requirements in the intersection point set, the target intersection points are located on the straight line required by the user, and use the least squares method to obtain the target straight line corresponding to the target intersection points, so that the straight line required by the user can be selected from the contour line of the target object and displayed, without calculating the remaining straight lines, effectively reducing the computational amount, avoiding resource waste, and the user can also quickly and accurately obtain the required straight line.

[0078] Please refer to Figure 7 , Figure 7 which is a schematic flowchart of the straight line detection method in another embodiment of the present invention. The straight line detection method of the present invention includes the following steps:

[0079] S201: Obtain the to-be-processed image including the target object.

[0080] In a specific implementation scenario, obtaining the to-be-processed image of the target object can be on-site shooting or downloading from the network.

[0081] S202: Obtain the rectangular parameters of the rectangular detection frame set by the user, and generate a rectangular detection frame according to the rectangular parameters. The rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame, as well as the length information and spacing information of the wide sides.

[0082] In a specific implementation scenario, please continue to refer to Figure 2 . As Figure 2 shown, V1, V2, V3, and V4 are the four vertices of the rectangular detection frame, P1 is the midpoint of V1V3, P2 is the midpoint of V2V4, P3 is the midpoint of V1V2, P4 is the midpoint of V3V4, P0 is the midpoint of the connection line of P1 and P2, and is also the midpoint of the connection line of P3 and P4. Among them, the distance from P0 to P3 or P0 to P4 is equal to the length L1, and the included angle Angle between the straight line connecting P1 and P2 and the X-axis, and the value range of Angle is from 0 to 360 degrees.

[0083] When the user sets a rectangular detection frame, it can be achieved by setting rectangular parameters. The rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame, as well as the length information and spacing information of the wide sides. That is Figure 2 the positions of points P1 and P2 and L1 in. When the coordinates of P1 and P2 are known and L1 is known, the value of Angle and the coordinates of P0, P3, P4, V1, V2, V3, and V4 can be calculated. Please refer to the following formulas:

[0084] Angle = atan2(p2 y - p1 y ),(p2 x - p1 x ). When Angle is less than 0, Angle = Angle + 360

[0085] p0 = [(p1 x + p2 x ) / 2, (p1 y + p2 y ) / 2]

[0086] p3 = [L1 * sin(Angle) + p0 x , - L1 * cos(Angle) + p0 y

[0087] p4 = [- L1 * sin(Angle) + p0 x , L1 * cos(Angle) + p0 y

[0088] V1 = [p1 x + p3 x - p0 x , p1 y + p3 y - p0 y

[0089] V2 = [p2 x + p3 x - p0 x , p2 y + p3 y - p0 y

[0090] V3 = [p1 x + p4 x - p0 x , p1 y + p4 y - p0 y

[0091] ​​​​​V4 = [p2 x + p4 x - p0 x , p2 y + p4 y - p0 y

[0092] S203: Crop the image to be processed according to the rectangular detection frame to obtain the target image, perform filtering processing and edge detection processing on the target image, and obtain an edge image including the edge contour of the target object. Set the gray value of the pixels in the edge image that are not in the area corresponding to the rectangular detection frame of the target image to 0, and obtain the mask image of the target object.

[0093] In a specific implementation scenario, crop the image to be processed according to the rectangular detection frame to obtain the target image, perform filtering processing and edge detection processing on the target image, and obtain an edge image including the edge contour of the target object. Please refer to Figure 8 , Figure 8 which is a schematic diagram of the edge image of an embodiment of the present invention. Set the gray value of the pixels in the edge image that are not in the area corresponding to the rectangular detection frame of the target image to 0. Please refer to Figure 9 , Figure 9 which is a schematic diagram of the mask image of an embodiment of the present invention. As shown in Figure 9 , the mask image includes the edge contour of the target object.

[0094] S204: Generate a set of equally spaced parallel lines according to the spacing information and two wide sides. Perform an intersection operation between the set of parallel lines and the edge contour to obtain an intersection point set.

[0095] In a specific implementation scenario, the rectangular parameters further include spacing information L2. The straight lines V1V3 and V2V4 are divided into (2 * L1) / L2 equal parts at an interval of L2 to generate a set of parallel lines. It is possible that (2 * L1) / L2 cannot be divided evenly, and still divide from V1 at an interval of L2. In this implementation scenario, take V1V3 as the starting straight line and the straight line V1V2 as the position where the starting point is located. In other implementation scenarios, V2V4 can also be used as the starting straight line, which is not limited here.

[0096] According to the coordinates of P0, P1, P2, P3, P4, V1, V2, V3, V4 and the values of L1 and L2, the starting point and midpoint coordinates of each straight line in the set of parallel lines can be obtained. Calculate the distance from the midpoint of each straight line in the set of parallel lines to P1, sort the parallel lines in ascending order according to this distance, and generate a straight line array. Perform an intersection operation between the straight line array and the edge contour to obtain at least one intersection point of each straight line and the edge contour, and generate an intersection point set.

[0097] ​S205: Calculate the distance between each intersection point and the starting point of the line it lies on, and obtain the candidate intersection points on each line that meet the preset requirements. The preset requirements include the maximum distance or the minimum distance.

[0098] In a specific implementation scenario, calculate the distance between each intersection point and the starting point of the line it lies on. The coordinates of the starting points of each line have been obtained in the above steps. According to Figure 6 it can be known that there can be multiple intersection points on each line, and these intersection points are also on different lines of the edge contour of the target object. The user can select candidate intersection points from the intersection points according to the line they need to obtain.

[0099] In this implementation scenario, obtain the distance between the intersection point and the starting point of the line it lies on, and use the intersection point with the maximum or minimum distance from the starting point on each line as the candidate intersection point. When selecting the point with the farthest distance as the candidate intersection point, please refer to Figure 10 , Figure 10 which is a schematic diagram of the candidate intersection points in an embodiment of the present invention. As Figure 10 shown in, select the point with the farthest distance as the candidate intersection point, and the candidate intersection point is located on the lower edge of the target object. When selecting the point with the closest distance as the candidate intersection point, please refer to Figure 11 , Figure 11 which is a schematic diagram of the candidate intersection points in another embodiment of the present invention. As Figure 11 shown in, select the point with the closest distance as the candidate intersection point, and the candidate intersection point is located on the upper edge of the target object.

[0100] S206: Use the maximum consensus sampling method to screen out the target intersection points from the candidate intersection points.

[0101] In a specific implementation scenario, refer to Figure 10 and Figure 11 it can be known that the candidate intersection points are not necessarily on the same line, and it is necessary to select the target intersection points located on the same line from the candidate intersection points. In this implementation scenario, the maximum consensus sampling method is used to screen out the target intersection points.

[0102] Obtain the candidate intersection point set (x i , y i ), i = 1, 2,... n, where n is the number of candidate intersection points. Randomly select 2 non-coincident points to generate a candidate line Ax + By + C = 0, and calculate the residual res i = Ax i + By i + C for each candidate intersection point. When res iWhen ≤ error, the candidate intersection point is considered an inlier on the candidate line, where error represents the inlier distance, i.e., the preset residual threshold, which can be set by the user and is recorded as the number of inliers and the inlier point set on the candidate line.

[0103] Repeat the above steps to obtain the candidate lines generated by every two candidate intersection points in the candidate intersection point set, as well as the number of inliers and the inlier point set for each candidate line. The candidate intersection point in the inlier point set corresponding to the candidate line with the largest number of inliers is taken as the target intersection point.

[0104] In an implementation scenario, when the number of inliers on a candidate line reaches a certain proportion N, the iterative operation can be terminated, which can improve the operation speed and save operation resources. Please refer to the following formula to obtain the iteration termination condition N:

[0105]

[0106] Where c represents the current number of inliers, and s represents the inlier proportion coefficient, ranging from 0 to 1.

[0107] S207: Use the least squares method to obtain the target line corresponding to the target intersection point.

[0108] In a specific implementation scenario, step S207 is basically the same as step S105 in the first embodiment of the line detection method of the present invention, and will not be elaborated here.

[0109] Please refer to Figure 12 and Figure 13 , Figure 12 is Figure 10 a schematic diagram of the target intersection point and the target line corresponding to the candidate intersection point in Figure 13 is Figure 11 a schematic diagram of the target intersection point and the target line corresponding to the candidate intersection point in

[0110] From the above description, it can be seen that in this embodiment, by calculating the distance between each intersection point and the starting point of the line where it is located, obtaining the candidate intersection points on each line that meet the preset requirements, and using the maximum consensus sampling method to screen the candidate intersection points to obtain the target intersection point, the points on the line required by the user can be accurately screened, facilitating the user to quickly obtain the target line.

[0111] Please refer to Figure 14 , Figure 14 which is a schematic structural diagram of the line detection system in an embodiment of the present invention. The line detection system 10 includes: an edge module 11, a line module 12, an intersection module 13, and a target module 14.

[0112] The edge module 11 is used to obtain a to-be-processed image including a target object and a rectangular detection frame set by a user for the to-be-processed image, crop the to-be-processed image according to the rectangular detection frame to obtain a target image, and obtain the edge contour of the target object according to the target image; the straight line module 12 is used to generate a set of parallel straight lines according to two wide sides of the rectangular detection frame, and the set of parallel straight lines is parallel to the two wide sides and has the same length; the intersection module 13 is used to perform an intersection operation on the set of parallel straight lines and the edge contour to obtain an intersection point set, and select target intersection points that meet preset requirements from the intersection point set; the target module 14 is used to obtain a target straight line corresponding to the target intersection points by using the least squares method.

[0113] The edge module 11 is further used to obtain the rectangular parameters of the rectangular detection frame set by the user, generate the rectangular detection frame according to the rectangular parameters, and the rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame, as well as the length information and spacing information of the wide sides. The straight line module 12 is further used to generate a set of equally spaced parallel straight lines according to the spacing information and the two wide sides.

[0114] The intersection module 13 is further used to calculate the distance between each intersection point and the starting point of the straight line where it is located, obtain candidate intersection points that meet preset requirements on each straight line, and the preset requirements include the maximum distance or the minimum distance; the target intersection points are screened out from the candidate intersection points by using the maximum consensus sampling method.

[0115] The intersection module 13 is further used to arbitrarily select two candidate intersection points to generate a candidate straight line, calculate the residuals between the remaining candidate intersection points and the candidate straight line, and use the remaining candidate intersection points with residuals less than a preset residual threshold as inliers of the candidate straight line; obtain all candidate straight lines that can be generated by the candidate intersection points, obtain the inlier quantity and inlier point set of each candidate straight line; use the candidate intersection points in the inlier point set of the candidate straight line with the inlier quantity meeting the preset requirements as the target intersection points; wherein, the preset requirements include the maximum inlier quantity or the proportion of the inlier quantity to the candidate intersection point quantity being greater than a preset proportion threshold.

[0116] The edge module 11 is further used to perform filtering processing and edge detection processing on the target image to obtain an edge image including the edge contour of the target object.

[0117] The edge module 11 is further used to set the gray values of the pixels in the edge image that are not located in the area corresponding to the rectangular detection frame of the target image to 0 to obtain a mask image of the target object.

[0118] The target module 14 is further used to calculate the straight line intersection points of the target straight line and the straight lines of the rectangular detection frame, and obtain at least one of the starting point, midpoint, end point, fitting point array, and the angle with the X-axis of the target straight line according to the straight line intersection points.

[0119] Please refer to Figure 15 , Figure 15It is a schematic structural diagram of a computer device in an embodiment of the present invention. The computer device 20 includes a processor 21 and a memory 22. The processor 21 is coupled to the memory 22. A computer program is stored in the memory 22, and when the processor 21 is working, it executes the computer program to implement as Figure 1 - Figure 2 the method shown. For the detailed method, reference can be made to the above, and it will not be elaborated here.

[0120] Please refer to Figure 16 , Figure 16 It is a schematic structural diagram of a storage medium in an embodiment of the present invention. At least one computer program 31 is stored in the storage medium 30, and the computer program 31 is used to be executed by a processor to implement as Figure 1 and Figure 2 the methods shown. For the detailed methods, reference can be made to the above, and it will not be elaborated here. In one embodiment, the computer-readable storage medium 30 can be a storage chip in a terminal, a hard disk, a mobile hard disk, a USB flash drive, an optical disc or other writable and readable storage tools, and can also be a server, etc.

[0121] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database or other medium used in the various embodiments provided in the present application can include non-volatile and / or volatile memories. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or an external cache. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0122] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.

[0123] The above embodiments only represent several implementation manners of the present application. The description thereof is relatively specific and detailed, but it should not be construed as a limitation to the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims. Please enter the specific implementation content part.

Claims

1. A straight line detection method, characterized in that: The steps include: Obtaining rectangular parameters set by the user, and generating a rectangular detection frame according to the rectangular parameters, wherein the rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame and the length information and spacing information of the wide sides; Acquire an image to be processed including a target object, crop the image to be processed according to the rectangular detection frame to acquire a target image, and acquire an edge contour of the target object according to the target image; generating a group of parallel straight lines with equal spacing according to the spacing information and the two broad sides, wherein the group of parallel straight lines are parallel to the two broad sides and have equal lengths; Intersecting the set of parallel straight lines with the edge contour to obtain a set of intersection points, calculating the distance between each intersection point and the starting point of the straight line on which it lies, and obtaining candidate intersection points on each straight line that meet preset requirements, wherein the preset requirements include a maximum distance or a minimum distance; arbitrarily selecting two candidate intersection points to generate a candidate line, calculating the residuals between the remaining candidate intersection points and the candidate line, and taking the remaining candidate intersection points whose residuals are less than a preset residual threshold as the interior points of the candidate line; Obtain all candidate lines that can be generated by the candidate intersection points, and obtain the number of interior points and the interior point set of each candidate line; The candidate intersection point in the inlier point set of the candidate line whose number of inliers meets a preset requirement is used as the target intersection point; wherein the preset requirement includes that the number of inliers is the largest or the ratio of the number of inliers to the number of candidate intersection points is greater than a preset ratio threshold; The target straight line corresponding to the target intersection point is obtained using the least squares method.

2. The straight line detection method according to claim 1, characterized in that: The step of acquiring the edge contour of the target object according to the target image comprises: The target image is subjected to filtering processing and edge detection processing to obtain an edge image including the edge contour of the target object.

3. The straight line detection method according to claim 2, characterized in that: Before the step of performing an intersection operation on the set of parallel straight lines and the edge contour, the method includes: The grayscale values of pixels in the edge image that are not located in the area corresponding to the rectangular detection frame of the target image are set to 0, and a mask image of the target object is obtained.

4. The straight line detection method according to claim 1, wherein: After the step of using the least squares method to obtain the target straight line corresponding to the target intersection point, the method includes: Calculate the intersection point of the target straight line and the straight line of the rectangular detection frame, and obtain at least one of the starting point, midpoint, end point, fitting point array, and angle with the X-axis of the target straight line according to the straight line intersection point.

5. A straight line detection system, characterized in that: Includes the following modules: an edge module configured to obtain rectangular parameters set by a user, generate a rectangular detection frame based on the rectangular parameters, wherein the rectangular parameters include the positions of the midpoints of the two wide sides of the rectangular detection frame and information about the length and spacing of the wide sides; obtain an image to be processed including a target object, crop the image to be processed based on the rectangular detection frame to obtain a target image, and obtain an edge contour of the target object based on the target image; a straight line module, configured to generate a set of parallel straight lines with equal spacing according to the spacing information and the two broad sides, wherein the set of parallel straight lines are parallel to the two broad sides and have equal lengths; An intersection module is used to perform an intersection operation on the set of parallel straight lines and the edge contour to obtain a set of intersection points, calculate the distance between each intersection point and the starting point of the straight line on which it is located, and obtain candidate intersection points on each straight line that meet preset requirements, wherein the preset requirements include the maximum distance or the minimum distance; arbitrarily select two of the candidate intersection points to generate a candidate straight line, calculate the residuals between the remaining candidate intersection points and the candidate straight line, and use the remaining candidate intersection points whose residuals are less than a preset residual threshold as the inliers of the candidate straight line; obtain all candidate straight lines that can be generated by the candidate intersection points, obtain the number of inliers and the inlier point set of each candidate straight line; use the candidate intersection points in the inlier point set of the candidate straight line whose number of inliers meets the preset requirements as the target intersection point; wherein the preset requirements include the maximum number of inliers or the ratio of the number of inliers to the number of candidate intersection points being greater than a preset ratio threshold; The target module is used to obtain the target straight line corresponding to the target intersection point by using the least square method. 6 . An image processing device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the steps of the method according to claim 1 .

7. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Rotary robust three-dimensional object detection optimization method and device

    CN111028264A

  • Image processing device, image processing method, and computer program product

    US20190087962A1