Frame extraction method and device, vehicle and readable storage medium

By conducting straight line detection and clustering of target images in autonomous driving perception, and combining the weight value of the straight line cluster, the border is determined, which solves the problems of large amount of calculation and inefficiency in the prior art, and efficient border extraction is achieved.

CN120182944APending Publication Date: 2025-06-20CHONGQING CHANGAN AUTOMOBILE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311771226.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-20
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

When the prior art performs border recognition in autonomous driving perception, the calculation amount is large, and repeated inefficient calculations account for a large proportion, resulting in inefficient border extraction efficiency.

Method used

By performing straight line detection on the target image, horizontal straight line segments and vertical straight line segments are selected, and clustered based on these straight line segments to obtain straight line clusters. Then, the border of the target image is determined based on the weight value of the straight line cluster.

Benefits of technology

Reduces unnecessary repeated calculations, reduces computing resource overhead, and improves the efficiency and accuracy of border extraction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120182944A_ABST
    Figure CN120182944A_ABST
Patent Text Reader

Abstract

The invention relates to a frame extraction method and device, a vehicle and a readable storage medium, and is applied to the technical field of automatic driving. The method comprises the following steps: performing straight line detection on a target image to obtain a first straight line segment in the target image; determining a horizontal straight line segment and a vertical straight line segment in the first straight line segment based on the inclination angle of the first straight line segment; determining a horizontal straight line cluster corresponding to the horizontal straight line segment and a vertical straight line cluster corresponding to the vertical straight line segment; determining a first weight value of the horizontal straight line cluster and a second weight value of the vertical straight line cluster; according to the first weight value, determining a target horizontal straight line cluster corresponding to the target image, and according to the second weight value, determining a target vertical straight line cluster corresponding to the target image; and determining a frame of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster. According to the embodiment of the invention, under the condition that the frame extraction accuracy is ensured, the computing resource overhead for frame extraction is reduced, and the frame extraction efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of autonomous driving, and particularly to a method and device for extracting a border, a vehicle, and a readable storage medium. Background Art

[0002] In the field of autonomous driving, computer vision is one of the important technologies for a vehicle to perceive the external environment, and it has a large number of applications in aspects such as autonomous driving perception, positioning, and map making. In the process of recognizing traffic lights and rectangular signs in an image collected by a front-view camera of a vehicle, it is usually necessary to perform border recognition on traffic signs such as traffic lights and rectangular signs in the image.

[0003] Currently, after an image is collected by a camera installed in a vehicle, it is usually necessary to search and optimize all the line segment endpoints in the rectangular edge feature map of the image and compare weights, and update the preset line segments to optimize the rectangular border of the rectangular edge feature map.

[0004] However, in the process of border recognition in related technologies, key information needs to be preset, and all the line segment endpoints in the rectangular edge feature map need to be searched, resulting in a large amount of calculation, a relatively large proportion of repetitive and inefficient calculations, and low efficiency in border extraction. Summary of the Invention

[0005] One of the purposes of the present invention is to provide a method for extracting a border to solve the problems of large calculation amount, relatively large proportion of repetitive and inefficient calculations, and low efficiency in border extraction in the process of border recognition in the prior art; the second purpose is to provide a device for extracting a border; the third purpose is to provide a vehicle; the fourth purpose is to provide a readable storage medium.

[0006] To achieve the above purposes, the technical solutions adopted by the present invention are as follows:

[0007] A method for extracting a border, the method comprising:

[0008] Performing line detection on a target image to obtain first line segments in the target image;

[0009] Determining the inclination angle of the first line segments, and based on the inclination angle, determining horizontal line segments and vertical line segments in the first line segments;

[0010] Determining a horizontal line cluster corresponding to the horizontal line segments and a vertical line cluster corresponding to the vertical line segments; the horizontal line cluster is a line cluster determined with the horizontal line segments as the central line segments, and the vertical line cluster is a line cluster determined with the vertical line segments as the central line segments;

[0011] Determine the first weight value of the horizontal straight line clusters and the second weight value of the vertical straight line clusters;

[0012] According to the first weight value, determine the target horizontal straight line clusters corresponding to the target image, and according to the second weight value, determine the target vertical straight line clusters corresponding to the target image;

[0013] Based on the target horizontal straight line clusters and the target vertical straight line clusters, determine the border of the target image.

[0014] According to the above technical means, in the process of extracting the border of the target image, first, based on the inclination angles of the first straight line segments in the target image, filter out the horizontal and vertical straight line segments in the first straight line segments. Then, based on the horizontal and vertical straight line segments, cluster each of the first straight line segments to obtain horizontal straight line clusters and vertical straight line clusters. Finally, according to the first weight values of the horizontal straight line clusters and the second weight values of the vertical straight line clusters, determine the target horizontal straight line clusters and the target vertical straight line clusters corresponding to the target image, and further determine the border of the target image. While ensuring the accuracy of the border extraction of the target image, after screening and clustering the first straight line segments in the target image, and then further determining the border of the target image based on the target horizontal straight line clusters and the target vertical straight line clusters obtained after clustering, a large amount of unnecessary repeated calculations are reduced, the computational resource overhead for extracting the border of the target image is reduced, and the efficiency of border extraction is improved.

[0015] Further, the determining the horizontal straight line clusters corresponding to the horizontal straight line segments includes:

[0016] Determine the first horizontal straight line where the target horizontal straight line segment is located; the target horizontal straight line segment is any horizontal straight line segment in the first straight line segments;

[0017] Determine the first distance and the second distance from the two endpoints of the first horizontal straight line segment in the first straight line segments to the first horizontal straight line;

[0018] In the case where both the first distance and the second distance are less than the first preset threshold, determine that the first horizontal straight line segment belongs to the horizontal straight line cluster with the first horizontal straight line as the central straight line.

[0019] According to the above technical means, cluster the first horizontal straight line segments according to the first distance and the second distance from the two endpoints of the first horizontal straight line segments in the first straight line segments to the first horizontal straight line where the target horizontal straight line segment is located, so as to cluster the horizontal straight line segments in the first straight line segments to obtain horizontal straight line clusters with each horizontal straight line segment as the central straight line segment. Moreover, the determination process of the first distance and the second distance is simple, making the clustering method based on the first distance and the second distance easy to implement.

[0020] Furthermore, determining the first weight value of the horizontal straight line cluster includes:

[0021] Determine the second horizontal straight line corresponding to the horizontal straight line cluster; the horizontal straight line cluster is a straight line cluster determined with the second horizontal straight line as the central straight line;

[0022] Determine the projection lengths of the horizontal straight line segments in the horizontal straight line cluster on the second horizontal straight line;

[0023] Determine the third distance and the fourth distance from the two endpoints of each horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line;

[0024] Calculate the first sum value of the third distance and the fourth distance corresponding to each horizontal straight line segment in the horizontal straight line cluster;

[0025] Calculate the ratio of the projection length and the first sum value corresponding to each horizontal straight line segment in the horizontal straight line cluster;

[0026] Calculate the average value of the ratios corresponding to each horizontal straight line segment in the horizontal straight line cluster, and determine the average value as the first weight value of the horizontal straight line cluster.

[0027] According to the above technical means, by determining the projection lengths of the horizontal straight lines in the horizontal straight line cluster on the second horizontal straight line corresponding to the horizontal straight line cluster and the third distance and the fourth distance from the two endpoints of each horizontal straight line segment to the second horizontal straight line, the calculation of the first weight value of the horizontal straight line cluster can be realized, and the data for calculating the first weight value is easy to obtain, improving the feasibility of the embodiments of the present invention.

[0028] Furthermore, the target horizontal straight line cluster includes a first horizontal straight line cluster and a second horizontal straight line cluster; the target vertical straight line cluster includes a first vertical straight line cluster and a second vertical straight line cluster;

