Image processing method and device and storage medium
By determining and combining straight line segments near the effective edge of the target element in the image in image processing, and generating a bonded line, the problem of error when extracting image element areas in the deep learning network is solved, and more accurate element area extraction is achieved.
Patent Information
- Application Number
- CN202510130054.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-05
- Publication Date
- 2025-06-20
AI Technical Summary
When extracting element areas in an image through a deep learning network, there is an error, which causes the extracted element areas to fail to fit well with the original element areas.
Obtain the original image, determine multiple effective edges of the target element, and determine multiple linear segments near it for each effective edge. By combining these straight line segments, we can obtain a straight line, and then determine the element area of the target element.
By combining straight lines near the effective edges, a straight line that adheres to the outer edge of the target element in the original image can be more accurately determined, so that it fits well with the original element area.
Smart Images

Figure CN120182312A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular, to an image processing method, apparatus, and storage medium. Background Art
[0002] In recent years, portable devices (such as mobile phones) are often used to capture various elements (such as documents) to obtain images for recording or sharing various elements. In order to better record or share various elements, it is often necessary to extract the element area (such as the document area) in the image.
[0003] In the related art, a deep learning network is usually used to extract the element area in the image. Although the element area in the image can be extracted through the deep learning network, there are errors in the extracted element area in the image, that is, the extracted element area in the image does not fit well with the original element area in the image. Summary of the Invention
[0004] In order to solve the above technical problem that although the element area in the image can be extracted through the deep learning network, there are errors in the extracted element area in the image, that is, the extracted element area in the image does not fit well with the original element area in the image, embodiments of the present application provide an image processing method, apparatus, electronic device, and storage medium. The specific technical solutions are as follows:
[0005] In the first aspect of the embodiments of the present application, first, an image processing method is provided, and the method includes:
[0006] Obtain an original image, and determine multiple effective edges of a target element in the original image;
[0007] For any one of the effective edges, determine multiple straight line segments near the effective edge;
[0008] Perform a merging process on the multiple straight line segments to obtain a fitting straight line corresponding to the effective edge;
[0009] Determine the element area of the target element in the original image according to the multiple fitting straight lines.
[0010] In an optional implementation manner, the determining multiple effective edges of the target element in the original image includes:
[0011] Extract the first edges of each element in the original image by using a first edge extraction method, and extract the second edges of the target element in the original image by using a second edge extraction method; where the first edge extraction method and the first edge extraction method are different edge extraction methods;
[0012] Perform dilation processing on the second edge to obtain the dilated edge of the target element in the original image;
[0013] Perform an intersection operation on the first edge and the dilated edge to obtain multiple effective edges of the target element in the original image.
[0014] In an alternative embodiment, before extracting the first edges of the respective elements in the original image using the first edge extraction method and extracting the second edges of the target element in the original image using the second edge extraction method, it further includes:
[0015] Perform denoising processing on the original image to obtain the denoised original image;
[0016] Perform equal-proportion compression processing on the denoised original image to obtain a target image.
[0017] In an alternative embodiment, the determining multiple straight line segments near the effective edge includes:
[0018] Use a straight line detection algorithm to perform straight line detection on the effective edge to obtain multiple straight line segments near the effective edge.
[0019] In an alternative embodiment, before performing merging processing on the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge, it further includes:
[0020] Filter the multiple straight line segments to obtain the filtered multiple straight line segments;
[0021] Perform merging processing on the filtered multiple straight line segments to obtain the fitting straight line corresponding to the effective edge.
[0022] In an alternative embodiment, the filtering the multiple straight line segments to obtain the filtered multiple straight line segments includes:
[0023] For any one of the straight line segments, determine whether the length of the straight line segment is less than a preset length threshold;
[0024] Determine the first angle formed between the straight line segment and the effective edge, and determine whether the first angle is greater than a preset first angle threshold;
[0025] In the case where the length of the straight line segment is less than the preset length threshold, and / or, the first angle is greater than the preset first angle threshold, discard the straight line segment;
[0026] Determine the remaining straight line segments among the multiple straight line segments as the filtered multiple straight line segments.
[0027] In an alternative embodiment, the merging process for the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge includes:
[0028] Determine a second included angle between any two of the multiple straight line segments;
[0029] Select the maximum second included angle from the second included angles, and determine whether the maximum second included angle is less than a preset second included angle threshold;
[0030] In the case where the maximum second included angle is less than the preset second included angle threshold, perform a merging process on the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge.
[0031] In an alternative embodiment, the merging process for the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge includes:
[0032] Store the multiple straight line segments in a line segment set, and iteratively execute the following steps until the number of line segments in the line segment set is 1, to obtain the fitting straight line corresponding to the effective edge:
[0033] Select the longest straight line segment from the line segment set, and merge the longest straight line segment with any one of the remaining straight line segments in the line segment set to obtain a merged straight line segment;
[0034] Store the merged straight line segment in the line segment set, and remove the longest straight line segment and the straight line segment participating in the merging from the line segment set.
[0035] In an alternative embodiment, the merging of the longest straight line segment with any one of the remaining straight line segments in the line segment set to obtain a merged straight line segment includes:
[0036] Select an edge point from the longest straight line segment, and select a corresponding opposite edge point from any one of the remaining straight line segments in the line segment set;
[0037] Generate a merged straight line segment based on the edge point and the opposite edge point.
[0038] In an alternative embodiment, the storing of the merged straight line segment in the line segment set includes:
[0039] Determine a third included angle formed between the merged straight line segment and the longest straight line segment, and determine whether the third included angle is less than a preset third included angle threshold;
[0040] In the case where the third included angle is less than the preset third included angle threshold, store the merged straight line segment in the line segment set.
[0041] In an optional implementation manner, determining the element region of the target element in the original image according to the multiple fitting straight lines includes:
[0042] Determining the straight line equations corresponding to the multiple fitting straight lines respectively, and determining the intersection points of adjacent straight line equations;
[0043] Connecting adjacent intersection points to obtain the element region of the target element in the original image.
[0044] In an optional implementation manner, connecting adjacent intersection points to obtain the element region of the target element in the original image includes:
[0045] When the intersection points are located in the internal region of the original image, connecting adjacent intersection points to obtain the element region of the target element in the original image.
[0046] In the second aspect of the embodiments of the present application, an image processing device is further provided, and the device includes:
[0047] An image acquisition module, configured to acquire an original image;
[0048] An edge determination module, configured to determine multiple effective edges of the target element in the original image;
[0049] A line segment determination module, configured to, for any one of the effective edges, determine multiple straight line segments near the effective edge;
[0050] A line segment merging module, configured to perform a merging process on the multiple straight line segments to obtain a fitting straight line corresponding to the effective edge;
[0051] A region determination module, configured to determine the element region of the target element in the original image according to the multiple fitting straight lines.
[0052] In an optional implementation manner, the edge determination module is specifically configured to:
[0053] Extract the first edges of each element in the original image by using a first edge extraction method, and extract the second edges of the target element in the original image by using a second edge extraction method; wherein, the first edge extraction method and the first edge extraction method are different edge extraction methods;
[0054] Perform a dilation process on the second edge to obtain a dilated edge of the target element in the original image;
[0055] Perform an intersection operation on the first edge and the dilated edge to obtain multiple effective edges of the target element in the original image.
[0056] In an alternative embodiment, the apparatus further comprises:
[0057] An image denoising module, configured to perform denoising processing on the original image to obtain the denoised original image;
[0058] An image compression module, configured to perform proportional compression processing on the denoised original image to obtain a target image.
[0059] In an alternative embodiment, the line segment determination module is specifically configured to:
[0060] Use a line detection algorithm to perform line detection on the effective edges to obtain multiple straight line segments near the effective edges.
[0061] In an alternative embodiment, the line segment merging module specifically comprises:
[0062] A line segment filtering sub-module, configured to filter multiple straight line segments to obtain multiple filtered straight line segments;
[0063] A line segment merging sub-module, configured to perform merging processing on the multiple filtered straight line segments to obtain the fitting straight line corresponding to the effective edge.
[0064] In an alternative embodiment, the line segment filtering sub-module is specifically configured to:
[0065] For any one of the straight line segments, determine whether the length of the straight line segment is less than a preset length threshold;
[0066] Determine a first included angle formed between the straight line segment and the effective edge, and determine whether the first included angle is greater than a preset first included angle threshold;
[0067] In the case where the length of the straight line segment is less than the preset length threshold and / or the first included angle is greater than the preset first included angle threshold, discard the straight line segment;
[0068] Determine the remaining straight line segments among the multiple straight line segments as the multiple filtered straight line segments.
[0069] In an alternative embodiment, the line segment merging module specifically comprises:
[0070] An included angle determination sub-module, configured to determine a second included angle between any two of the multiple straight line segments;
[0071] An included angle selection sub-module, configured to select the largest second included angle from the second included angles, and determine whether the largest second included angle is less than a preset second included angle threshold;
[0072] A line segment merging sub-module, configured to merge multiple said straight line segments to obtain a fitting straight line corresponding to the effective edge when a maximum second included angle is less than a preset second included angle threshold.
[0073] In an optional embodiment, the line segment merging sub-module specifically includes:
[0074] An iteration unit, configured to store multiple said straight line segments into a line segment set, and iteratively execute the following steps until the number of line segments in the line segment set is 1, to obtain a fitting straight line corresponding to the effective edge:
[0075] A line segment merging unit, configured to select the longest straight line segment from the line segment set, and merge the longest straight line segment with any one of the remaining straight line segments in the line segment set to obtain a merged straight line segment;
[0076] A line segment storage unit, configured to store the merged straight line segment into the line segment set, and remove the longest straight line segment and the straight line segment participating in the merge from the line segment set.
[0077] In an optional embodiment, the line segment merging unit is specifically configured to:
[0078] Select an edge point from the longest straight line segment, and select a corresponding opposite edge point from any one of the remaining straight line segments in the line segment set;
[0079] Generate a merged straight line segment according to the edge point and the opposite edge point.
[0080] In an optional embodiment, the line segment storage unit is specifically configured to:
[0081] Determine a third included angle formed between the merged straight line segment and the longest straight line segment, and determine whether the third included angle is less than a preset third included angle threshold;
[0082] When the third included angle is less than the preset third included angle threshold, store the merged straight line segment into the line segment set.
[0083] In an optional embodiment, the region determination module specifically includes:
[0084] An intersection point determination sub-module, configured to determine straight line equations corresponding to multiple said fitting straight lines respectively, and determine intersection points of adjacent said straight line equations;
[0085] A region determination sub-module, configured to connect adjacent said intersection points to obtain an element region of a target element in the original image.
[0086] In an optional embodiment, the region determination sub-module is specifically configured to:
[0087] When the intersection point is located in the inner region of the original image, adjacent intersection points are connected to obtain the element region of the target element in the original image.
[0088] In the third aspect of the embodiments of the present application, an electronic device is further provided, including a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete mutual communication through the communication bus;
[0089] The memory is used to store a computer program;
[0090] The processor is configured to implement the image processing method described in any one of the first aspects when executing the program stored on the memory.
[0091] In the fourth aspect of the embodiments of the present application, a storage medium is further provided. Instructions are stored in the storage medium, and when it runs on a computer, the computer is made to execute the image processing method described in any one of the first aspects.
[0092] In the fifth aspect of the embodiments of the present application, a computer program product containing instructions is further provided. When it runs on a computer, the computer is made to execute the image processing method described in any one of the above.
[0093] The technical solution provided by the embodiments of the present application is to obtain an original image, determine multiple effective edges of a target element in the original image, for any effective edge, determine multiple straight line segments near the effective edge, perform a merging process on the multiple straight line segments to obtain a fitting straight line corresponding to the effective edge, and determine the element region of the target element in the original image according to the multiple fitting straight lines.
[0094] In this way, by merging multiple straight line segments near the effective edges of the target element in the original image, a fitting straight line that fits the edge of the target element in the original image can be obtained. According to the fitting straight line, the element region of the target element in the original image can be determined, which can fit well with the original element region of the target element in the original image. BRIEF DESCRIPTION OF THE DRAWINGS
[0095] The accompanying drawings here are incorporated into the description and form a part of this description, showing embodiments consistent with the present application, and are used together with the description to explain the principles of the present application.
[0096] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other accompanying drawings can be obtained based on these drawings without creative efforts.
[0097] One or more embodiments are illustrated by way of example in the accompanying drawings, which do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements, and unless otherwise stated, the figures in the drawings do not constitute a scale limitation.
[0098] Figure 1 It is a schematic diagram of the implementation process of an image processing method shown in an embodiment of the present application;
[0099] Figure 2 It is a schematic diagram of the implementation process of another image processing method shown in an embodiment of the present application;
[0100] Figure 3 It is a schematic diagram of the implementation process of an effective edge determination method shown in an embodiment of the present application;
[0101] Figure 4 It is a schematic diagram of the first edge of each element in a document image shown in an embodiment of the present application;
[0102] Figure 5 It is a schematic diagram of the second edge of a document in a document image shown in an embodiment of the present application;
[0103] Figure 6 It is a schematic diagram of the effective edge of a document in a document image shown in an embodiment of the present application;
[0104] Figure 7 It is a schematic diagram of the implementation process of a straight line segment merging method shown in an embodiment of the present application;
[0105] Figure 8 It is a schematic diagram of a maximum second included angle greater than or equal to a preset second included angle threshold shown in an embodiment of the present application;
[0106] Figure 9 It is a schematic diagram of the merging of the longest straight line segment AB and the straight line segment CD shown in an embodiment of the present application;
[0107] Figure 10 It is a schematic diagram of the intersection of adjacent straight line equations shown in an embodiment of the present application;
[0108] Figure 11 It is a schematic diagram of the structure of an image processing device shown in an embodiment of the present application;
[0109] Figure 12 It is a schematic diagram of the structure of an electronic device shown in an embodiment of the present application. Detailed implementation manners
[0110] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the following will clearly and completely describe the technical solutions in the embodiments of this application with reference to the accompanying drawings in the embodiments of this application. Apparently, the described embodiments are some, but not all, of the embodiments of this application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of this application without creative efforts shall fall within the scope of protection of this application.
[0111] The following disclosure provides many different embodiments or examples for implementing different structures of this application. To simplify the disclosure of this application, the components and settings of specific examples are described below. Of course, they are only examples and are not intended to limit this application. In addition, this application may repeat reference numerals and / or letters in different examples. This repetition is for the purpose of simplification and clarity and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0112] As Figure 1 shown, it is a schematic flowchart of an implementation process of an image processing method provided by an embodiment of this application. This method is applied to an electronic device and may specifically include the following steps:
[0113] S101, obtain an original image and determine multiple effective edges of a target element in the original image.
[0114] In the embodiments of this application, an original image is obtained. For the original image, for example, it may be a document image that contains a document, or it may be a certificate image that contains a certificate. The embodiments of this application do not make any limitations in this regard.
[0115] For the original image, it is necessary to determine multiple effective edges of the target element in the original image. For example, for a document image, determine the straight lines corresponding to each side of the document in the document image, that is, 4 effective edges corresponding to 4 sides. Or, for a certificate image, determine the straight lines corresponding to each side of the certificate in the certificate image, that is, 4 effective edges corresponding to 4 sides. Among them, in an embodiment of this application, the multiple effective edges of the target element are the outer edge lines that make up the shape of the target element extracted from the original image. In an embodiment of this application, the outer edge lines that make up the shape of the target element extracted from the original image have a certain distance from the actual outer edge of the target element shape and cannot fit well with the actual outer edge of the target element shape.
[0116] It should be noted that for the target elements in the original image, such as documents, certificates, cover images, posters, etc., the embodiments of the present application do not limit this. In addition, regarding the number of effective edges, it is related to the shape of the target element. For example, the shape of a document is generally rectangular. If the target element is a document, then the number of effective edges is 4. If the target element is a triangular object, then the number of effective edges is 3. If the target element is a pentagram-shaped object, then the number of effective edges is 10.
[0117] S102. For any effective edge, determine multiple straight line segments near the effective edge.
[0118] S103. Perform a merging process on the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge.
[0119] In the embodiments of the present application, for the multiple effective edges of the target element in the original image determined in the above steps, for any effective edge, determine multiple straight line segments near the effective edge. Among them, the multiple straight line segments near the effective edge can be obtained by means of a straight line detection algorithm.
[0120] For the multiple straight line segments near the effective edge, perform a merging process to obtain the fitting straight line corresponding to the effective edge. This fitting straight line is a straight line that fits the outer edge of the target element in the original image. In this way, for each effective edge of the target element in the original image, the corresponding fitting straight line can be obtained.
[0121] It should be noted that in an embodiment of the present application, for the vicinity of the effective edge, it generally refers to the first region range where the distance from any point on the effective edge is less than the first threshold. The multiple straight line segments near the effective edge refer to the straight line segments within the first region range where the distance from any point on the effective edge is less than the first threshold. The straight line segments within the first region range where the distance from any point on the effective edge is less than the first threshold mean that at least one point of the straight line segment is within this first region range. The embodiments of the present application do not limit this. Among them, the first threshold can be set according to requirements.
[0122] In another embodiment of the present application, the multiple straight line segments near the effective edge can also refer to the situation where the distance from any point on the straight line segment to any effective edge is less than the second threshold. Among them, the second threshold can be set according to requirements.
[0123] S104. According to the multiple fitting straight lines, determine the element region of the target element in the original image.
[0124] In the embodiment of the present application, multiple fitting lines can be obtained through the above steps. Each fitting line is a line that fits the outer edge of the target element in the original image. In this way, according to the multiple fitting lines, the element area of the target element in the original image can be determined, which can fit well with the original element area of the target element in the original image. Among them, the original element area is the element area where the target element actually is in the image. For the determined element area, it can be displayed for recording and sharing the target element in the original image.
[0125] For example, through the above steps, the fitting lines corresponding to each effective edge of the document in the document image are obtained. The fitting line is a line that fits the outer edge of the document in the document image. According to the multiple fitting lines, the document area of the document in the document image can be determined, which can fit well with the original document area of the document in the document image.
[0126] In this way, by combining multiple straight line segments near the effective edges of the target element in the original image, the fitting line that fits the outer edge of the target element in the original image can be obtained. According to the fitting line, the element area of the target element in the original image can be determined, which can fit well with the original element area of the target element in the original image.
[0127] As Figure 2 shown, it is a schematic flowchart of the implementation process of another image processing method provided by the embodiment of the present application. This method is applied to an electronic device and specifically may include the following steps:
[0128] S201, obtain the original image and determine multiple effective edges of the target element in the original image.
[0129] In the embodiment of the present application, the original image is obtained and multiple effective edges of the target element in the original image are determined. Among them, the first edges of each element in the original image are extracted by using the first edge extraction method, and the second edges of the target element in the original image are extracted by using the second edge extraction method. Here, the first edge extraction method and the first edge extraction method are different edge extraction methods. The second edge is subjected to a dilation process to obtain the dilated edge of the target element in the original image. An intersection operation is performed on the first edge and the dilated edge to obtain multiple effective edges of the target element in the original image.
[0130] In addition, for the original image, there will inevitably be noise, such as salt-and-pepper noise. In order to avoid excessive invalid noise affecting the subsequent processing flow, it is necessary to denoise the original image. In addition, the original image can also be compressed. A smaller-sized image helps to improve the efficiency of the subsequent processing flow.
[0131] Based on this, denoise the original image to obtain the denoised original image, perform proportional compression processing on the denoised original image to obtain the target image, and determine multiple effective edges of the target element in the target image.
[0132] Among them, filtering methods such as median filtering can be used to denoise the original image, remove salt-and-pepper noise therein, and obtain the denoised original image. Of course, other filtering methods can also be used, and the embodiments of the present application do not limit this. For the denoised original image, proportional compression processing can be performed on the denoised original image according to a certain size (for example, the length of the image is 512) to obtain the target image, and the embodiments of the present application do not limit this.
[0133] In addition, for the determination of multiple effective edges of the target element in the target image, reference can be made to the method as Figure 3 shown. As Figure 3 shown, it is a schematic flowchart of the implementation process of an effective edge determination method provided by the embodiment of the present application. This method is applied to an electronic device and specifically may include the following steps:
[0134] S301, extract the first edges of each element in the target image using the first edge extraction method, and extract the second edges of the target element in the target image using the second edge extraction method.
[0135] In the embodiment of the present application, for the target image obtained through the above denoising and compression processing, the first edges of each element (the elements here include the subsequent target elements) in the target image can be extracted using the first edge extraction method, and the second edges of the target element in the target image can be extracted using the second edge extraction method. Among them, the first edge extraction method and the first edge extraction method are different edge extraction methods.
[0136] It should be noted that in an embodiment of the present application, for the first edge extraction method, it can be an edge extraction operator. For example, it can be the Canny operator. Of course, it can also be other edge detection operators such as the Sobel operator, Prewitt operator, and Laplacian operator. The embodiments of the present application do not limit this. In addition, for the second edge extraction method, it can be a deep learning model, or a series of algorithms such as yolo or a key point detection method can be used instead. The embodiments of the present application do not limit this.
[0137] For example, in an embodiment of the present application, for the document image obtained through denoising and compression processing, the Canny operator can be used to extract the first edges of each element including the document, keyboard, and text boxes included in the document in the document image. As Figure 4 shown, the second edges of the document in the document image can be extracted using a deep learning model. As Figure 5As shown. In another embodiment of the present application, the Canny operator can also be used to extract the first edges of various elements such as documents, keyboards, and text boxes contained in the document image that has not been denoised and compressed, such as Figure 4 shown, and a deep learning model is used to extract the second edge of the document in the document image, such as Figure 5 shown.
[0138] Among them, for the deep learning model, it needs to be trained in advance, and subsequently, the deep learning model can be used to extract the second edge of the target element in the target image. For the training process of the deep learning model, specifically: obtain a sample image, where the sample edge of the target element is marked in the sample image, and there are other elements in the sample image besides the target element. Input the sample image into the initial deep learning model to obtain the predicted edge of the target element in the sample image, determine the edge loss between the sample edge and the predicted edge, train the initial deep learning model according to the edge loss, and stop training when the edge loss converges, for example, when the edge loss is less than a certain threshold, to obtain the deep learning model. By training the deep learning model, the deep learning model can well identify the effective edge of the target element, rather than the edge of other interfering elements in the original image or the processed target image.
[0139] S302. Perform dilation processing on the second edge to obtain the dilated edge of the target element in the target image.
[0140] S303. Perform an intersection operation on the first edge and the dilated edge to obtain multiple effective edges of the target element in the target image.
[0141] In the embodiment of the present application, it is very difficult to process the first edges of various elements in the target image extracted by the first edge extraction method. Therefore, in the embodiment of the present application, dilation processing is performed on the second edge of the target element in the target image extracted by the second edge extraction method, and then an intersection is made with the first edge to obtain multiple effective edges of the target element in the target image.
[0142] Specifically, perform dilation processing on the second edge of the target element in the target image to obtain the dilated edge of the target element in the target image, and perform an intersection operation on the first edges of various elements in the target image and the dilated edge of the target element in the target image to obtain multiple effective edges of the target element in the target image, such as Figure 6 shown.
[0143] It should be noted that the dilation processing of the second edge of the target element in the target image essentially takes the second edge of the target element in the target image as the center, and each pixel point that makes up the second edge extends an appropriate width (the so-called appropriate width refers to a width less than a certain threshold, where the threshold can be set according to requirements or obtained according to a certain calculation method, and is not limited in the embodiments of the present application) to both sides respectively, so as to achieve the dilation processing of the second edge of the target element in the target image. Among them, in an embodiment of the present application, for the appropriate width of extension, it can be the product of the length of the corresponding second edge and a preset value, where the product of the length of the second edge and the preset value is within the range of (0, 1). The embodiments of the present application do not limit this.
[0144] For example, for the second edge of a document in a document image, there are usually 4 second edges. Taking the first second edge as an example, with the first second edge as the center, each pixel point that makes up the first second edge extends an appropriate width to both sides respectively. Here, the appropriate width is the product of the length of the first second edge and a preset value (for example: 0.04), so as to achieve the dilation processing of the first second edge. The dilation processing of the remaining 3 second edges is similar.
[0145] In an embodiment of the present application, taking the second edge of the target element in the target image as the center, an array composed of 0 and 1 with an appropriate length as the width, and the size of this array is the same as the array composed of the second edge of the target element in the target image. By multiplying the corresponding elements of the two arrays, the dilated second edge can be obtained.
[0146] In addition, it should be noted that for the above-mentioned original image, it is also possible not to perform denoising and compression processing, directly use the first edge extraction method to extract the first edges of each element in the original image, use the second edge extraction method to extract the second edge of the target element in the original image, perform dilation processing on the second edge to obtain the dilated edge of the target element in the original image, and perform an intersection operation on the first edge and the dilated edge to obtain multiple effective edges of the target element in the original image. For the determination process of multiple effective edges of the target element in the original image, except for the denoising and compression processing of the original image, it is the same as the processing process of the target image in the above steps S301 - S303. The embodiments of the present application do not limit this.
[0147] S202. For any effective edge, use a line detection algorithm to perform line detection on the effective edge to obtain multiple straight line segments near the effective edge.
[0148] In the embodiments of the present application, multiple effective edges can be obtained through the above steps. For any effective edge, a line detection algorithm is used to detect lines on the effective edge, and multiple line segments near the effective edge are obtained.
[0149] It should be noted that in one embodiment of the present application, for the line detection algorithm, for example, it can be a probabilistic Hough line detection algorithm. Of course, it can also be a line detection algorithm such as Hough transform, Radon transform, EDLines, etc. The embodiments of the present application do not limit this.
[0150] In addition, it should be noted that for the above-mentioned effective edges, they can be the effective edges of the target elements in the original image, or the effective edges of the target elements in the target image obtained after denoising and compressing the original image. The embodiments of the present application do not limit this.
[0151] For the vicinity of the effective edge, in one embodiment of the present application, it generally refers to a first region range where the distance from any point on the effective edge is less than a first threshold. The multiple line segments near the effective edge refer to the line segments within the first region range where the distance from any point on the effective edge is less than the first threshold. The line segments within the first region range where the distance from any point on the effective edge is less than the first threshold means that at least one point of the line segment is within the first region range. The embodiments of the present application do not limit this. Among them, the first threshold can be set according to requirements.
[0152] In another embodiment of the present application, the multiple line segments near the effective edge can also refer to the case where the distance from any point on the line segment to any effective edge is less than a second threshold.
[0153] S203. Filter the multiple line segments to obtain the filtered multiple line segments.
[0154] S204. Perform a merging process on the filtered multiple line segments to obtain the fitting line corresponding to the effective edge.
[0155] In the embodiments of the present application, through the above steps, for any valid edge (i.e., the valid edge of the target element in the above-mentioned original image or the valid edge of the target element in the target image obtained after denoising and compressing the original image), a plurality of straight line segments near the valid edge can be obtained by using a straight line detection algorithm. For the plurality of straight line segments, the straight line segments that do not meet the requirements can be filtered out through a filtering operation first, and then the remaining straight line segments can be merged to obtain a fitting straight line corresponding to the valid edge. By filtering the plurality of straight line segments near the valid edge obtained by straight line detection of the valid edge, extremely short line segments (with a length less than a preset length threshold) and straight line segments with a particularly large first included angle formed with the valid edge (the first included angle is greater than a preset first included angle threshold) can be removed; interference of irrelevant straight line segments to subsequent processing is reduced, and at the same time, the number of merging processes is reduced, improving the processing efficiency of obtaining the fitting straight line corresponding to the valid edge.
[0156] Based on this, for any valid edge, the plurality of straight line segments near the valid edge are filtered to obtain a plurality of filtered straight line segments, and the plurality of filtered straight line segments are merged to obtain a fitting straight line corresponding to the valid edge. Among them, extremely short straight line segments and straight line segments with a particularly large included angle with the valid edge need to be filtered out.
[0157] To this end, for any straight line segment near the valid edge, it is judged whether the length of the straight line segment is less than a preset length threshold, the first included angle formed between the straight line segment and the valid edge is determined, and it is judged whether the first included angle is greater than a preset first included angle threshold (such as 30°). In the case where the length of the straight line segment is less than the preset length threshold and / or the first included angle is greater than the preset first included angle threshold, the straight line segment is discarded, and the remaining straight line segments among the plurality of straight line segments are determined as the plurality of filtered straight line segments.
[0158] It should be noted that for the preset length threshold, it can be the product of the length of the second edge of the target element in the original image or the target image extracted by using a deep learning model corresponding to the valid edge and a preset value (such as 0.04). For example, for the first valid edge, the preset length threshold is the product of the length of the first second edge of the target element in the original image or the target image extracted by using a deep learning model corresponding to the first valid edge and 0.04.
[0159] In addition, in an embodiment of the present application, the filtered straight line segments can be merged to obtain a fitting straight line corresponding to the valid edge, which can refer to Figure 7The method shown. In another embodiment of the present invention, multiple straight line segments near the effective edge obtained by straight line detection of the effective edge can also be directly merged without filtering to obtain the fitting straight line corresponding to the effective edge. The specific processing process can also refer to, for example, Figure 7 The method shown.
[0160] Specifically, as Figure 7 Shown, it is a schematic flowchart of the implementation process of a straight line segment merging method provided by an embodiment of the present application. This method is applied to an electronic device and may specifically include the following steps:
[0161] S701, determine the second angle between any two straight line segments among the multiple straight line segments.
[0162] S702, select the maximum second angle from the second angles and determine whether the maximum second angle is less than a preset second angle threshold.
[0163] S703, in the case where the maximum second angle is less than the preset second angle threshold, perform a merging process on the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge.
[0164] In the embodiment of the present application, for multiple straight line segments near any effective edge, after the above filtering steps, multiple filtered straight line segments can be obtained, or multiple straight line segments near the effective edge obtained by straight line detection of the effective edge can be directly processed without the above filtering steps. Based on this, it is detected whether the corresponding edge of the target element is curved. If it is curved, then the second edge of the target element in the original image or the target image extracted by the deep learning model is directly used as the fitting straight line corresponding to the effective edge. Otherwise, a straight line segment merging process is performed to obtain the fitting straight line corresponding to the effective edge.
[0165] Based on this, for multiple (filtered or unfiltered) straight line segments of any effective edge, determine the second angle between any two straight line segments among the multiple straight line segments, select the maximum second angle from the second angles, and determine whether the maximum second angle is less than a preset second angle threshold (for example, 15°). In the case where the maximum second angle is less than the preset second angle threshold, it indicates that the corresponding edge of the target element is not curved. At this time, a merging process is performed on the multiple straight line segments to obtain the fitting straight line corresponding to the effective edge. In the case where the maximum second angle is greater than or equal to the preset second angle threshold, as Figure 8 Shown, it indicates that the corresponding edge of the target element is curved. At this time, the second edge of the target element in the original image or the target image extracted by the deep learning model corresponding to the effective edge is used as the fitting straight line corresponding to the effective edge.
[0166] Among them, multiple straight line segments are merged to obtain a fitting straight line corresponding to the effective edge. Specifically: store the multiple straight line segments in a line segment set, and iteratively execute the following steps until the number of line segments in the line segment set is 1 (at this time, the straight line segment in the line segment set is the fitting straight line corresponding to the effective edge), to obtain the fitting straight line corresponding to the effective edge: select the longest straight line segment from the line segment set, merge the longest straight line segment with any remaining straight line segment in the line segment set to obtain a merged straight line segment; store the merged straight line segment in the line segment set, and remove the longest straight line segment and the straight line segment participating in the merge from the line segment set.
[0167] Among them, for the merge operation of the longest straight line segment and any remaining straight line segment in the line segment set, specifically: select an edge point from the longest straight line segment (the principle for selecting this edge point is to select any remaining straight line segment in the line segment set, and the selected edge point is the farthest from the selected remaining straight line segment in the line segment set. Among them, in an embodiment of the present application, the distance between the selected edge point and the selected remaining straight line segment in the line segment set can be the straight-line distance between the selected edge point and the endpoint of the selected remaining straight line segment in the line segment set. When one endpoint of the longest straight line segment is perpendicular to any remaining straight line segment in the line segment set, select the other endpoint of the longest straight line segment as the edge point. As Figure 9 shown, when one endpoint B of the longest straight line segment AB is perpendicular to any remaining straight line segment CD in the line segment set, select the other endpoint A of the longest straight line segment as the edge point. One endpoint being perpendicular to any remaining straight line segment in the line segment set means that among the multiple straight lines passing through this endpoint, one is perpendicular to any remaining straight line segment in the line segment set.), select the opposite edge point corresponding to the edge point from any remaining straight line segment in the selected line segment set (that is, among any remaining straight line segments in the selected line segment set, the endpoint farthest from the edge point selected from the longest straight line segment), and generate a merged straight line segment according to the edge point and the opposite edge point. Among them, for the selection of the above-mentioned edge point and opposite edge point, follow the principle of the largest distance or the longest straight line after merging, that is, the distance between the selected edge point and the opposite edge point is the largest, or the straight line segment connecting the edge point and the opposite edge point is the longest.
[0168] For example, as Figure 9As shown, the longest straight-line segment is AB. Select any remaining straight-line segment CD from the set of line segments. Since one endpoint B of the longest straight-line segment AB is perpendicular to any remaining straight-line segment CD in the selected set of line segments, among the multiple straight lines passing through endpoint B, there can be a straight line perpendicular to any remaining straight-line segment CD in the selected set of line segments. Therefore, select the other endpoint A of the longest straight-line segment AB as the edge point. Select the corresponding opposite-edge point D from any remaining straight-line segment CD in the set of line segments. The opposite-edge point D is the farthest from the edge point A. Connect the edge point A and the opposite-edge point D to obtain the merged straight-line segment AD. At this time, the distance between the edge point A and the opposite-edge point D is the largest, or the merged straight-line segment AD obtained by connecting the edge point A and the opposite-edge point D is the longest.
[0169] In addition, before storing the merged straight-line segment into the set of line segments and removing the longest straight-line segment and the straight-line segment participating in the merging from the set of line segments, it is also necessary to determine the third included angle formed between the merged straight-line segment and the longest straight-line segment, and determine whether the third included angle is less than a preset third included angle threshold (such as 1°). When the third included angle is less than the preset third included angle threshold, store the merged straight-line segment into the set of line segments, remove the longest straight-line segment and the straight-line segment participating in the merging from the set of line segments, and enter the next iteration. When the third included angle is greater than or equal to the preset third included angle threshold, discard the merged straight-line segment, retain the longest straight-line segment and the straight-line segment participating in the merging in the set of line segments, and enter the next iteration.
[0170] For example, determine the third included angle formed between the merged straight-line segment and the longest straight-line segment, and determine whether the third included angle is less than 1°. When the third included angle is less than 1°, store the merged straight-line segment into the set of line segments, remove the longest straight-line segment and the straight-line segment participating in the merging from the set of line segments, and enter the next iteration. When the third included angle is greater than or equal to 1, discard the merged straight-line segment, retain the longest straight-line segment and the straight-line segment participating in the merging in the set of line segments, and enter the next iteration.
[0171] S205. Determine the element area of the target element in the original image according to multiple fitting straight lines.
[0172] In the embodiment of the present application, through the above steps, multiple fitting straight lines can be obtained. Thus, according to the multiple fitting straight lines, the element area of the target element in the original image can be determined. Among them, each fitting straight line can be represented by a straight-line equation, and the intersection points of adjacent straight-line equations can be determined. As Figure 10 shown, the intersection points form the element area of the target element in the original image.
[0173] Specifically, determine the straight-line equations corresponding to multiple fitting straight lines, determine the intersection points of adjacent straight-line equations, and connect the adjacent intersection points to obtain the element region of the target element in the original image. Among them, if the original image undergoes the above denoising and compression processing, then for the intersection points, which are the intersection points on the target image after denoising and compression of the original image, they need to be mapped back to the original image according to the compression ratio, and then connect the adjacent intersection points to obtain the element region of the target element in the original image.
[0174] It should be noted that the validity of the intersection points of adjacent straight-line equations needs to be verified. Therefore, in the case where the above intersection points are located in the internal region of the original image, connect the adjacent intersection points to obtain the element region of the target element in the original image. In addition, if the original image undergoes the above denoising and compression processing, then for the intersection points, which are the intersection points on the target image after denoising and compression of the original image, in the case where they are located in the internal region of the target image, map them back to the original image according to the compression ratio, and then connect the adjacent intersection points to obtain the element region of the target element in the original image.
[0175] In this way, by merging multiple straight-line segments near the valid edges of the target element in the original image, the fitting straight lines that fit the outer edges of the target element in the original image can be obtained. According to the fitting straight lines, the element region of the target element in the original image can be determined, which can fit well with the original element region of the target element in the original image.
[0176] Corresponding to the above method embodiments, an embodiment of the present application also provides an image processing device, as Figure 11 shown. The device may include: an image acquisition module 1110, an edge determination module 1120, a line segment determination module 1130, a line segment merging module 1140, and a region determination module 1150.
[0177] The image acquisition module 1110 is configured to acquire an original image;
[0178] The edge determination module 1120 is configured to determine multiple valid edges of the target element in the original image;
[0179] The line segment determination module 1130 is configured to, for any one of the valid edges, determine multiple straight-line segments near the valid edge;
[0180] The line segment merging module 1140 is configured to perform a merging process on the multiple straight-line segments to obtain the fitting straight line corresponding to the valid edge;
[0181] The region determination module 1150 is configured to determine the element region of the target element in the original image according to the multiple fitting straight lines.
[0182] In an alternative embodiment, the edge determination module is specifically configured to:
[0183] Extract the first edges of each element in the original image using a first edge extraction method, and extract the second edges of the target element in the original image using a second edge extraction method; wherein, the first edge extraction method and the second edge extraction method are different edge extraction methods;
[0184] Perform a dilation process on the second edges to obtain the dilated edges of the target element in the original image;
[0185] Perform an intersection operation on the first edges and the dilated edges to obtain multiple effective edges of the target element in the original image.
[0186] In an optional implementation manner, the device further includes:
[0187] An image denoising module, configured to perform a denoising process on the original image to obtain the denoised original image;
[0188] An image compression module, configured to perform a proportional compression process on the denoised original image to obtain a target image.
[0189] In an optional implementation manner, the line segment determination module is specifically configured to:
[0190] Use a line detection algorithm to perform line detection on the effective edges to obtain multiple line segments near the effective edges.
[0191] In an optional implementation manner, the line segment merging module specifically includes:
[0192] A line segment filtering sub-module, configured to filter multiple line segments to obtain multiple filtered line segments;
[0193] A line segment merging sub-module, configured to perform a merging process on multiple filtered line segments to obtain a fitting line corresponding to the effective edges.
[0194] In an optional implementation manner, the line segment filtering sub-module is specifically configured to:
[0195] For any one of the line segments, determine whether the length of the line segment is less than a preset length threshold;
[0196] Determine a first included angle formed between the line segment and the effective edge, and determine whether the first included angle is greater than a preset first included angle threshold;
[0197] In the case where the length of the line segment is less than the preset length threshold, and / or, the first included angle is greater than the preset first included angle threshold, discard the line segment;
[0198] Determine the remaining straight line segments among the multiple straight line segments as the filtered multiple straight line segments.
[0199] In an optional embodiment, the line segment merging module specifically includes:
[0200] An included angle determination sub-module, configured to determine a second included angle between any two of the multiple straight line segments;
[0201] An included angle selection sub-module, configured to select the largest second included angle from the second included angles, and determine whether the largest second included angle is less than a preset second included angle threshold;
[0202] A line segment merging sub-module, configured to perform a merging process on the multiple straight line segments when the largest second included angle is less than the preset second included angle threshold, to obtain the fitting straight line corresponding to the effective edge.
[0203] In an optional embodiment, the line segment merging sub-module specifically includes:
[0204] An iteration unit, configured to store the multiple straight line segments in a line segment set, and iteratively execute the following steps until the number of line segments in the line segment set is 1, to obtain the fitting straight line corresponding to the effective edge:
[0205] A line segment merging unit, configured to select the longest straight line segment from the line segment set, and merge the longest straight line segment with any one of the remaining straight line segments in the line segment set to obtain a merged straight line segment;
[0206] A line segment storage unit, configured to store the merged straight line segment in the line segment set, and remove the longest straight line segment and the straight line segment participating in the merging from the line segment set.
[0207] In an optional embodiment, the line segment merging unit is specifically configured to:
[0208] Select edge points from the longest straight line segment, and select corresponding opposite edge points from any one of the remaining straight line segments in the line segment set;
[0209] Generate a merged straight line segment according to the edge points and the opposite edge points.
[0210] In an optional embodiment, the line segment storage unit is specifically configured to:
[0211] Determine a third included angle formed between the merged straight line segment and the longest straight line segment, and determine whether the third included angle is less than a preset third included angle threshold;
[0212] When the third included angle is less than a preset third included angle threshold, store the combined straight line segment in the line segment set.
[0213] In an alternative embodiment, the region determination module specifically includes:
[0214] An intersection determination sub-module, configured to determine the respective straight line equations corresponding to multiple fitting straight lines, and determine the intersections of adjacent straight line equations;
[0215] A region determination sub-module, configured to connect adjacent intersections to obtain the element region of the target element in the original image.
[0216] In an alternative embodiment, the region determination sub-module is specifically configured to:
[0217] When the intersection is located in the internal region of the original image, connect adjacent intersections to obtain the element region of the target element in the original image.
[0218] The embodiment of the present application also provides an electronic device, as Figure 12 shown, including a processor 121, a communication interface 122, a memory 123, and a communication bus 124. Among them, the processor 121, the communication interface 122, and the memory 123 complete mutual communication through the communication bus 124.
[0219] The memory 123 is used to store a computer program;
[0220] The processor 121, when executing the program stored on the memory 123, implements the following steps:
[0221] Obtain an original image, and determine multiple effective edges of the target element in the original image; for any one of the effective edges, determine multiple straight line segments near the effective edge; perform a merging process on the multiple straight line segments to obtain a fitting straight line corresponding to the effective edge; determine the element region of the target element in the original image according to the multiple fitting straight lines.
[0222] The communication bus mentioned in the above electronic device may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity, only a thick line is shown in the figure, but it does not mean that there is only one bus or one type of bus.
[0223] The communication interface is used for communication between the above-mentioned electronic device and other devices.
[0224] The memory may include a random access memory (RAM) and may also include a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0225] The above-mentioned processor may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0226] In another embodiment provided by the present application, a storage medium is also provided. Instructions are stored in the storage medium, and when it runs on a computer, the computer is made to execute the image processing method described in any one of the above embodiments.
[0227] In another embodiment provided by the present application, a computer program product containing instructions is also provided. When it runs on a computer, the computer is made to execute the image processing method described in any one of the above embodiments.
[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a storage medium or transmitted from one storage medium to another. For example, the computer instructions can be transmitted from a website, computer, server, or data center to another website, computer, server, or data center by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wirelessly (such as infrared, wireless, microwave, etc.). The storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, hard disk, magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)).
[0229] It should be noted that in this document, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising a..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the element.
[0230] Each embodiment in this specification is described in a related manner. The same or similar parts among the embodiments can be referred to each other, and the differences between each embodiment and other embodiments are emphasized. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
[0231] The above is only a preferred embodiment of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.
Claims
1. An image processing method, characterized in that: The method comprises: Acquire an original image, and determine a plurality of valid edges of a target element in the original image; For any of the valid edges, determining a plurality of straight line segments near the valid edge; Merging the plurality of straight line segments to obtain a fitting straight line corresponding to the effective edge; An element region of a target element in the original image is determined according to the plurality of fitted straight lines.
2. The method according to claim 1, characterized in that The determining of a plurality of valid edges of the target element in the original image comprises: Extracting first edges of each element in the original image using a first edge extraction method, and extracting second edges of target elements in the original image using a second edge extraction method; wherein the first edge extraction method and the second edge extraction method are different edge extraction methods; Performing dilation processing on the second edge to obtain a dilated edge of the target element in the original image; An intersection operation is performed on the first edge and the dilated edge to obtain multiple valid edges of the target element in the original image.
3. The method according to claim 2, characterized in that Before extracting the first edge of each element in the original image by using the first edge extraction method and extracting the second edge of the target element in the original image by using the second edge extraction method, the method further includes: Performing denoising on the original image to obtain the denoised original image; The denoised original image is subjected to proportional compression processing to obtain a target image.
4. The method according to claim 1, characterized in that The determining of a plurality of straight line segments near the effective edge comprises: A straight line detection algorithm is used to perform straight line detection on the effective edge to obtain a plurality of straight line segments near the effective edge.
5. The method according to claim 1, characterized in that Before merging the plurality of straight line segments to obtain the fitted straight line corresponding to the effective edge, the method further includes: Filtering the plurality of straight line segments to obtain a plurality of filtered straight line segments; The filtered plurality of straight line segments are merged to obtain a fitting straight line corresponding to the effective edge.
6. The method according to claim 5, characterized in that The filtering of the plurality of straight line segments to obtain the filtered plurality of straight line segments comprises: For any of the straight line segments, determining whether the length of the straight line segment is less than a preset length threshold; Determine a first angle formed between the straight line segment and the valid edge, and determine whether the first angle is greater than a preset first angle threshold; When the length of the straight line segment is less than a preset length threshold, and / or the first angle is greater than a preset first angle threshold, discard the straight line segment; The remaining straight line segments among the plurality of straight line segments are determined as the plurality of straight line segments after filtering.
7. The method according to claim 1, characterized in that The merging of the plurality of straight line segments to obtain the fitted straight line corresponding to the effective edge includes: Determine a second angle between any two of the plurality of straight line segments; Selecting a maximum second angle from the second angles, and determining whether the maximum second angle is less than a preset second angle threshold; When the maximum second angle is less than the preset second angle threshold, a plurality of straight line segments are merged to obtain a fitting straight line corresponding to the effective edge.
8. The method according to claim 7, characterized in that The merging of the plurality of straight line segments to obtain the fitted straight line corresponding to the effective edge includes: The plurality of straight line segments are stored in a line segment set, and the following steps are iteratively performed until the number of line segments in the line segment set is 1, and the fitting straight line corresponding to the valid edge is obtained: Selecting the longest straight line segment from the line segment set, and merging the longest straight line segment with any remaining straight line segment in the line segment set to obtain a merged straight line segment; The merged straight line segment is stored in the line segment set, and the longest straight line segment and the straight line segment involved in the merge are removed from the line segment set.
9. The method according to claim 8, characterized in that The step of merging the longest straight line segment with any remaining straight line segment in the line segment set to obtain a merged straight line segment includes: Select an edge point from the longest straight line segment, and select an opposite edge point corresponding to the edge point from any remaining straight line segment in the line segment set; A merged straight line segment is generated according to the edge point and the opposite edge point.
10. The method according to claim 8, characterized in that The step of storing the merged straight line segment into the segment set includes: Determine a third angle formed between the combined straight line segment and the longest straight line segment, and determine whether the third angle is less than a preset third angle threshold; When the third angle is less than a preset third angle threshold, the merged straight line segment is stored in the segment set.
11. The method according to claim 1, characterized in that: The step of determining the element region of the target element in the original image according to the plurality of fitted straight lines includes: Determine the linear equations corresponding to the plurality of fitted straight lines, and determine the intersection points of the adjacent linear equations; Adjacent intersection points are connected to obtain an element region of the target element in the original image.
12. An image processing device, characterized in that: The device comprises: An image acquisition module, used for acquiring original images; An edge determination module, used for determining a plurality of valid edges of a target element in the original image; A line segment determination module, used for determining, for any of the valid edges, a plurality of straight line segments near the valid edge; A line segment merging module, used for merging a plurality of the straight line segments to obtain a fitting straight line corresponding to the effective edge; The region determination module is used to determine the element region of the target element in the original image according to the plurality of fitted straight lines.
13. A storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 11 is implemented.