A method for extracting line segment endpoints
By extracting line segment endpoints through image processing methods, the inefficiency of wiring error checking in circuit experiments is solved, and efficient and accurate endpoint extraction and feature point extraction in complex situations are achieved.
Patent Information
- Application Number
- CN202210248088.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-14
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2042-03-14
AI Technical Summary
The existing technology lacks effective image processing methods for checking equipment wiring errors or omissions in circuit experiments, resulting in low inspection efficiency.
By processing the image, the maximum contour area is obtained, the coordinate difference of adjacent areas on the contour line is calculated to determine the direction, noise reduction and dislocation processing are performed, the turning point position is expanded, the position where the x-axis and/or y-axis direction changes is found, and the turning point is selected in the overlapping part to mark and extract the endpoint.
It realizes efficient and accurate extraction of line segment endpoints, can extract convex and concave points in complex situations, and improves the efficiency and accuracy of wiring inspection.
Smart Images

Figure CN114792376B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a method for extracting line segment endpoints. Background Art
[0002] OpenCV is a cross-platform computer vision and machine learning software library that can run on Linux, Windows, Android, and Mac OS operating systems. It is lightweight and efficient, consisting of a series of C functions and a small number of C++ classes. It also provides interfaces for languages such as Python, Ruby, and MATLAB, and implements many common algorithms in image processing and computer vision.
[0003] In some electrical circuit experiments, there are many devices that are connected by wires. Since there are many wiring points on the equipment, wiring errors or omissions often occur, which will have a great impact on the experiment. Therefore, it is necessary to check the wiring position. In order to improve the efficiency and accuracy of the inspection, the use of image processing can well achieve the above purpose. However, there is currently no corresponding image processing method in technology. Summary of the Invention
[0004] The purpose of the present invention is to provide a line segment endpoint extraction method to achieve the extraction and marking of the endpoints of the wire portion in an image.
[0005] To solve the above technical problems, the present invention provides a line segment endpoint extraction method, comprising:
[0006] Process the image to obtain the maximum contour area;
[0007] Calculate the coordinate difference of adjacent areas on the contour line to determine the contour direction;
[0008] Perform noise reduction and dislocation processing to obtain turning points;
[0009] Expanding the location area of the turning point;
[0010] Find the location where the x-axis and / or y-axis direction changes; and
[0011] Select one of the turning points in the overlapping part and mark it. The marked turning point is the endpoint.
[0012] Optionally, the step of processing the image to obtain the maximum contour area includes: binarizing the image to obtain a black and white image, extracting the contour of the wire portion, wherein the contour is presented as a closed curve, and selecting the largest contour area;
[0013] Optionally, before binarizing the image to obtain a black and white image, the following steps may be performed:
[0014] Convert the image into grayscale and get the structural element;
[0015] The obtained grayscale image is subjected to a processing process including dilation-erosion-dilation.
[0016] Optionally, in the step of calculating the coordinate difference between adjacent areas on the contour line to determine the contour direction, the direction is represented according to the slope or difference of the adjacent areas.
[0017] Optionally, the contour direction is determined by selecting two adjacent areas or two areas with the same spacing.
[0018] Optionally, the noise reduction process includes: modifying the directions of the coordinates of adjacent regions on the x-axis and the y-axis to keep them consistent with the front and back directions.
[0019] Optionally, the modifying the direction includes: when encountering a noise area that needs to be changed, modifying the direction data of the noise area into data of a previous area or a next area.
[0020] Optionally, the misalignment processing includes: calculating the absolute value of the misalignment difference of the coordinate difference (|ΔX n -ΔX n-i |,|ΔY n -ΔY n-i |), where 1≤i≤n, and determine the turning point from the misalignment difference.
[0021] Optionally, select an integer to expand the turning point location area, and the integer varies depending on the diameter of the target line in the image.
[0022] Optionally, the method of expanding the position area includes: expanding the area of the turning point to both sides to find the overlapping part, or determining a convolution range to find the overlapping part.
[0023] The present invention provides a method for extracting line segment endpoints, comprising: processing an image to obtain the maximum contour area; calculating the coordinate difference between adjacent areas on the contour line to determine the contour direction; performing noise reduction and misalignment processing to obtain turning points; expanding the area where the turning points are located; finding the area where the x-axis and / or y-axis direction changes; and selecting one of the turning points in the overlapping portion and marking it, with the marked turning point being the endpoint. Thus, the present invention facilitates the extraction of the positions of the two endpoints of a line segment. Furthermore, the present invention can also extract convex and concave points in more complex situations (such as when two line segments intersect). BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A schematic flow chart of a line segment endpoint extraction method according to an embodiment of the present invention;
[0025] Figure 2 A schematic diagram of contour generation for one embodiment of the present invention;
[0026] Figure 3 A schematic diagram of contour area marking generation according to an embodiment of the present invention;
[0027] Figure 4 ΔX is an embodiment of the present invention n Schematic diagram of the distribution of the values of ;
[0028] Figure 5 ΔX after noise reduction according to an embodiment of the present invention n Schematic diagram of the distribution of the values of ;
[0029] Figure 6 Schematic diagram of the x-axis turning point and the y-axis turning point obtained after the misalignment process according to one embodiment of the present invention;
[0030] Figure 7 This is a schematic diagram of an enlarged x-axis turning point and a y-axis turning point according to an embodiment of the present invention;
[0031] Figure 8 This is a schematic diagram of endpoint marking according to an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The present invention will be described in more detail below with reference to schematic diagrams, which illustrate preferred embodiments of the present invention. It should be understood that those skilled in the art may modify the present invention as described herein while still achieving the advantageous effects of the present invention. Therefore, the following description should be understood as a general guide for those skilled in the art and not as a limitation of the present invention.
[0033] The present invention is described in more detail in the following paragraphs by way of example with reference to the accompanying drawings. The advantages and features of the present invention will become more apparent from the following description and claims. It should be noted that the drawings are greatly simplified and not to exact scale, and are provided solely for the purpose of assisting in the description of the embodiments of the present invention.
[0034] Please refer to Figure 1 , an embodiment of the present invention provides a line segment endpoint extraction method, comprising:
[0035] S101, processing the image to obtain the maximum contour area;
[0036] S102, calculating the coordinate difference of adjacent areas on the contour line to determine the contour direction;
[0037] S103, performing noise reduction and dislocation processing to obtain a turning point;
[0038] S104, expanding the location area of the turning point;
[0039] S105, finding a location area where the x-axis and / or y-axis directions change; and
[0040] S106: Select one of the turning points in the overlapping portion and mark it. The marked turning point is the endpoint.
[0041] Through the above process, the present invention can conveniently find the endpoint positions of line segments, and can also realize the extraction of convex points and concave points in more complex situations (such as the intersection of two line segments).
[0042] The method of the present invention is described in detail below:
[0043] In S101, the image is imported, read, converted into a grayscale image, and a structural element is obtained. Then, the grayscale image is subjected to a dilation-erosion-dilation process, and the image is binarized to obtain a black and white image. Figure 2 shown.
[0044] For example, the function {cv2.findContours()} is input to extract the contour of the wire portion. In the embodiment of the present invention, the contour refers to the line at the intersection of black and white in the black and white image, and the contour is presented as a closed curve.
[0045] We can use the input function {cv2.contourArea()} to calculate the contour area to select the largest contour area.
[0046] It should be noted that the description of the functions in the present invention is mainly for illustration, and those skilled in the art can select other functions that can realize the corresponding functions according to actual needs, which are all included in the concept of the present invention.
[0047] In S102, for example, the coordinates of the contour area on the x-axis and y-axis are obtained by inputting the function {cv2.findContours()}, and the coordinates are recorded as (X0, Y0), (X1, Y1), (X2, Y3) ... (X n , Y n ), where each coordinate can be set with a serial number, such as Figure 3 The 6 numbers shown represent 6 coordinates.
[0048] Calculate the coordinate difference (X n -X n-i , Y n -Y n-i ), where 1≤i≤n, denoted as (ΔX n , ΔY n), it should be noted that (ΔX n , ΔY n ) is only for the convenience of recording and does not represent the ΔX n is the horizontal axis and ΔY n For the points with ordinates, we need to pay attention to the 0th position (X0, Y0) and the last position (X n , Y n ) are adjacent, so the last item of the coordinate difference is (X n -X0,Y n -Y0),
[0049] For example, taking i=1 as an example, the specific example is:
[0050] ΔX n : -1, -1, -1, -1, ..., 0, 0, 0, ..., -1, -1, -1, -1, ...;
[0051] ΔY n : -1, -1, -1, -1, …, 0, 0, 0, …, -1, -1, -1, -1, ….
[0052] like Figure 4 In the figure, a portion of ΔX is schematically shown. n In actual operation, colors can be used to distinguish them, for example, red represents "-1", blue represents "0", and green represents "1".
[0053] It is understandable that ΔX n and ΔY n The value of can also be other than just "1", "0" and "-1".
[0054] In S103, the noise reduction process includes: modifying the directions of the coordinates of adjacent regions on the x-axis and the y-axis to keep them consistent with the front and back directions.
[0055] In a specific implementation, the noise reduction processing method is to convert (ΔX n , ΔY n ) is modified to 1 or -1, that is, when encountering a noise area that needs to be changed, the direction data of the noise area is modified to the data of the previous area or the next area. It can be understood that when ΔX n and ΔY n When the value of can be other, the modification page can be changed to other values.
[0056] For example, after noise reduction:
[0057] ΔX n: -1, -1, -1, -1, ..., 1, 1, 1, ..., -1, -1, -1, -1, ...;
[0058] ΔY n : -1, -1, -1, -1,......,1, 1, 1,......, -1, -1, -1, -1,.......
[0059] like Figure 5 In the figure, the noise reduction ΔX is schematically shown. n In actual operation, colors can also be used to distinguish them.
[0060] In S103, the misalignment processing includes: calculating the absolute value of the misalignment difference of the coordinate difference (|ΔX n -ΔX n-i |,|ΔY n -ΔY n-i |), and determine the turning point from the misalignment difference.
[0061] Taking i=1 as an example, the obtained misalignment differences include (0, 0), (0, 2), (2, 0) and (2, 2).
[0062] For example, specifically:
[0063] |ΔX n -ΔX n-1 |:0,0,0,0,0,......,0,0,2,0,0,0,0,0,0,0,......;
[0064] |ΔY n -ΔY n-1 |:0,0,0,0,2,......,0,0,0,0,0,0,2,0,0,.......
[0065] In one embodiment, for example, the specific position of the turning point can be found: the positions with misalignment difference values of (0, 2), (2, 0) and (2, 2) are turning points, where the misalignment difference value of (0, 2) indicates the position where the y-axis turns, the misalignment difference value of (2, 0) indicates the position where the x-axis turns, and the misalignment difference value of (2, 2) indicates the position where both the x-axis and the y-axis turn at the same time.
[0066] like Figure 6 , the x-axis turning point and the y-axis turning point obtained after the misalignment treatment are schematically shown.
[0067] In S104, the location area of the turning points can be expanded by selecting a certain integer, for example, selecting 3 forward and backward, and the integer (such as "3") is different due to the different diameters of the target lines in the image.
[0068] In a specific implementation, the operation is:
[0069] Will
[0070] |ΔX n -ΔX n-1 |:......,0,0,0,0,2,0,0,0,0,0,......;
[0071] |ΔY n -ΔY n-1 |:......,0,0,0,0,0,2,0,0,0,......;
[0072] Transformed into
[0073] |ΔX n -ΔX n-1 |:......,0,2,2,2,2,2,2,2,0,......;
[0074] |ΔY n -ΔY n-1 |:......,0,0,2,2,2,2,2,2,2,2,.......
[0075] That is, expand the absolute value of the difference to "2" by 3 before and after, and expand it to "2".
[0076] like Figure 7 In the figure, the situation after the x-axis turning point and the y-axis turning point are enlarged is shown schematically.
[0077] In S105, according to the overlapping position, for example (|ΔX n -ΔX n-1 |,|ΔY n -ΔY n-1 The value of |) is (2, 2), and the location area where the directions of the x-axis and y-axis change at the same time is found, or the location area of the x-axis or y-axis turning point is used separately according to the specific target task.
[0078] In S106, by filtering the positions of redundant turning points, one of the turning points in the overlapping part is selected for marking, and the marked turning point is the endpoint, such as Figure 8 As shown, the points with coordinates of number 914 and number 2024 are the endpoints.
[0079] In summary, the present invention provides a method for extracting line segment endpoints, comprising: processing an image to obtain a maximum contour area; calculating the coordinate difference between adjacent areas on the contour line to determine the contour direction; performing noise reduction and misalignment processing to obtain turning points; expanding the location area of the turning points; finding the location area where the x-axis and / or y-axis direction changes; and selecting one of the turning points in the overlapping portion for marking, where the marked turning point is the endpoint. The present invention can determine the location of the turning point based on the misalignment difference, and screen the turning points according to the actual target requirements, thereby obtaining the endpoints of the line segments and the convex and concave points of the intersecting line segments.
[0080] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.
Claims
1. A line segment endpoint extraction method, characterized in that: include: Process the image to obtain the maximum contour area; Calculate the coordinate difference of adjacent areas on the contour line to determine the contour direction; Performing noise reduction and misalignment processing to obtain a turning point, wherein the misalignment processing includes: calculating an absolute value of a misalignment difference of coordinate differences (|ΔXn-ΔXn-i|, |ΔYn-ΔYn-i|), where 1≤i≤n, and determining a turning point from the misalignment difference; Expanding the location area of the turning point; Find the location where the x-axis and / or y-axis direction changes; and Select one of the turning points in the overlapping part and mark it. The marked turning point is the endpoint.
2. A line segment endpoint extraction method according to claim 1, characterized in that: The step of processing the image to obtain the maximum contour area includes: binarizing the image to obtain a black and white image, extracting the contour of the wire portion, where the contour appears as a closed curve, and selecting the largest contour area.
3. A line segment endpoint extraction method according to claim 2, characterized in that: Before binarizing the image to obtain a black and white image, the following steps are also included: Convert the image into grayscale and obtain the structural element; The obtained grayscale image is subjected to a processing process including dilation-erosion-dilation.
4. A line segment endpoint extraction method according to claim 2, characterized in that: In the step of calculating the coordinate difference between adjacent areas on the contour line to determine the contour direction, the adjacent areas are represented according to the slope or difference.
5. A line segment endpoint extraction method according to claim 4, characterized in that: To determine the contour direction, select two adjacent areas, or two areas with the same spacing.
6. A line segment endpoint extraction method according to claim 1, characterized in that: The noise reduction process includes: modifying the directions of the coordinates of adjacent regions on the x-axis and the y-axis to keep them consistent with the front and back directions.
7. A line segment endpoint extraction method according to claim 6, characterized in that: The modifying of the directions of the coordinates of adjacent regions on the x-axis and the y-axis includes: when encountering a noise region that needs to be changed, modifying the direction data of the noise region into data of a previous region or a next region.
8. A line segment endpoint extraction method according to claim 1, characterized in that: Select an integer to expand the turning point location area. The integer varies depending on the diameter of the target line in the image.
9. A line segment endpoint extraction method according to claim 1, characterized in that: Ways to expand the location area include: expanding the area of the turning point to both sides to find the overlapping part, or determining a convolution range to find the overlapping part.
Citation Information
Patent Citations
Zigzag road information extraction and representation method based on aerial view field
CN110210298A
Triangular mesh model generation method and device
CN110706351A