[0029] Determining the target horizontal straight line cluster corresponding to the target image according to the first weight value and determining the target vertical straight line cluster corresponding to the target image according to the second weight value includes:

[0030] Determine the center point of the target image;

[0031] Based on the center point, determine the horizontal straight line cluster corresponding to the maximum value of the first weight value in the horizontal straight line clusters located above the center point as the first horizontal straight line cluster;

[0032] Determine the horizontal straight line cluster corresponding to the maximum value of the first weight value in the horizontal straight line clusters located below the center point as the second horizontal straight line cluster;

[0033] Determine the first vertical line cluster as the vertical line cluster corresponding to the maximum value of the first weight value among the vertical line clusters located on the left side of the center point;

[0034] Determine the second vertical line cluster as the vertical line cluster corresponding to the maximum value of the first weight value among the vertical line clusters located on the right side of the center point.

[0035] According to the above technical means, based on the relative positions of the horizontal line clusters and the vertical line clusters with respect to the center point of the target image, determine the line cluster corresponding to the maximum value of the weight value in each relative position as the target line cluster, which improves the representativeness of the target line cluster, and further improves the accuracy of the border of the target image determined based on the target horizontal line cluster and the target vertical line cluster.

[0036] Further, the determining the border of the target image based on the target horizontal line cluster and the target vertical line cluster includes:

[0037] Determine the first target horizontal line corresponding to the first horizontal line cluster and the second target horizontal line corresponding to the second horizontal line cluster;

[0038] Determine the first target vertical line corresponding to the first vertical line cluster and the second target vertical line corresponding to the second vertical line cluster;

[0039] Determine the border formed by the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line as the border of the target image.

[0040] According to the above technical means, determine the border formed by the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line as the border of the target image, which ensures the integrity of determining the border of the target image.

[0041] Further, the method further includes:

[0042] Obtain the edge points corresponding to the edge region of the target image;

[0043] Respectively determine a first set of edge points corresponding to the first target horizontal line, a second set of edge points corresponding to the second target horizontal line, a third set of edge points corresponding to the first target vertical line, and a fourth set of edge points corresponding to the second target vertical line from the edge points; wherein, the distance between the edge points in the first set of edge points and the first target horizontal line, the distance between the edge points in the second set of edge points and the second target horizontal line, the distance between the edge points in the third set of edge points and the first target vertical line, and the distance between the edge points in the fourth set of edge points and the second target vertical line are all less than a second preset threshold;

[0044] Perform linear fitting on the first edge point set, the second edge point set, the third edge point set, and the fourth edge point set respectively to obtain the first target horizontal line after fitting, the second target horizontal line after fitting, the first target vertical line after fitting, and the second target vertical line after fitting;

[0045] Determine the border formed by the first target horizontal line after fitting, the second target horizontal line after fitting, the first target vertical line after fitting, and the second target vertical line after fitting as the border of the target image.

[0046] According to the above technical means, based on the edge points corresponding to the edge region of the target image, further fitting and correction are performed on the first target horizontal line, the second target horizontal line corresponding to the target horizontal line cluster, and the first target vertical line, the second target vertical line corresponding to the target vertical line cluster, further improving the accuracy of the border of the target image.

[0047] Further, the determining the horizontal line segment and the vertical line segment in the first line segment based on the inclination angle includes:

[0048] When the inclination angle falls within a first preset angle range, determine the first line segment corresponding to the inclination angle as the horizontal line segment;

[0049] When the inclination angle falls within a second preset angle range, determine the first line segment corresponding to the inclination angle as the vertical line segment.

[0050] According to the above technical means, an optional implementation manner for determining the horizontal line segment and the vertical line segment in the first line segment is provided, which improves the flexibility of the implementation manner of the embodiments of the present invention while realizing the screening of the first line segment based on the inclination angle of the first line segment in the target image.

[0051] A border extraction device, the device includes:

[0052] A line detection module, configured to perform line detection on a target image to obtain a first line segment in the target image;

[0053] A first determination module, configured to determine the inclination angle of the first line segment, and based on the inclination angle, determine the horizontal line segment and the vertical line segment in the first line segment;

[0054] A second determination module, configured to determine a horizontal straight line cluster corresponding to the horizontal straight line segment and a vertical straight line cluster corresponding to the vertical straight line segment; the horizontal straight line cluster is a straight line cluster determined with the horizontal straight line segment as the central straight line segment, and the vertical straight line cluster is a straight line cluster determined with the vertical straight line segment as the central straight line segment;

[0055] A third determination module, configured to determine a first weight value of the horizontal straight line cluster and a second weight value of the vertical straight line cluster;

[0056] A fourth determination module, configured to determine a target horizontal straight line cluster corresponding to the target image according to the first weight value, and determine a target vertical straight line cluster corresponding to the target image according to the second weight value;

[0057] A fifth determination module, configured to determine a border of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster.

[0058] According to the above technical means, the border extraction device first filters out the horizontal straight line segments and vertical straight line segments in the first straight line segments based on the inclination angles of the first straight line segments in the target image, and then clusters each of the first straight line segments based on the horizontal straight line segments and vertical straight line segments to obtain a horizontal straight line cluster and a vertical straight line cluster. Finally, according to the first weight value of each horizontal straight line cluster and the second weight value of each vertical straight line cluster, a target horizontal straight line cluster corresponding to the target image and a target vertical straight line cluster corresponding to the target image are determined, and further the border of the target image is determined. While ensuring the accuracy of the border extraction of the target image, the first straight line segments in the target image are filtered and clustered, and then the border of the target image is determined based on the target horizontal straight line cluster in the horizontal straight line cluster and the target vertical straight line cluster in the vertical straight line cluster obtained after clustering, reducing a large amount of unnecessary repeated calculations, reducing the computational resource overhead for extracting the border of the target image, and improving the efficiency of border extraction.

[0059] A vehicle, the vehicle includes an electronic device, the electronic device includes a memory and a processor, the memory is used to store a computer program, the processor is used to call and run the computer program stored in the memory, and when the processor executes the computer program, the border extraction method described in any one of the above is implemented.

[0060] A readable storage medium, the readable storage medium stores a computer program, and when the computer program is executed by a processor, the border extraction method described in any one of the above is implemented.

[0061] Advantages of the present invention:

[0062] In the process of extracting the border of the target image, the present invention first screens out the horizontal and vertical line segments in the first line segments based on the inclination angles of the first line segments in the target image. Then, based on the horizontal and vertical line segments, each first line segment is clustered to obtain a horizontal line cluster and a vertical line cluster. Finally, according to the first weight value of each horizontal line cluster and the second weight value of each vertical line cluster, the target horizontal line cluster and the target vertical line cluster corresponding to the target image are determined, and then the border of the target image is determined. While ensuring the accuracy of the border extraction of the target image, the first line segments in the target image are screened and clustered, and then the border of the target image is determined based on the target horizontal line cluster and the target vertical line cluster obtained after clustering, reducing a large amount of unnecessary repeated calculations, reducing the computational resource overhead for extracting the border of the target image, and improving the efficiency of border extraction. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1 It is a flowchart of the steps of a border extraction method provided by an embodiment of the present invention;

[0064] Figure 2 It is a schematic diagram of a target image provided by an embodiment of the present invention;

[0065] Figure 3 It is a flowchart of the steps of another border extraction method provided by an embodiment of the present invention;

[0066] Figure 4 It is a schematic diagram of another target image provided by an embodiment of the present invention;

[0067] Figure 5 It is a schematic diagram of the relationship between the horizontal line segments and the horizontal line in a horizontal line cluster provided by an embodiment of the present invention;

[0068] Figure 6 It is a schematic diagram of the relationship between the vertical line segments and the vertical line in a vertical line cluster provided by an embodiment of the present invention;

[0069] Figure 7 It is a schematic diagram of determining the border of the target image provided by an embodiment of the present invention;

[0070] Figure 8 It is a schematic diagram of correcting the target vertical line by fitting edge points provided by an embodiment of the present invention;

[0071] Figure 9 It is a logic block diagram of a border extraction device provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0072] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention, rather than for limiting the protection scope of the present invention.

[0073] It should be noted that the diagrams provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner. Therefore, only the components related to the present invention are shown in the diagrams, rather than being drawn according to the number, shape, and size of the components in actual implementation. The type, quantity, and proportion of each component in actual implementation can be arbitrarily changed, and the component layout type may also be more complex.

[0074] Method Embodiment

[0075] Refer to Figure 1 , which shows a flowchart of the steps of a border extraction method provided by an embodiment of the present invention. The method includes steps S110 to S160:

[0076] The border extraction method provided by an embodiment of the present invention can be applied to an electronic device in a vehicle for high-precision map construction. The vehicle can be any vehicle supporting the autonomous driving function, and the electronic device is an electronic device with data processing function in the vehicle. After determining the border of the target image through steps S110 to S160, the electronic device can reconstruct the target object corresponding to the target image in the high-precision map, such as a traffic light group, a road sign, etc.

[0077] Step S110: Perform line detection on the target image to obtain the first line segments in the target image.

[0078] Among them, the target image is part or all of the image in the original image obtained by the vehicle-mounted camera. The original image is an image of the driving environment around the vehicle obtained in real time by the vehicle-mounted camera. The target image is the image corresponding to the target object in the original image, and the target object can be a traffic light group, a road sign, etc.

[0079] Specifically, after obtaining the original image through the vehicle-mounted camera, the electronic device can determine the target area where the target object is located in the original image and determine this target area as the target image.

[0080] When the electronic device can detect a target object in the original image, it can generate a bounding box for enclosing the target object in the original image, and crop the original image based on the bounding box. The part of the original image within the cropped bounding box is the target image. It should be noted that when the original image only includes the target object, the original image can also be directly determined as the target image. The embodiments of the present invention do not make specific limitations on this.

[0081] Among them, the bounding box enclosing the target object is the bounding box after screening and dilation. When the target object is blocked by a small number of objects (such as tree branches, lamp posts, etc.), the connected regions of the semantic labels of the target object on the original image will be split into two or more, but the gaps between the multiple connected regions are not large. By dilating the connected regions, the multiple connected regions will be merged into one. Therefore, the bounding box obtained at this time is quite different from the border of the target image, and the bounding box is larger than and includes the border of the target image; if the target object is blocked by a large amount and only a part of the target object exists in the original image, then the area of the target object on the original image is significantly smaller than its area on the original images of the previous and subsequent frames. In this case, the original image can be excluded, and the target image is not obtained from this original image. Thus, the problem of straight line breakage of the target object in the target image due to occlusion can be effectively solved, and the integrity of the target object in the target image is improved.

[0082] In the embodiments of the present invention, after obtaining the target image, the electronic device can use existing line detection algorithms to perform line detection on the target image to obtain all line segments in the target image, that is, the first line segments. Among them, the existing line detection algorithms can include, but are not limited to, Hough line transform, a Line Segment Detector (LSD), Fast Line Detector (FLD), CannyLines line detection, etc.

[0083] Referring to Figure 2 , a schematic diagram of a target image provided by an embodiment of the present invention is shown. In Figure 2 , the target image 10 is a partial image in the original image 00. After the electronic device performs line detection on the target image 10, a large number of first line segments with different directions and lengths as shown in Figure 2 can be obtained.

[0084] It should be noted that target objects such as traffic light groups and road signs are generally rectangular. The embodiments of the present invention mainly take the example of obtaining the rectangular border of the target image for illustration.

[0085] Step S120: Determine the inclination angle of the first line segments, and based on the inclination angle, determine the horizontal line segments and vertical line segments among the first line segments.

[0086] In an embodiment of the present invention, the process for the electronic device to determine the inclination angle of the first straight line segment may specifically be as follows: First, obtain the endpoint coordinates of the first straight line segment; then, calculate the slope of the first straight line segment according to the endpoint coordinates; and finally, determine the inclination angle of the first straight line segment according to the slope of the first straight line segment.

[0087] Among them, the endpoint coordinates are the coordinates of the endpoints in the first straight line segment in the pixel coordinate system. The pixel coordinate system is established with the upper left corner of the target image as the origin, the direction horizontally to the right from the origin as the positive x-axis direction, and the direction vertically downward from the origin as the positive y-axis direction. In the pixel coordinate system, the target image can be represented as a two-dimensional matrix, and the pixel coordinates correspond to the indices of the pixels in the matrix; in addition, the vehicle body will not have a large-angle roll, and the horizontal and vertical in the pixel coordinate system are equivalently represented as the horizontal and vertical in the world coordinate system. The coordinates and concepts such as horizontal and vertical involved in the embodiments of the present invention are all concepts in the pixel coordinate system.

[0088] Specifically, the electronic device can calculate the slope of the first straight line segment through the following formula 1:

[0089]

[0090] Among them, k represents the slope of the first straight line segment; the endpoints of the first straight line segment include a first endpoint and a second endpoint. The coordinates of the first endpoint are (x1, y1), the coordinates of the second endpoint are (x2, y2), x1 represents the abscissa of the first endpoint, y1 represents the ordinate of the first endpoint, x2 represents the abscissa of the second endpoint, and y2 represents the ordinate of the second endpoint.

[0091] After obtaining the slope of the first straight line segment, the electronic device can calculate the inclination angle of the first straight line segment through the following formula 2:

[0092] α = tan -1 (k) (2)

[0093] Among them, α represents the inclination angle of the first straight line segment.

[0094] In an embodiment of the present invention, after determining the inclination angle of the first straight line segment, the electronic device may determine the horizontal straight line segment and the vertical straight line segment in the first straight line segment based on the inclination angle. Specifically, the electronic device may determine the first straight line segment with an inclination angle of 0° or 180°, that is, parallel to the x-axis of the pixel coordinate system, as the horizontal straight line segment; and determine the first straight line segment with an inclination angle of 90° or -90°, that is, parallel to the y-axis of the pixel coordinate system, as the vertical straight line segment.

[0095] Step S130: Determine the horizontal straight line cluster corresponding to the horizontal straight line segment and the vertical straight line cluster corresponding to the vertical straight line segment; the horizontal straight line cluster is a straight line cluster determined with the horizontal straight line segment as the central straight line segment, and the vertical straight line cluster is a straight line cluster determined with the vertical straight line segment as the central straight line segment.

[0096] In the embodiment of the present invention, after the electronic device determines the horizontal straight line segment and the vertical straight line segment in the first straight line segment through step S120, it can determine the horizontal straight line cluster with each horizontal straight line segment as the central straight line segment, and determine the vertical straight line cluster with each vertical straight line segment as the central straight line segment; it can be understood that the number of horizontal straight line clusters is the same as the number of horizontal straight line segments, and the number of vertical straight line clusters is the same as the number of vertical straight line segments.

[0097] As an alternative embodiment, the process for the electronic device to determine the horizontal straight line cluster corresponding to the target horizontal straight line segment is specifically as follows: obtain the distance from the center point of each first horizontal straight line segment in the first straight line segment to the target horizontal straight line segment or the extension line of the target horizontal straight line segment; when the distance is less than or equal to the third preset threshold, determine that the first horizontal straight line segment belongs to the horizontal straight line cluster with the target horizontal straight line segment as the central straight line segment.

[0098] Wherein, both the target horizontal straight line segment and the first horizontal straight line segment are any horizontal straight line segments in the horizontal straight line segments determined in step S120, and the target horizontal straight line segment and the first horizontal straight line segment may be the same horizontal straight line segment or different horizontal straight line segments. The center point of the first horizontal straight line segment is the point on the first horizontal straight line segment that is equidistant from the two endpoints of the first horizontal straight line segment. The third preset threshold can be set according to the clustering requirements in the actual scenario, and the embodiment of the present invention does not make specific limitations on this.

[0099] In the embodiment of the present invention, the process for the electronic device to determine the vertical straight line cluster corresponding to the target vertical straight line segment is specifically as follows: obtain the distance from the center point of the first vertical straight line segment in the first straight line segment to the target vertical straight line segment or the extension line of the target vertical straight line segment; when the distance is less than or equal to the third preset threshold, determine that the first vertical straight line segment belongs to the vertical straight line cluster with the target vertical straight line segment as the central straight line segment.

[0100] Wherein, both the target vertical straight line segment and the first vertical straight line segment are any vertical straight line segments in the vertical straight line segments determined in step S120, and the target vertical straight line segment and the first vertical straight line segment may be the same vertical straight line segment or different vertical straight line segments. The center point of the first vertical straight line segment is the point on the first vertical straight line segment that is equidistant from the two endpoints of the first vertical straight line segment.

[0101] Step S140: Determine the first weight value of the horizontal straight line cluster and the second weight value of the vertical straight line cluster.

[0102] In an embodiment of the present invention, the weight value of a straight line cluster is a weight value determined based on at least one of the distances from each straight line segment in the straight line cluster to the central straight line segment and the lengths of the straight line segments in the straight line cluster. The larger the weight value, the closer the straight line cluster is to the actual border of the target image.

[0103] Specifically, the electronic device can determine the first weight value by calculating the second sum of the distances from the center points of the horizontal straight line segments in the horizontal straight line cluster to the central straight line segment or the extension line of the central straight line segment. The smaller the second sum, the larger the first weight value of the horizontal straight line cluster. Among them, the electronic device can directly determine the second sum as the first weight value; or a mapping relationship between the second sum and the first weight value can be determined in advance. When the electronic device obtains the second sum, it can determine the first weight value of the horizontal straight line cluster based on the mapping relationship between the second sum and the first weight value.

[0104] Optionally, the electronic device can determine the first weight value by calculating the third sum of the lengths of the horizontal straight line segments in the horizontal straight line cluster. The larger the third sum, the larger the first weight value of the horizontal straight line cluster. Among them, the electronic device can directly determine the third sum as the first weight value; or a mapping relationship between the third sum and the first weight value can be determined in advance. When the electronic device obtains the third sum, it can determine the first weight value of the horizontal straight line cluster based on the mapping relationship between the third sum and the first weight value.

[0105] Optionally, a proportional relationship between the distances from the center points of the horizontal straight line segments in the horizontal straight line cluster to the central straight line segment or the extension line of the central straight line segment and the lengths of the horizontal straight line segments in the horizontal straight line cluster can also be determined in advance. For example, the proportional relationship can be 3:7. When the electronic device determines the first weight value of the horizontal straight line cluster, it can calculate the first product of the second sum value and 0.3 and the second product of the third sum value and 0.7 respectively, and determine the ratio of the second product to the first product as the first weight value, or determine the first weight value based on the ratio index of the second product to the first product. The embodiments of the present invention do not make specific limitations in this regard.

[0106] In an embodiment of the present invention, the method for the electronic device to determine the second weight value of the vertical straight line cluster is the same as the method for determining the first weight value of the horizontal straight line cluster. To avoid repetition, it will not be elaborated here.

[0107] Step S150: Determine the target horizontal straight line cluster corresponding to the target image according to the first weight value, and determine the target vertical straight line cluster corresponding to the target image according to the second weight value.

[0108] In an embodiment of the present invention, the larger the weight value of a straight line cluster, the closer the straight line cluster is to the actual border of the target image. The number of target horizontal straight line clusters can be one or two; the number of target vertical straight line clusters is also one or two.

[0109] Specifically, when the number of both the target horizontal straight line cluster and the target vertical straight line cluster is one, in the process of the electronic device determining the target horizontal straight line cluster and the target vertical straight line cluster corresponding to the target image, the horizontal straight line cluster corresponding to the maximum value of the first weight value determined in step S140 can be determined as the target horizontal straight line cluster, and the vertical straight line cluster corresponding to the maximum value of the second weight value determined in step S140 can be determined as the target vertical straight line cluster.

[0110] It can be understood that when the border of the target image is a rectangular border, it is necessary to determine the upper border and the lower border of the rectangular border based on the horizontal straight line cluster, and determine the left border and the right border of the rectangular border based on the vertical straight line cluster. Specifically, when the number of target horizontal straight line clusters is two, the target horizontal straight line clusters include a first horizontal straight line cluster and a second horizontal straight line cluster. In the process of the electronic device determining the target horizontal straight line cluster, the horizontal straight line cluster corresponding to the maximum value of the first weight value located on the upper side of the target image can be determined as the first horizontal straight line cluster by combining the specific position of the horizontal straight line cluster in the target image and the first weight value, and the horizontal straight line cluster corresponding to the maximum value of the first weight value located on the lower side of the target image can be determined as the second horizontal straight line cluster; correspondingly, when the number of target vertical straight line clusters is two, the target vertical straight line clusters include a first vertical straight line cluster and a second vertical straight line cluster. In the process of the electronic device determining the target vertical straight line cluster, the vertical straight line cluster corresponding to the maximum value of the second weight value located on the left side of the target image can be determined as the first vertical straight line cluster by combining the specific position of the vertical straight line cluster in the target image and the second weight value, and the vertical straight line cluster corresponding to the maximum value of the second weight value located on the right side of the target image can be determined as the second vertical straight line cluster.

[0111] Step S160: Determine the border of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster.

[0112] Specifically, when the number of target horizontal straight line clusters is one, the electronic device can first determine the first central straight line segment of the target horizontal straight line cluster, and then determine a second central straight line segment parallel to the first central straight line segment; wherein, the distance between the second central straight line segment and the first central straight line segment can be equal to the length of the target vertical straight line cluster, and the length of the target vertical straight line cluster is the distance between the endpoint at the uppermost end of the target vertical straight line cluster and the endpoint at the lowermost end of the target vertical straight line cluster.

[0113] Similarly, when the number of target vertical line clusters is 1, the electronic device can first determine the third central line segment of the target vertical line cluster, and then determine the fourth central line segment parallel to the third central line segment; wherein, the distance between the fourth central line segment and the third central line segment can be equal to the length of the target horizontal line cluster, and the length of the target horizontal line cluster is the distance between the leftmost endpoint and the rightmost endpoint of the target horizontal line cluster.

[0114] When the number of target horizontal line clusters is 2, the electronic device can respectively determine the first central line segment of the first horizontal line cluster and the second central line segment of the second horizontal line cluster in the target horizontal line cluster, and the third central line segment of the first vertical line cluster and the second central line segment of the second vertical line cluster in the target vertical line cluster, and determine the border formed by the extension lines of the first central line segment, the second central line segment, the third central line segment, and the fourth central line segment as the border of the target image.

[0115] The border extraction method provided by the embodiments of the present invention reduces a large amount of unnecessary repeated calculations, reduces the computational resource overhead for extracting the border of the target image, and improves the efficiency of border extraction.

[0116] Refer to Figure 3 , which shows a flowchart of steps of another border extraction method provided by the embodiments of the present invention. The method includes steps S201 to S214:

[0117] Step S201: Perform line detection on the target image to obtain the first line segment in the target image.

[0118] For a detailed description of this step, reference can be made to the detailed description of step S110, which will not be elaborated here.

[0119] Step S202: Determine the inclination angle of the first line segment.

[0120] For a detailed description of this step, reference can be made to the detailed description of step S120, which will not be elaborated here.

[0121] Step S203: When the inclination angle falls within the first preset angle range, determine the first line segment corresponding to the inclination angle as a horizontal line segment.

[0122] Step S204: When the inclination angle falls within the second preset angle range, determine the first line segment corresponding to the inclination angle as a vertical line segment.

[0123] In an embodiment of the present invention, after the electronic device determines the inclination angle of the first straight line segment through step S202, the inclination angle can be compared with a first preset angle range and a second preset angle range respectively. The first straight line segment whose inclination angle falls within the first preset angle range is determined as a horizontal straight line segment, and the first straight line segment whose inclination angle falls within the second preset angle range is determined as a vertical straight line segment.

[0124] Among them, the first preset angle range is an angle range determined with 0° or 180° as the central value, and the second preset angle range is an angle range determined with 90° or -90° as the central value. Exemplarily, the first angle range can be 0±5°, or 0±10°, or 180±5°; the second angle range can be 90±5°, or 90±10°. The embodiments of the present invention do not make specific limitations on this.

[0125] Step S205: Determine the horizontal straight line cluster corresponding to the horizontal straight line segment and the vertical straight line cluster corresponding to the vertical straight line segment; the horizontal straight line cluster is a straight line cluster determined with the horizontal straight line segment as the central straight line segment, and the vertical straight line cluster is a straight line cluster determined with the vertical straight line segment as the central straight line segment.

[0126] In an embodiment of the present invention, the method for the electronic device to determine the horizontal straight line cluster corresponding to the horizontal straight line segment specifically includes steps A11 to A13:

[0127] Step A11: Determine the first horizontal straight line where the target horizontal straight line segment is located; the target horizontal straight line segment is any horizontal straight line segment among the first straight line segments.

[0128] Specifically, the straight line equation of the first horizontal straight line where the target horizontal straight line segment is located can be determined according to the coordinates of the two endpoints of the target horizontal straight line segment, so as to determine the first horizontal straight line where the target horizontal straight line segment is located.

[0129] Refer to Figure 4 , which shows another schematic diagram of the target image provided by the embodiment of the present invention. The first horizontal straight line where the target horizontal straight line segment 12 among the first straight line segments of the target image 10 is located is 121.

[0130] Step A12: Determine the first distance and the second distance from the two endpoints of the first horizontal straight line segment among the first straight line segments to the first horizontal straight line.

[0131] Step A13: In the case where both the first distance and the second distance are less than the first preset threshold, determine that the first horizontal straight line segment belongs to the horizontal straight line cluster with the first horizontal straight line as the central straight line.

[0132] Among them, the first preset threshold can be selected according to the size of the target image. For a horizontal straight line segment, the first preset threshold can be selected to be about 20% of the vertical height of the target image. Exemplarily, the first preset threshold can be 20 pixels to 40 pixels.

[0133] When the first distance from the first endpoint of the first horizontal straight line to the first horizontal straight line and the second distance from the second endpoint of the first horizontal straight line to the first horizontal straight line are both less than the first preset threshold, it can be determined that the first horizontal straight line segment belongs to the horizontal straight line cluster with the first horizontal straight line as the central straight line. Thus, through steps A11 to A13, the horizontal straight line cluster corresponding to each horizontal straight line segment can be determined.

[0134] In the embodiment of the present invention, the method for the electronic device to determine the vertical straight line cluster corresponding to the vertical straight line segment specifically includes steps A21 to A23:

[0135] Step A21, determine the first vertical straight line where the target vertical straight line segment is located; the target vertical straight line segment is any vertical straight line segment in the first straight line segment.

[0136] Specifically, according to the coordinates of the two endpoints of the target vertical straight line segment, the straight line equation of the first vertical straight line where the target vertical straight line segment is located can be determined, thereby determining the first vertical straight line where the target vertical straight line segment is located.

[0137] Refer to Figure 4 , among the first straight line segments of the target image 10, the first vertical straight line where the target vertical straight line segment 11 is located is 111.

[0138] Step A22, determine the fifth distance and the sixth distance from the two endpoints of the first vertical straight line segment in the first straight line segment to the first vertical straight line.

[0139] It should be noted that the first vertical straight line segment is any vertical straight line segment in the first straight line segment, and the first vertical straight line segment can be the same vertical straight line segment as the target vertical straight line segment or a different vertical straight line segment from the target vertical straight line segment.

[0140] Step A23, when both the fifth distance and the sixth distance are less than the fourth preset threshold, determine that the first vertical straight line segment belongs to the vertical straight line cluster with the first vertical straight line as the central straight line.

[0141] Among them, the fourth preset threshold can be selected according to the size of the target image. For a vertical straight line segment, the fourth preset threshold can be selected to be about 20% of the horizontal width of the target image.

[0142] In the case where the fifth distance from the first end point of the first vertical straight line segment to the first vertical straight line and the sixth distance from the second end point to the first vertical straight line are both less than the fourth preset threshold, it can be determined that the first vertical straight line segment belongs to the vertical straight line cluster centered on the first vertical straight line. Thus, through steps A21 to A23, the vertical straight line clusters corresponding to each vertical straight line segment can be determined.

[0143] Step S206, determine the first weight value of the horizontal straight line cluster and the second weight value of the vertical straight line cluster.

[0144] In the embodiment of the present invention, the method for the electronic device to determine the first weight value of the horizontal straight line cluster specifically includes steps B11 to B13:

[0145] Step B11, determine the second horizontal straight line corresponding to the horizontal straight line cluster; the horizontal straight line cluster is a straight line cluster determined with the second horizontal straight line as the central straight line.

[0146] Among them, the second horizontal straight line corresponding to the horizontal straight line cluster is the horizontal straight line used to determine the horizontal straight line cluster in steps A11 to A13.

[0147] Step B12, determine the projection length of each horizontal straight line segment in the horizontal straight line cluster on the second horizontal straight line.

[0148] Refer to Figure 5 , which shows a schematic diagram of the relationship between the horizontal straight line segment and the horizontal straight line in a horizontal straight line cluster provided by an embodiment of the present invention. The projection length of any horizontal straight line segment 13 in the horizontal straight line cluster on the second horizontal straight line 121 is l1.

[0149] Step B13, determine the third distance and the fourth distance from the two end points of each horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line.

[0150] Refer to Figure 5 , the third distance from the first end point of any horizontal straight line segment 13 in the horizontal straight line cluster to the horizontal straight line 121 is d3, and the fourth distance from the second end point to the horizontal straight line 121 is d4.

[0151] Step B14, calculate the first sum value of the third distance and the fourth distance corresponding to each horizontal straight line segment in the horizontal straight line cluster.

[0152] Step B15, calculate the ratio of the projection length and the first sum value corresponding to each horizontal straight line segment in the horizontal straight line cluster.

[0153] Step B16, calculate the average value of the ratios corresponding to each horizontal straight line segment in the horizontal straight line cluster, and determine the average value as the first weight value of the horizontal straight line cluster.

[0154] In an embodiment of the present invention, when the electronic device determines the projection length through step B12 and determines the third distance and the fourth distance through step B13, the first weight value of the horizontal straight line cluster can be determined by the following formula 3:

[0155]

[0156] Wherein, w1 represents the first weight value; n represents the total number of horizontal straight line clusters in the target image; l1 represents the projection length of each horizontal straight line segment in the horizontal straight line cluster on the second horizontal straight line; d3 represents the third distance from the first end point of each horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line; d4 represents the fourth distance from the second end point of each horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line.

[0157] In an embodiment of the present invention, the method for the electronic device to determine the second weight value of the vertical straight line cluster specifically includes steps B21 to B23:

[0158] Step B21, determine the second vertical straight line corresponding to the vertical straight line cluster; the vertical straight line cluster is a straight line cluster determined with the second vertical straight line as the central straight line.

[0159] Wherein, the second vertical straight line corresponding to the vertical straight line cluster is the vertical straight line used to determine the vertical straight line cluster in steps A21 to A23.

[0160] Step B22, determine the projection length of each vertical straight line segment in the vertical straight line cluster on the second vertical straight line.

[0161] Refer to Figure 6 , which shows a schematic diagram of the relationship between the vertical straight line segment and the vertical straight line in a vertical straight line cluster provided by an embodiment of the present invention. The projection length of any vertical straight line segment 14 in the vertical straight line cluster on the second vertical straight line 111 is l2.

[0162] Step B23, determine the seventh distance and the eighth distance from the two end points of each vertical straight line segment in the vertical straight line cluster to the second vertical straight line.

[0163] Refer to Figure 6 , the seventh distance from the first end point of any vertical straight line segment 14 in the vertical straight line cluster to the vertical straight line 111 is d7, and the eighth distance from the second end point to the vertical straight line 111 is d8.

[0164] Step B24, calculate the fourth sum value of the seventh distance and the eighth distance corresponding to each vertical straight line segment in the vertical straight line cluster.

[0165] Step B25: Calculate the ratio of the projection length corresponding to each vertical line segment in the vertical line cluster to the fourth sum value.

[0166] Step B26: Calculate the average value of the ratios corresponding to each vertical line segment in the vertical line cluster, and determine the average value as the second weight value of the vertical line cluster.

[0167] In an embodiment of the present invention, when the electronic device determines the projection length through step B22 and determines the seventh distance and the eighth distance through step B23, the second weight value of the vertical line cluster can be determined by the following formula 4:

[0168]

[0169] where w2 represents the second weight value; m represents the total number of vertical line clusters in the target image; l2 represents the projection length of each vertical line segment in the vertical line cluster on the second vertical line; d7 represents the seventh distance from the first endpoint of each vertical line segment in the vertical line cluster to the second vertical line; d8 represents the eighth distance from the second endpoint of each vertical line segment in the vertical line cluster to the second vertical line.

[0170] Step S207: Determine the center point of the target image.

[0171] The center point of the target image is the intersection of the vertical center line and the horizontal center of the target image.

[0172] Step S208: Based on the center point, determine the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line cluster above the center point as the first horizontal line cluster.

[0173] Step 209: Determine the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line cluster below the center point as the second horizontal line cluster.

[0174] Step 210: Determine the vertical line cluster corresponding to the maximum value of the first weight value in the vertical line cluster to the left of the center point as the first vertical line cluster.

[0175] Step 211: Determine the vertical line cluster corresponding to the maximum value of the first weight value in the vertical line cluster to the right of the center point as the second vertical line cluster.

[0176] The target horizontal line cluster includes the first horizontal line cluster and the second horizontal line cluster; the target vertical line cluster includes the first vertical line cluster and the second vertical line cluster.

[0177] In an embodiment of the present invention, when the electronic device determines the target horizontal straight line cluster corresponding to the target image according to the first weight value and determines the target vertical straight line cluster corresponding to the target image according to the second weight value, in the case where the border of the target image is a rectangular border, it is necessary to determine the upper border and the lower border of the rectangular border based on the horizontal straight line cluster, and determine the left border and the right border of the rectangular border based on the vertical straight line cluster. As can be seen from Formula 3, the first weight value is positively correlated with the projection length of the horizontal straight line segment in the horizontal straight line cluster projected onto the second horizontal straight line, and negatively correlated with the distances from the two endpoints of the horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line. The larger the weight value of the straight line cluster, the closer the straight line cluster is to the actual border of the target image. Based on the relative positions of the horizontal straight line cluster and the vertical straight line cluster with respect to the center point of the target image, the straight line cluster corresponding to the maximum weight value among the straight line clusters corresponding to each position is determined as the target straight line cluster, which improves the representativeness of the target straight line cluster, and further improves the accuracy of the border of the target image determined based on the target horizontal straight line cluster and the target vertical straight line cluster.

[0178] Step 212: Determine a first target horizontal straight line corresponding to the first horizontal straight line cluster and a second target horizontal straight line corresponding to the second horizontal straight line cluster.

[0179] Step 213: Determine a first target vertical straight line corresponding to the first vertical straight line cluster and a second target vertical straight line corresponding to the second vertical straight line cluster.

[0180] Step 214: Determine the border formed by the first target horizontal straight line, the second target horizontal straight line, the first target vertical straight line, and the second target vertical straight line as the border of the target image.

[0181] In an embodiment of the present invention, the target horizontal straight line cluster includes a first horizontal straight line cluster determined through step S208 and a second horizontal straight line cluster determined through step S209, and the target vertical straight line cluster includes a first vertical straight line cluster determined through step S210 and a second vertical straight line cluster determined through step S211.

[0182] When the electronic device determines the border of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster, it can respectively determine a first target horizontal straight line corresponding to the first horizontal straight line cluster, a second target horizontal straight line corresponding to the second horizontal straight line cluster, a first target vertical straight line corresponding to the first vertical straight line cluster, and a second target vertical straight line corresponding to the second vertical straight line cluster, and then determine the border formed by the first target horizontal straight line, the second target horizontal straight line, the first target vertical straight line, and the second target vertical straight line as the border of the target image.

[0183] It should be noted that the first horizontal straight line cluster is a straight line cluster determined with the first target horizontal straight line as the central straight line, the second horizontal straight line cluster is a straight line cluster determined with the second target horizontal straight line as the central straight line, the first vertical straight line cluster is a straight line cluster determined with the first vertical straight line as the central straight line, and the second vertical straight line cluster is a straight line cluster determined with the second vertical straight line as the central straight line.

[0184] Referring to Figure 7 , a schematic diagram of determining the border of a target image provided by an embodiment of the present invention is shown. The border formed by the first target horizontal straight line 151 where the central straight line segment 15 in the first horizontal straight line cluster is located, the second target horizontal straight line 161 where the central straight line segment 16 in the second horizontal straight line cluster is located, the first vertical straight line 171 where the central straight line segment 17 in the first vertical straight line cluster is located, and the second vertical straight line 181 where the central straight line segment 18 in the second vertical straight line cluster is located is the border of the target image 10.

[0185] Optionally, the method further includes steps C11 to C14:

[0186] Step C11: Obtain the edge points of the target image.

[0187] Specifically, the electronic device can calculate the edge points of the target image by using the Canny operator.

[0188] Step C12: Respectively determine a first edge point set corresponding to the first target horizontal straight line, a second edge point set corresponding to the second target horizontal straight line, a third edge point set corresponding to the first target vertical straight line, and a fourth edge point set corresponding to the second target vertical straight line from the edge points.

[0189] Among them, the distances between the edge points in the first edge point set and the first target horizontal straight line, the distances between the edge points in the second edge point set and the second target horizontal straight line, the distances between the edge points in the third edge point set and the first target vertical straight line, and the distances between the edge points in the fourth edge point set and the second target vertical straight line are all less than a second preset threshold.

[0190] Specifically, the electronic device can determine the edge points with a distance less than the second preset threshold from the first target horizontal straight line as the first edge point set, the edge points with a distance less than the second preset threshold from the second target horizontal straight line as the second edge point set, the edge points with a distance less than the second preset threshold from the first target vertical straight line as the third edge point set, and the edge points with a distance less than the second preset threshold from the second target vertical straight line as the fourth edge point set.

[0191] Step C13: Perform linear fitting on the first edge point set, the second edge point set, the third edge point set, and the fourth edge point set respectively to obtain the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line.

[0192] Step C14: Determine the border formed by the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line as the border of the target image.

[0193] It should be noted that the edge points of the target image obtained by using the Canny operator are discrete edge points, and the lines directly fitted based on the discrete edge points are not the lines where the border of the target image is located. In the embodiments of the present invention, the first edge point set, the second edge point set, the third edge point set, and the fourth edge point set corresponding to the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line are determined based on the magnitude relationship between the edge points and the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line. Further, through step C13, linear fitting is performed on each edge point set to obtain the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line. Through step C14, the border formed by the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line is determined as the border of the target image, improving the accuracy of determining the border of the target image.

[0194] In the embodiments of the present invention, after the electronic device executes step C13, it can repeatedly execute step C12 and step C13 to repeatedly perform fitting on the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line obtained after executing step C13 until the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line obtained after executing step C13 no longer change, and then execute step C14 to determine the border formed by the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line as the border of the target image.

[0195] Refer to Figure 8, which shows a schematic diagram of correcting a target vertical line by fitting edge points according to an embodiment of the present invention. Edge points 20 in the target image whose distance from the target vertical line 171 is less than the second preset threshold D are determined as the edge point set corresponding to the target vertical line 171. By performing a linear fitting on these edge points, the first fitted target vertical line 171-1 is obtained; repeat the above steps C12 to C13 to perform a secondary linear fitting on the first fitted target vertical line 171-1 to obtain the second fitted target vertical line 171-2; when the second fitted target vertical line 171-2 no longer changes compared with the first fitted target vertical line 171-1, execute step C14 to determine the border of the target image based on the second fitted target vertical line 171-2.

[0196] The border extraction method provided by the embodiment of the present invention first screens out horizontal line segments and vertical line segments in the first line segments in the target image based on the inclination angles of the first line segments, and then clusters each of the first line segments based on the horizontal line segments and vertical line segments to obtain a horizontal line cluster and a vertical line cluster. Finally, according to the first weight value of each horizontal line cluster and the second weight value of each vertical line cluster, the target horizontal line cluster and the target vertical line cluster corresponding to the target image are determined, and then the border of the target image is determined. While ensuring the accuracy of the border extraction of the target image, the first line segments in the target image are screened and clustered, and then the border of the target image is determined based on the target horizontal line cluster in the horizontal line cluster and the target vertical line cluster in the vertical line cluster obtained after clustering, reducing a large amount of unnecessary repeated calculations, reducing the computational resource overhead for extracting the border of the target image, and improving the efficiency of border extraction.

[0197] Device embodiment

[0198] Refer to Figure 9 , which shows a logic block diagram of a border extraction device provided by an embodiment of the present invention. The device includes:

[0199] A line detection module 910, configured to perform line detection on a target image to obtain the first line segments in the target image;

[0200] A first determination module 920, configured to determine the inclination angles of the first line segments, and based on the inclination angles, determine the horizontal line segments and vertical line segments in the first line segments;

[0201] A second determination module 930, configured to determine the horizontal line cluster corresponding to the horizontal line segments and the vertical line cluster corresponding to the vertical line segments; the horizontal line cluster is a line cluster determined with the horizontal line segment as the central line segment, and the vertical line cluster is a line cluster determined with the vertical line segment as the central line segment;

[0202] A third determination module 940, configured to determine a first weight value of the horizontal straight line cluster and a second weight value of the vertical straight line cluster;

[0203] A fourth determination module 950, configured to determine a target horizontal straight line cluster corresponding to the target image according to the first weight value, and determine a target vertical straight line cluster corresponding to the target image according to the second weight value;

[0204] A fifth determination module 960, configured to determine a border of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster.

[0205] Optionally, the second determination module includes:

[0206] A first determination sub-module, configured to determine a first horizontal straight line where a target horizontal straight line segment is located; the target horizontal straight line segment is any horizontal straight line segment in the first straight line segment;

[0207] A second determination sub-module, configured to determine a first distance and a second distance from two endpoints of the first horizontal straight line segment in the first straight line segment to the first horizontal straight line;

[0208] A third determination sub-module, configured to determine that the first horizontal straight line segment belongs to a horizontal straight line cluster with the first horizontal straight line as a central straight line when both the first distance and the second distance are less than a first preset threshold.

[0209] Optionally, the third determination module includes:

[0210] A fourth determination sub-module, configured to determine a second horizontal straight line corresponding to the horizontal straight line cluster; the horizontal straight line cluster is a straight line cluster determined with the second horizontal straight line as a central straight line;

[0211] A fifth determination sub-module, configured to determine a projection length of each horizontal straight line segment in the horizontal straight line cluster on the second horizontal straight line;

[0212] A sixth determination sub-module, configured to determine a third distance and a fourth distance from two endpoints of each horizontal straight line segment in the horizontal straight line cluster to the second horizontal straight line;

[0213] A first calculation sub-module, configured to calculate a first sum value of the third distance and the fourth distance corresponding to each horizontal straight line segment in the horizontal straight line cluster;

[0214] A second calculation sub-module, configured to calculate a ratio of the projection length and the first sum value corresponding to each horizontal straight line segment in the horizontal straight line cluster;

[0215] A third calculation sub-module, configured to calculate an average value of the ratios corresponding to the horizontal line segments in the horizontal line cluster, and determine the average value as the first weight value of the horizontal line cluster.

[0216] Optionally, the target horizontal line cluster includes a first horizontal line cluster and a second horizontal line cluster; the target vertical line cluster includes a first vertical line cluster and a second vertical line cluster.

[0217] The fourth determination module includes:

[0218] A seventh determination sub-module, configured to determine the center point of the target image.

[0219] An eighth determination sub-module, configured to, based on the center point, determine the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line cluster located above the center point as the first horizontal line cluster.

[0220] A ninth determination sub-module, configured to determine the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line cluster located below the center point as the second horizontal line cluster.

[0221] A tenth determination sub-module, configured to determine the vertical line cluster corresponding to the maximum value of the first weight value in the vertical line cluster located to the left of the center point as the first vertical line cluster.

[0222] An eleventh determination sub-module, configured to determine the vertical line cluster corresponding to the maximum value of the first weight value in the vertical line cluster located to the right of the center point as the second vertical line cluster.

[0223] Optionally, the fifth determination module includes:

[0224] A twelfth determination sub-module, configured to determine a first target horizontal line corresponding to the first horizontal line cluster and a second target horizontal line corresponding to the second horizontal line cluster.

[0225] A thirteenth determination sub-module, configured to determine a first target vertical line corresponding to the first vertical line cluster and a second target vertical line corresponding to the second vertical line cluster.

[0226] A fourteenth determination sub-module, configured to determine the frame formed by the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line as the frame of the target image.

[0227] Optionally, the fifth determination module further includes:

[0228] An acquisition sub-module, configured to acquire the edge points of the target image.

[0229] A fifteenth determination sub-module, configured to respectively determine a first set of edge points corresponding to the first target horizontal line, a second set of edge points corresponding to the second target horizontal line, a third set of edge points corresponding to the first target vertical line, and a fourth set of edge points corresponding to the second target vertical line from the edge points; wherein, the distances between the edge points in the first set of edge points and the first target horizontal line, the distances between the edge points in the second set of edge points and the second target horizontal line, the distances between the edge points in the third set of edge points and the first target vertical line, and the distances between the edge points in the fourth set of edge points and the second target vertical line are all less than a second preset threshold;

[0230] A line fitting sub-module, configured to respectively perform line fitting on the first set of edge points, the second set of edge points, the third set of edge points, and the fourth set of edge points to obtain a fitted first target horizontal line, a fitted second target horizontal line, a fitted first target vertical line, and a fitted second target vertical line;

[0231] A sixteenth determination sub-module, configured to determine the frame formed by the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line as the frame of the target image.

[0232] Optionally, the first determination module includes:

[0233] A seventeenth determination sub-module, configured to determine the first line segment corresponding to the inclination angle as a horizontal line segment when the inclination angle falls within a first preset angle range;

[0234] An eighteenth determination sub-module, configured to determine the first line segment corresponding to the inclination angle as a vertical line segment when the inclination angle falls within a second preset angle range.

[0235] For the apparatus embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the related parts, please refer to the partial description of the method embodiments.

[0236] An embodiment of the present invention further provides a vehicle, the vehicle includes an electronic device, the electronic device includes a memory and a processor, the memory is used to store a computer program, the processor is used to call and run the computer program stored in the memory, and when the processor executes the computer program, it implements the frame extraction method described in any one of the above.

[0237] An embodiment of the present invention further provides a readable storage medium, the readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the frame extraction method described in any one of the above.

[0238] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the embodiments, reference can be made to each other.

[0239] The above embodiments are only preferred embodiments given to fully illustrate the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or transformations made by those skilled in the art on the basis of the present invention are within the protection scope of the present invention.

Claims

1. A method for border extraction, characterized in that, The method includes: Performing line detection on a target image to obtain a first line segment in the target image; Determining the inclination angle of the first line segment, and based on the inclination angle, determining a horizontal line segment and a vertical line segment in the first line segment; Determining a horizontal line cluster corresponding to the horizontal line segment and a vertical line cluster corresponding to the vertical line segment; the horizontal line cluster is a line cluster determined with the horizontal line segment as the central line segment, and the vertical line cluster is a line cluster determined with the vertical line segment as the central line segment; Determining a first weight value of the horizontal line cluster and a second weight value of the vertical line cluster; According to the first weight value, determining a target horizontal line cluster corresponding to the target image, and according to the second weight value, determining a target vertical line cluster corresponding to the target image; Based on the target horizontal line cluster and the target vertical line cluster, determining a border of the target image.

2. The method according to claim 1, characterized in that, The determining the horizontal line cluster corresponding to the horizontal line segment includes: Determining a first horizontal line where a target horizontal line segment is located; the target horizontal line segment is any horizontal line segment in the first line segment; Determining a first distance and a second distance from two endpoints of the first horizontal line segment in the first line segment to the first horizontal line; In the case where both the first distance and the second distance are less than a first preset threshold, determining that the first horizontal line segment belongs to a horizontal line cluster with the first horizontal line as the central line.

3. The method according to claim 1, characterized in that, The determining the first weight value of the horizontal line cluster includes: Determining a second horizontal line corresponding to the horizontal line cluster; the horizontal line cluster is a line cluster determined with the second horizontal line as the central line segment; Determining a projection length of each horizontal line segment in the horizontal line cluster on the second horizontal line; Determining a third distance and a fourth distance from two endpoints of each horizontal line segment in the horizontal line cluster to the second horizontal line; Calculating a first sum value of the third distance and the fourth distance corresponding to each horizontal line segment in the horizontal line cluster; Calculating a ratio of the projection length and the first sum value corresponding to each horizontal line segment in the horizontal line cluster; Calculating an average value of the ratios corresponding to each horizontal line segment in the horizontal line cluster, and determining the average value as the first weight value of the horizontal line cluster.

4. The method according to claim 1, characterized in that, The target horizontal line cluster includes a first horizontal line cluster and a second horizontal line cluster; the target vertical line cluster includes a first vertical line cluster and a second vertical line cluster; The according to the first weight value, determining the target horizontal line cluster corresponding to the target image, and according to the second weight value, determining the target vertical line cluster corresponding to the target image, includes: Determining a center point of the target image; Based on the center point, determining the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line clusters located above the center point as the first horizontal line cluster; Determining the horizontal line cluster corresponding to the maximum value of the first weight value in the horizontal line clusters located below the center point as the second horizontal line cluster; Determine the first vertical line cluster corresponding to the maximum value of the first weight value in the vertical line clusters on the left side of the center point as the first vertical line cluster; Determine the second vertical line cluster corresponding to the maximum value of the first weight value in the vertical line clusters on the right side of the center point as the second vertical line cluster.

5. The method according to claim 4, characterized in that, The determining of the border of the target image based on the target horizontal line cluster and the target vertical line cluster includes: Determine a first target horizontal line corresponding to the first horizontal line cluster and a second target horizontal line corresponding to the second horizontal line cluster; Determine a first target vertical line corresponding to the first vertical line cluster and a second target vertical line corresponding to the second vertical line cluster; Determine the border formed by the first target horizontal line, the second target horizontal line, the first target vertical line, and the second target vertical line as the border of the target image.

6. The method according to claim 5, characterized in that, The method further includes: Obtain the edge points of the target image; Respectively determine a first set of edge points corresponding to the first target horizontal line, a second set of edge points corresponding to the second target horizontal line, a third set of edge points corresponding to the first target vertical line, and a fourth set of edge points corresponding to the second target vertical line from the edge points; wherein, the distance between the edge points in the first set of edge points and the first target horizontal line, the distance between the edge points in the second set of edge points and the second target horizontal line, the distance between the edge points in the third set of edge points and the first target vertical line, and the distance between the edge points in the fourth set of edge points and the second target vertical line are all less than a second preset threshold; Perform line fitting on the first set of edge points, the second set of edge points, the third set of edge points, and the fourth set of edge points respectively to obtain a fitted first target horizontal line, a fitted second target horizontal line, a fitted first target vertical line, and a fitted second target vertical line; Determine the border formed by the fitted first target horizontal line, the fitted second target horizontal line, the fitted first target vertical line, and the fitted second target vertical line as the border of the target image.

7. The method according to claim 1, wherein The determining of the horizontal line segment and the vertical line segment in the first line segment based on the inclination angle includes: In the case where the inclination angle falls within a first preset angle range, determine the first line segment corresponding to the inclination angle as a horizontal line segment; In the case where the inclination angle falls within a second preset angle range, determine the first line segment corresponding to the inclination angle as a vertical line segment.

8. A border extraction device, wherein The device includes: A line detection module, configured to perform line detection on a target image to obtain a first line segment in the target image; A first determination module, configured to determine the inclination angle of the first line segment and, based on the inclination angle, determine the horizontal line segment and the vertical line segment in the first line segment; A second determination module, configured to determine a horizontal straight line cluster corresponding to the horizontal straight line segment and a vertical straight line cluster corresponding to the vertical straight line segment; the horizontal straight line cluster is a straight line cluster determined with the horizontal straight line segment as the central straight line segment, and the vertical straight line cluster is a straight line cluster determined with the vertical straight line segment as the central straight line segment; A third determination module, configured to determine a first weight value of the horizontal straight line cluster and a second weight value of the vertical straight line cluster; A fourth determination module, configured to determine a target horizontal straight line cluster corresponding to the target image according to the first weight value, and determine a target vertical straight line cluster corresponding to the target image according to the second weight value; A fifth determination module, configured to determine a border of the target image based on the target horizontal straight line cluster and the target vertical straight line cluster.

9. A vehicle, wherein The vehicle includes an electronic device, the electronic device includes a memory and a processor, the memory is configured to store a computer program, the processor is configured to call and run the computer program stored in the memory, and when the processor executes the computer program, the border extraction method according to any one of claims 1 to 7 above is implemented.

10. A readable storage medium storing a computer program, wherein When the computer program is executed by the processor, the border extraction method according to any one of claims 1 to 7 above is implemented.