Roof contour regularizing method, device and storage medium

By acquiring the outline of the roof area to be identified and constructing an initial outline, and then iteratively adjusting it using the target loss function, the problem of poor roof outline regularization in existing technologies is solved, and high-precision roof outline regularization is achieved.

CN122199820APending Publication Date: 2026-06-12HEFEI SUNGROW RENEWABLE ENERGY SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HEFEI SUNGROW RENEWABLE ENERGY SCI & TECH CO LTD
Filing Date
2026-04-20
Publication Date
2026-06-12

AI Technical Summary

Technical Problem

When dealing with irregular roof contours, especially in scenarios where the roof contour has sloping edges, existing technologies result in a large deviation between the normalized roof contour and the original roof contour, leading to poor normalization results.

Method used

By acquiring the outline of the roof area to be identified, the original roof outline is determined, and each vertex is traversed to construct the initial outline. The initial outline points are iteratively adjusted in combination with the target loss function, and the user's selection intention is introduced as prior information to optimize the outline regularization direction.

🎯Benefits of technology

It effectively reduces iteration deviation, improves the accuracy of roof contour regularization results, and ensures the degree of fit between the regularized roof contour and the original roof contour.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122199820A_ABST
    Figure CN122199820A_ABST
Patent Text Reader

Abstract

The application discloses a roof contour regularization method and device and a storage medium, relates to the technical field of data processing, and discloses a roof contour regularization method, which comprises the following steps: obtaining a to-be-recognized roof area, and extracting the contour of the to-be-recognized roof area to obtain a to-be-recognized roof contour, wherein the to-be-recognized roof area is a user frame selection area; determining an original roof contour corresponding to the to-be-recognized roof area; traversing each vertex of the to-be-recognized roof contour, determining contour points on the original roof contour that are aligned with the vertices, and constructing an initial contour according to the contour points that are aligned with the vertices; and based on a target loss function and the initial contour, iteratively adjusting the contour points of the initial contour to obtain a regularized roof contour. Through the technical scheme, the deviation between the regularized roof contour and the original roof contour is reduced, and the regularization precision of the roof contour is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to methods, apparatus and storage media for roof contouring. Background Technology

[0002] Currently, it's possible to automatically extract the original roof outline coordinates from a building's 3D model. To generate design drawings, these coordinates can be directly projected onto a plane to obtain the building's roof's planar coordinates. However, because the extracted original roof outline coordinates exhibit significant unevenness at the edges, directly passing them into the design drawing generation process is unacceptable for subsequent calculations. Therefore, it's necessary to normalize the original roof outline coordinates.

[0003] The roof outline regularization scheme of related technologies can make the edges on the original roof outline as parallel as possible to each other, the adjacent edges as perpendicular as possible to each other, and the adjacent and parallel line segments as collinear as possible, thereby achieving the regularization of the original roof outline.

[0004] However, when dealing with irregular roof outlines, especially in scenarios where the roof outline has sloping edges, excessive orthogonality in some areas of the roof outline can lead to a large deviation between the normalized roof outline and the original roof outline, resulting in a poor normalization effect of the original roof outline. Summary of the Invention

[0005] The main objective of this application is to provide a method, apparatus, and storage medium for roof contour straightening, which aims to reduce the deviation between the straightened roof contour and the original roof contour and improve the straightening accuracy of the roof contour.

[0006] To achieve the above objectives, this application proposes a method for roof contour regularization, comprising: Obtain the roof area to be identified and extract the outline of the roof area to be identified to obtain the roof outline to be identified, where the roof area to be identified is the area selected by the user. Determine the original roof outline corresponding to the roof area to be identified; Traverse each vertex of the roof outline to be identified, determine the outline points on the original roof outline that are aligned with each vertex, and construct the initial outline based on the outline points aligned with each vertex. Based on the objective loss function and the initial contour, the contour points of the initial contour are iteratively adjusted to obtain the regularized roof contour.

[0007] In addition, to achieve the above objectives, this application also proposes a roof contour straightening device, including: a memory, a processor, and a roof contour straightening program stored in the memory and executable on the processor, the roof contour straightening program being configured to implement the steps of the roof contour straightening method described above.

[0008] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, storing a roof contour regularization program, which, when executed by a processor, implements the steps of the roof contour regularization method as described above.

[0009] The one or more technical solutions proposed in this application have at least the following technical effects: by taking the user-selected area as the roof area to be identified and extracting its contour, and combining the contour points on the original roof contour that are aligned with the vertices of the selected contour to construct an initial contour, the user's selection intention is introduced as effective prior information, making the starting point of iterative optimization more in line with the actual roof contour direction; and then iteratively adjusting the initial contour points based on the target loss function, it can fully rely on the user's prior intention to guide the optimization direction of contour regularization, effectively adapt to various complex roof scenarios, reduce iterative deviation, and thus improve the accuracy of the roof contour regularization result. Attached Figure Description

[0010] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0011] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 A flowchart illustrating an embodiment of the roof contour straightening method of this application; Figure 2 This is a flowchart illustrating Embodiment 2 of the roof contour straightening method of this application. Figure 3 This is a flowchart illustrating Embodiment 2 of the roof contour straightening method of this application. Figure 4 This is a schematic diagram of the roof outline to be identified in this application and the original roof outline; Figure 5 This is a structural schematic diagram of the roof contour straightening device of this application.

[0013] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0014] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.

[0015] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.

[0016] Currently, it is possible to automatically extract the original roof outline coordinates from the 3D model of a building. In order to generate design drawings, the original roof outline coordinates can be directly projected onto a plane to obtain the planar coordinates of the building roof. However, in practical applications, it has been found that: (1) the 3D model has unevenness at the roof edge, which is an error caused by modeling accuracy; (2) the roof edge is bulged due to the presence of pipes, ladders and other devices leading to the roof; (3) the roof height is low and it is closely connected to large trees near the roof; (4) the building roof outline itself is irregular. These problems result in obvious unevenness at the edges of the extracted original roof outline coordinates. If the original roof outline coordinates are directly passed into the step of generating design drawings, it is unacceptable for the subsequent calculation process. Therefore, it is necessary to normalize the original roof outline coordinates.

[0017] The roof outline regularization scheme of related technologies can make the edges on the original roof outline as parallel as possible to each other, the adjacent edges as perpendicular as possible to each other, and the adjacent and parallel line segments as collinear as possible, thereby achieving the regularization of the original roof outline.

[0018] However, when dealing with irregular roof outlines, especially in scenarios where the roof outline has sloping edges, excessive orthogonality in some areas of the roof outline, and the use of related technologies for roof outline regularization schemes, will result in a large deviation between the regularized roof outline and the original roof outline, leading to a poor regularization effect of the original roof outline.

[0019] To address the aforementioned shortcomings, this application proposes a roof contour regularization method. The main technical solution includes: acquiring the roof region to be identified and extracting its contour to obtain the roof contour to be identified, wherein the roof region to be identified is the user-selected area; determining the original roof contour corresponding to the roof region to be identified; traversing each vertex of the roof contour to be identified, determining the contour points aligned with each vertex on the original roof contour, and constructing an initial contour based on the contour points aligned with each vertex; and iteratively adjusting the contour points of the initial contour based on the target loss function and the initial contour to obtain the regularized roof contour.

[0020] By using the user-selected area as the roof area to be identified and extracting its contour, and combining it with contour points aligned with the vertices of the selected contour on the original roof contour to construct an initial contour, the user's selection intent is introduced as effective prior information, making the starting point of iterative optimization more closely match the actual roof contour. Then, the initial contour points are iteratively adjusted based on the target loss function. This fully relies on the user's prior intent to guide the optimization direction of contour regularization, effectively adapting to various complex roof scenarios, reducing iteration bias, and thus improving the accuracy of the roof contour regularization results.

[0021] It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or roof contour straightening device capable of performing the above functions. The following description uses a roof contour straightening device as an example to illustrate this embodiment and the subsequent embodiments.

[0022] Based on this, the embodiments of this application provide a method for regularizing the roof outline, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the roof contour straightening method of this application. In this embodiment, the roof contour straightening method includes steps S10 to S40: Step S10: Obtain the roof area to be identified and extract the outline of the roof area to be identified to obtain the roof outline to be identified, wherein the roof area to be identified is the area selected by the user. Roof area to be identified: This refers to the specific roof area that needs to undergo contour normalization. This area is determined by the user through interactive selection and is the scope of all subsequent contour processing operations. For example, if a user selects the roof of a residential building on a satellite image using the mouse, the area within that selection is the roof area to be identified. Users can select the roof area to be identified according to their actual needs.

[0023] Roof outline to be identified: This refers to the outline of the roof area to be identified, which is the basis for subsequent outline alignment and adjustment. Its function is to provide the initial shape of the roof outline, reflecting the general outline characteristics of the roof, and providing a reference for comparison and regularization with the subsequent original roof outline. For example, the outline of the roof area to be identified, detected by the user's selected bounding box using an edge detection algorithm, is the roof outline to be identified.

[0024] In one optional approach: the user selects the roof area to be identified through a graphical interface, for example, displaying a color image on the roof area display screen. The user clicks the left mouse button to determine the starting point of the selection, drags the mouse to the appropriate position, and releases the left mouse button to form a rectangular or polygonal selection area. The system automatically captures the roof-related pixel areas within the selection area to obtain the roof area to be identified. Then, the color image of the selection area is converted to grayscale, and Gaussian blur is applied to eliminate noise interference from image noise on contour extraction. Appropriate high and low thresholds are set, and edge pixels within the roof area to be identified are detected. Continuous edge pixels are connected in sequence to form a closed contour line, which is the roof contour to be identified.

[0025] In another optional method: the user selects the roof area to be identified by inputting a coordinate range. For example, the user manually inputs the planar coordinates of the upper left and lower right corners of the roof area to be identified, and then extracts the corresponding image area according to the coordinate range to obtain the roof area to be identified. Then, starting from any edge pixel in the roof area to be identified, the user tracks the adjacent edge pixels in a clockwise direction, determines whether the adjacent pixels are edge pixels, and continues until returning to the starting pixel to form a complete closed contour, which is the roof contour to be identified.

[0026] Step S20: Determine the original roof outline of the roof area to be identified; Original roof outline: refers to the outline corresponding to the area of ​​the roof to be identified, and that is closest to the actual shape of the roof. Its function is to serve as a benchmark for outline regularization, ensuring that the regularized roof outline fits the actual shape of the roof and avoiding excessive deviation between the regularized roof outline and the actual roof outline.

[0027] In one alternative approach: after determining the roof area to be identified and the roof outline to be identified, the three-dimensional spatial coordinate information of the roof area to be identified can be obtained, and the original roof outline can be constructed using this three-dimensional spatial coordinate information.

[0028] Another optional method is to first input three-dimensional spatial coordinate information, construct and display the original roof outline using this three-dimensional spatial coordinate information, and then the user selects the original roof outline to obtain the roof area to be identified, and then identifies the outline of the roof area to be identified to obtain the roof outline to be identified.

[0029] It should be noted that the original roof outline and the roof outline to be identified have similar outline trends, which allows the roof outline to be identified to be used as prior knowledge for subsequent outline point alignment operations, thereby improving the alignment accuracy of subsequent outline points.

[0030] Step S30: Traverse each vertex of the roof outline to be identified, determine the outline points on the original roof outline that are aligned with each vertex, and construct the initial outline based on the outline points aligned with each vertex. Each vertex of the roof outline to be identified: refers to the intersection of two adjacent edges in the roof outline line to be identified, and each vertex has specific coordinate information. Each vertex can be found as a corresponding outline point on the original roof outline.

[0031] Initial contour: This refers to the preliminary contour constructed from the vertices of the roof contour to be identified, after finding the corresponding aligned contour points on the original roof contour. This initial contour provides an initial solution for subsequent error calculation and iterative optimization, clarifying the iteration direction and avoiding morphological deviations caused by directly adjusting the original roof contour. For example, each vertex of the roof contour to be identified is matched with the nearest contour point on the original roof contour, and then these corresponding points are connected sequentially to form the initial contour.

[0032] In one alternative approach: For each vertex, calculate the Euclidean distance (i.e., the straight-line distance between the vertex and all contour points on the original roof contour) and determine the contour point with the smallest distance as the contour point aligned with the vertex; then, in the order of the vertices of the roof contour to be identified, connect the corresponding aligned contour points in sequence to form a closed contour line, which is the initial contour.

[0033] In another alternative approach: For each vertex, calculate the Manhattan distance (i.e., the sum of the distances between the two points in the X and Y directions) between the vertex and all the contour points on the original roof profile, and select the contour point with the smallest distance as the contour point aligned with the vertex; then, according to the vertex order of the roof profile to be identified, connect all the aligned contour points in sequence to form a complete initial profile.

[0034] Understandably, by traversing the vertices and determining the alignment points, a preliminary correspondence between the roof outline to be identified and the original roof outline is achieved, establishing a connection bridge between the two. Constructing the initial outline provides an initial form for subsequent iterative adjustments, avoiding the form chaos caused by directly adjusting the original outline. At the same time, the initial outline retains the general structure of the roof outline to be identified, laying the foundation for subsequent optimization and adjustments.

[0035] Step S40: Based on the target loss function and the initial contour, the contour points of the initial contour are iteratively adjusted to obtain the regularized roof contour.

[0036] The target loss function is a mathematical function used to calculate the error between the initial profile and the original roof profile. It quantifies the deviation between the two by setting multiple constraints. Its role is to measure the degree of fit between the initial profile and the original roof profile, providing direction for profile adjustment and ensuring that iterative adjustments are made in the direction of minimizing error. For example, the target loss function can comprehensively judge the difference between the initial profile and the original roof profile by calculating errors in multiple dimensions such as vertex distance, shape similarity, spatial elevation error, orthogonality of adjacent edges, area similarity, and perimeter similarity.

[0037] Iterative adjustment refers to the process of repeatedly calculating the error of the target loss function, continuously updating the coordinates of the contour points of the initial contour, and gradually reducing the error between the initial contour and the original roof contour until the iteration termination condition is met. Its purpose is to progressively optimize the shape of the initial contour, making it increasingly conform to the original roof contour, ultimately resulting in a regular and accurate roof contour. For example, after each calculation of the error between the initial contour and the original roof contour, the coordinates of the contour points are adjusted, and the error is recalculated, repeating this process until the error is less than a preset threshold.

[0038] The standardized roof outline refers to the final roof outline that has the smallest error compared to the original roof outline after iterative adjustments. Its purpose is to provide standardized outline data for subsequent roof-related applications such as modeling and photovoltaic power station construction, solving the problem of low accuracy of the original roof outline.

[0039] In one optional approach: the initial contour is input into a preset target loss function to calculate the error between the initial contour and the original roof contour, and an iteration termination condition is set; if the termination condition is not met, the contour point coordinates of the initial contour are adjusted using the gradient descent method, and the X-axis and Y-axis coordinates of each contour point are updated along the direction of error reduction to obtain the updated contour. The updated contour is then input into the target loss function to recalculate the error, and the above process is repeated until the iteration termination condition is met. The contour at this point is the regularized roof contour.

[0040] In another optional approach: the initial contour is input into the target loss function, the comprehensive error is calculated through multiple constraint terms, and the iteration termination condition is set; if the termination condition is not met, the coordinates of the contour points of the initial contour are updated, the error descent direction and iteration step size are determined according to the second derivative of the error, the coordinates of each contour point are adjusted based on the error descent direction and iteration step size to obtain the updated contour, the error is recalculated and it is determined whether the termination condition is met, and the iteration is repeated until the requirements are met, and finally the regularized roof contour is obtained.

[0041] The iteration termination conditions mentioned above can be set to conditions such as the error being less than a preset threshold or the number of iterations reaching a preset maximum value.

[0042] Understandably, iterative adjustment is the core step in achieving a regular roof profile. By quantifying the deviation between the initial profile and the original roof profile through the objective loss function, the adjustment direction of the profile points is guided, the error is gradually reduced, the initial profile is continuously optimized, and finally a regular profile that fits the actual roof is obtained, thus achieving a regular roof profile.

[0043] In this embodiment, the user-selected area is used as the roof area to be identified, and its outline is extracted. An initial outline is constructed by combining the outline points on the original roof outline that are aligned with the vertices of the selected outline. The user's selection intention is introduced as effective prior information, making the starting point of iterative optimization more in line with the actual roof outline. Then, the initial outline points are iteratively adjusted based on the target loss function. This fully relies on the user's prior intention to guide the optimization direction of the outline regularization, effectively adapting to various complex roof scenarios, reducing iteration deviation, and thus improving the accuracy of the roof outline regularization result.

[0044] In one feasible implementation, determining the contour points aligned with each vertex on the original roof contour in step S30 may include steps S31-S32: Step S31: Traverse each vertex of the roof outline to be identified, and for each vertex, determine the distance between the vertex and each outline point on the original roof outline. Distance: refers to the spatial distance between the vertex of the roof profile to be identified and the outline point of the original roof profile. It is used to quantify the positional deviation between the two points. Distance calculation methods can include Euclidean distance, Manhattan distance, etc.

[0045] In one optional approach: each vertex of the roof profile to be identified is selected sequentially, and the planar coordinates of each vertex are obtained; for each vertex, all profile points on the original roof profile are traversed, the planar coordinates of each profile point are obtained, the distance between them is calculated using the Euclidean distance formula, and the distance value between each profile point and the vertex is recorded, ensuring that each vertex completes the distance calculation with all profile points on the original roof profile.

[0046] Understandably, by traversing the vertices and calculating the distance between each vertex and each contour point of the original roof outline, the positional deviation between the vertex and the contour point is quantified by the distance, providing a basis for the subsequent selection of the contour point with the shortest distance, and ensuring that the aligned contour point can fit the position of the corresponding vertex to the greatest extent.

[0047] Step S32: From all the contour points of the original roof contour, obtain the contour point that is closest to the vertex, and use it as the contour point on the original roof contour that is aligned with the vertex.

[0048] Aligned contour point: refers to the contour point on the original roof contour that is closest to a vertex of the roof contour to be identified. This point has the smallest positional deviation from the corresponding vertex and is the key node connecting the roof contour to be identified and the original roof contour, used to construct the initial contour.

[0049] In one alternative approach: For each vertex, sort its distance values ​​to all contour points on the original roof contour in ascending order of distance. Select the contour point corresponding to the first distance value after sorting, which is the contour point with the shortest distance to the vertex. Mark this contour point as the contour point aligned with the vertex and record the correspondence between the two to ensure that each vertex has a unique aligned contour point.

[0050] In another alternative approach: For each vertex, iterate through the distance values ​​between it and all contour points on the original roof contour, set a minimum initial distance value, compare each distance value with the minimum initial distance value in turn, if the current distance value is less than the minimum initial distance value, update the minimum initial distance value and record the corresponding contour point. After the traversal is complete, the finally recorded contour point is the contour point with the shortest distance to that vertex, and is used as the alignment contour point.

[0051] Understandably, by selecting the contour points with the shortest distance as alignment points, it is possible to ensure that the vertices of the roof contour to be identified correspond precisely to the contour points of the original roof contour, minimizing the positional deviation between the two, providing accurate nodes for the subsequent construction of the initial contour, and ensuring that the initial contour can fit the shape of the original roof contour.

[0052] In this embodiment, by traversing each vertex of the roof contour to be identified and determining the distance between each vertex and each contour point on the original roof contour, the contour point with the shortest distance to the vertex is obtained from all contour points of the original roof contour and used as the contour point on the original roof contour that is aligned with the vertex. This ensures that each vertex can find the most fitting original roof contour point, avoiding initial contour distortion caused by excessive alignment deviation, laying the foundation for subsequent iterative adjustments, and further improving the accuracy and reliability of the roof contour regularization.

[0053] In one feasible implementation, step S40 iteratively adjusts the contour points of the initial contour based on the target loss function and the initial contour to obtain the regularized roof contour, including: Step S41: Input the initial profile into the target loss function, and calculate the error between the initial profile and the original roof profile through each constraint term of the target loss function. Constraint terms: These are specific calculation terms in the target loss function used to quantify the deviation in a certain dimension between the initial profile and the original roof profile. Each constraint term corresponds to a type of deviation, and multiple constraint terms together constitute the target loss function, ensuring the comprehensiveness of error calculation. In this embodiment, the constraint terms can be expanded to multiple terms according to actual conditions, making the regularized roof profile more accurate. These constraint terms can be vertex distance error terms, shape similarity error terms, spatial elevation error terms, adjacent edge orthogonality error terms, area similarity error terms, and perimeter similarity error terms.

[0054] Error: refers to the degree of deviation between the initial profile and the original roof profile. It is calculated through the constraint terms of the target loss function and serves as the basis for determining whether the initial profile needs further adjustment. The smaller the error, the higher the degree of fit between the initial profile and the original roof profile; conversely, the larger the error, the lower the degree of fit between the initial profile and the original roof profile.

[0055] In one optional approach: the coordinates of all contour points of the initial contour and the coordinates of all contour points of the original roof contour are input into each constraint term of the target loss function; for each constraint term, the error between the initial contour and the original roof contour in the dimension corresponding to that constraint term is calculated, and the error calculation of all constraint terms is completed in sequence to obtain the error value corresponding to each constraint term.

[0056] Understandably, by calculating the error through each constraint, the deviation between the initial profile and the original roof profile can be quantified from multiple dimensions, avoiding the one-sidedness caused by single-dimensional error calculation and ensuring the comprehensiveness and accuracy of error assessment.

[0057] Step S42: Determine the total error between the initial profile and the original roof profile based on the errors calculated from each constraint. Total error: This refers to the overall deviation between the initial profile and the original roof profile after comprehensively processing the errors calculated from each constraint term in the target loss function. It can fully reflect the fit between the two. Each constraint term has a corresponding error. The total error can be obtained by adding or weighting the errors calculated from all constraint terms.

[0058] In one alternative approach: the total error is determined by weighted summation. A corresponding weight is pre-assigned to each constraint item. This weight can be set according to the importance of each constraint item. For example, the weight of the constraint item that has a greater impact on accuracy is set higher. The error value of each constraint item is multiplied by the corresponding weight, and then all the weighted error values ​​are added together. The sum obtained is the total error between the initial profile and the original roof profile.

[0059] Another alternative approach is to determine the total error by using the average error method. This involves summing the error values ​​calculated for all constraint terms to obtain the total error, and then dividing the total error by the number of constraint terms to obtain the average value, which is the total error. This method can reflect the deviation of each dimension in a balanced way.

[0060] Understandably, the total error can comprehensively reflect the overall fit between the initial profile and the original roof profile, avoiding the problem that the error of a single constraint term cannot fully evaluate the profile deviation, providing a core basis for the determination of iteration termination and profile adjustment, and ensuring that the iterative adjustment can proceed in the direction of minimizing the overall error.

[0061] Step S43: If the total error does not meet the iteration termination condition, update the contour point coordinates of the initial contour to obtain the updated contour. Input the updated contour into the target loss function to obtain the total error between the updated contour and the original roof contour. Iteration termination condition: refers to the preset standard used to determine whether the iterative adjustment should stop. It may include the total error being less than a preset threshold, the number of iterations reaching a preset maximum value, etc. When this condition is met, the iteration stops, and the outline at this time is the regularized roof outline.

[0062] Outline point coordinate update: This refers to adjusting the coordinates of each outline point on the initial outline according to the magnitude and direction of the total error, so that the outline points move to the corresponding positions of the original roof outline, thereby reducing the error between the two.

[0063] Updated profile: refers to the new profile obtained after adjusting the coordinates of the profile points of the initial profile. The error between this new profile and the original roof profile is smaller than that of the initial profile before adjustment, and it is the object of the next iteration adjustment.

[0064] In one optional approach: the preset iteration termination condition is that the total error is less than a preset value. If the calculated total error is greater than or equal to the preset value, it is determined that the termination condition has not been met. The gradient descent method is used to update the coordinates of the contour points of the initial contour. The gradient of the total error with respect to the coordinates of each contour point is calculated to determine the error descent direction. A fixed iteration step size is set, and the coordinates of each contour point are adjusted along the error descent direction to obtain the updated contour. The updated contour point coordinates are then input into the target loss function, and the above operation is repeated to calculate the updated total error, preparing for the next iteration judgment.

[0065] In another optional approach: the preset iteration termination condition is that the number of iterations reaches a preset number and the total error is less than a preset value. If the current total error is not less than the preset value or the number of iterations has not reached the preset number, the termination condition is not met. The gradient descent method is used to update the coordinates of the contour points. Combining the previous update direction and the current gradient direction, the coordinate update direction and step size are determined, and the coordinates of each contour point are adjusted to obtain the updated contour. The updated contour is input into the target loss function, and the errors of each constraint term and the total error are recalculated to enter the next iteration loop.

[0066] Understandably, when the total error does not meet the termination condition, updating the contour point coordinates can gradually reduce the error between the initial contour and the original roof contour, thus continuously optimizing the contour. Recalculating the total error of the updated contour allows for real-time acquisition of the contour adjustment effect, providing a basis for subsequent iterative judgments and ensuring that iterative adjustments can continuously move towards the direction of minimum error.

[0067] Step S44: If the total error satisfies the iteration termination condition, the initial profile is taken as the regularized roof profile.

[0068] In one optional approach: the preset iteration termination condition is that the total error is less than a preset value. When the calculated total error is less than the preset value, it is determined that the iteration termination condition is met. At this time, the iteration adjustment is stopped, and the current contour (or the contour after the last update if multiple iterations have been performed) is determined as the regularized roof contour. The coordinate information of the contour is saved for subsequent applications.

[0069] In another optional approach: the preset iteration termination condition is that the number of iterations reaches a preset number and the total error is less than a preset value. When the iteration termination condition is met, it is determined that the iteration can be terminated, the coordinate update operation is stopped, and the current contour (the contour after the last update) is used as the regularized roof contour to ensure that the contour shape is stable and the error meets the requirements.

[0070] Understandably, by determining whether the total error meets the termination condition, the waste of computational resources caused by excessive iteration can be avoided.

[0071] In this embodiment, by gradually reducing the total error through iteration, the degree of fit between the regularized roof outline and the original roof outline is ensured, effectively solving the deviation problem of the initial outline and improving the regularization accuracy of the roof outline. At the same time, the iteration termination condition is clearly defined to avoid over-iteration or under-iteration, taking into account both computational efficiency and regularization effect, making the entire outline regularization process more efficient and reliable.

[0072] The aforementioned constraints include vertex distance error, shape similarity error, spatial elevation error, and adjacent side orthogonality error; the errors between the initial profile and the original roof profile include: vertex distance error, shape similarity error, spatial elevation error, and adjacent side orthogonality error.

[0073] Vertex distance error term: This refers to the constraint term in the target loss function used to quantify the distance deviation between the vertices of the initial contour and the original roof contour. Its function is to ensure that the vertices of the initial contour can fit the corresponding positions of the original roof contour to the greatest extent possible, reducing vertex position deviation. Vertex distance error: This refers to the distance deviation between the initial contour and the original roof contour calculated through the vertex distance error term. It reflects the degree of positional fit between the vertices of the initial contour and the original roof contour. The smaller the error, the more accurate the vertex position.

[0074] Shape similarity error term: This refers to the constraint term in the objective loss function used to quantify the shape similarity deviation between the initial contour and the original roof contour. Its function is to ensure that the regularized roof contour maintains the same shape as the original roof contour. Shape similarity error: This refers to the shape deviation between the initial contour and the original roof contour calculated through the shape similarity error term. It reflects the degree of shape fit between the two; the smaller the error, the higher the shape similarity.

[0075] Spatial elevation error term: This refers to the constraint term in the target loss function used to quantify the elevation deviation between the vertices of the initial contour and the corresponding contour points of the original roof contour. Its function is to ensure that the regularized roof contour not only conforms to the original contour in the plane but also maintains consistency in spatial elevation. It is suitable for roof contour regularization with elevation information. Spatial elevation error: This refers to the elevation deviation between the initial contour and the original roof contour calculated through the spatial elevation error term. It reflects the degree of conformity between the two in the vertical direction in space. The smaller the error, the better the elevation consistency.

[0076] Adjacent edge orthogonality error: This refers to the constraint term in the target loss function used to quantify the deviation in orthogonality between adjacent edges of the initial contour. Its function is to ensure that adjacent edges of the regularized roof contour remain as perpendicular as possible, such as the adjacent edges of a rectangular roof, thus improving the regularity of the contour. Adjacent edge orthogonality error: This refers to the orthogonal deviation between adjacent edges of the initial contour calculated using the adjacent edge orthogonality error term. It reflects the degree of perpendicularity between adjacent edges; the smaller the error, the closer the adjacent edges are to perpendicularity, and the more regular the contour.

[0077] Specifically, in step S41, the error between the initial profile and the original roof profile is calculated using each constraint term of the target loss function, including: Step S411: When the constraint term is the vertex distance error term, traverse each vertex of the initial contour and calculate the distance between each vertex and the original roof contour for each vertex; obtain the vertex distance error between the initial contour and the original roof contour based on the sum of the squares of the distances between each vertex and the original roof contour. In one optional approach: when the constraint term is the vertex distance error term, each vertex of the initial contour is selected sequentially, and the planar coordinates of each vertex are obtained; for each vertex, the Euclidean distance between it and all contour points on the original roof contour is calculated, and the shortest distance among them is selected as the distance between the vertex and the original roof contour; the shortest distances corresponding to all vertices are squared, and then all the squared values ​​are added together, and the sum is the vertex distance error.

[0078] Understandably, calculating the vertex distance error through the vertex distance error term can accurately quantify the positional deviation between the initial contour vertices and the original roof contour, ensuring that the vertices of the initial contour can fit the corresponding positions of the original roof contour. This provides deviation data of the vertex position dimension for the calculation of the total error, while also guiding the adjustment direction of the contour point coordinates and improving the positional accuracy of the contour.

[0079] In step S412, when the constraint term is a shape similarity error term, for each vertex of the initial contour, calculate the distance to all contour points of the original roof contour to obtain the first shortest distance; for each contour point of the original roof contour, calculate the distance to all vertices of the initial contour to obtain the second shortest distance; select the maximum value between the first shortest distance and the second shortest distance as the shape similarity error. First shortest distance: refers to the shortest distance between each vertex of the initial profile and all profile points of the original roof profile. It is used to quantify the nearest position deviation between a single vertex and the original roof profile and is the basic data for calculating shape similarity error.

[0080] The second shortest distance refers to the shortest distance between each contour point of the original roof profile and all vertices of the initial profile. It is used to quantify the closest position deviation between a single contour point of the original roof profile and the initial profile, and together with the first shortest distance, it constitutes the basis for calculating the shape similarity error.

[0081] In one optional approach: when the constraint term is a shape similarity error term, traverse each vertex of the initial contour, calculate the Euclidean distance between each vertex and all contour points of the original roof contour, filter out the shortest distance corresponding to each vertex, which is the first shortest distance, and organize it to obtain a list of first shortest distances; then traverse each contour point of the original roof contour, calculate the Euclidean distance between each contour point and all vertices of the initial contour, filter out the shortest distance corresponding to each contour point, which is the second shortest distance, and organize it to obtain a list of second shortest distances; compare all distance values ​​in the two lists, and select the largest distance value as the shape similarity error.

[0082] Understandably, calculating the shape similarity error through the shape similarity error term can comprehensively assess the degree of shape fit between the initial outline and the original roof outline, avoiding the problem of accurate vertex positions but distorted overall shape. It provides deviation data of shape dimension for the calculation of total error, ensuring that the regularized roof outline not only has accurate vertex positions but also that the overall shape is consistent with the original roof outline.

[0083] Step S413: When the constraint term is the spatial elevation error term, for each vertex of the initial contour, calculate the distance to all contour points of the original roof contour to obtain the nearest contour point of each vertex; obtain the elevation information of each vertex and the elevation information of each nearest contour point; calculate the square of the elevation difference between the elevation information of each vertex and the elevation information of the corresponding nearest contour point to obtain the spatial elevation error. The nearest contour point refers to the contour point on the original roof contour that is closest to a certain vertex of the initial contour. This point has the smallest positional deviation from the corresponding vertex and is the core object for calculating spatial elevation error.

[0084] Elevation information: refers to the vertical height coordinates of the contour points in space, reflecting the spatial position of the contour points.

[0085] Squared elevation difference: refers to the square of the difference between the elevation information of a vertex of the initial contour and the elevation information of the corresponding nearest contour point. It is used to quantify the elevation deviation of a single vertex and is the basis for calculating spatial elevation error.

[0086] In one optional approach: when the constraint term is a spatial elevation error term, traverse each vertex of the initial contour, calculate the Euclidean distance between each vertex and all contour points of the original roof contour, and select the contour point with the shortest distance as the nearest contour point of that vertex; obtain the elevation information of each initial contour vertex and the elevation information of the corresponding nearest contour point through image analysis or laser scanning data; calculate the elevation difference of each vertex, perform a square operation on the elevation difference, and add the squares of the elevation differences of all vertices together to obtain the sum, which is the spatial elevation error.

[0087] Understandably, calculating the spatial elevation error through the spatial elevation error term can quantify the deviation between the initial outline and the original roof outline in the vertical direction in space. This is suitable for the regularization of three-dimensional roof outlines, ensuring that the regularized roof outline not only fits the original outline on the plane but also maintains consistency in elevation, thus improving the comprehensiveness and accuracy of outline regularization and providing deviation data in the elevation dimension for the calculation of total error.

[0088] Step S414: When the constraint term is the orthogonality error of adjacent sides, traverse the adjacent sides of the initial contour and obtain the direction vector of each side in the adjacent sides; calculate the cosine value between two sides in the adjacent sides based on the direction vector; determine the orthogonality error of adjacent sides based on the cosine value. Direction vector: refers to the vector used to represent the direction of adjacent edges. It can be calculated from the starting and ending coordinates of the edge and can accurately reflect the extension direction of the edge. It is the core basis for calculating the degree of orthogonality of adjacent edges.

[0089] Cosine value: refers to the cosine value of the angle between adjacent sides calculated by the direction vectors of adjacent sides. It is used to quantify the size of the angle between adjacent sides. When the cosine value is 0, the adjacent sides are completely orthogonal. The closer the cosine value is to 0, the higher the degree of orthogonality.

[0090] In one optional approach: when the constraint term is the orthogonality error of adjacent edges, all adjacent edges of the initial contour are traversed. For each pair of adjacent edges, the starting coordinates (Xa, Ya) and ending coordinates (Xb, Yb) of the first edge are obtained, and its direction vector is calculated as (Xb-Xa, Yb-Ya). The starting coordinates (Xb, Yb) and ending coordinates (Xc, Yc) of the second edge are obtained, and its direction vector is calculated as (Xc-Xb, Yc-Yb). The cosine value of the two direction vectors is calculated using the vector dot product formula, i.e., cosine value = (vector1·vector2) / (|vector1|*|vector2|). The absolute value of the cosine value is subtracted from 1 to obtain the orthogonality error of the pair of adjacent edges. All adjacent edges are traversed, and all orthogonality errors are added together to obtain the total orthogonality error of adjacent edges.

[0091] It is understandable that by calculating the orthogonality error of adjacent sides through the adjacent side orthogonality error term, the perpendicularity of the adjacent sides of the initial profile can be quantified, ensuring that the adjacent sides of the regularized roof profile remain as perpendicular as possible, thus improving the regularity of the profile. This is especially suitable for regular roof profiles such as rectangles and squares, and provides deviation data of the directional dimension of adjacent sides for the calculation of total error, further optimizing the profile shape.

[0092] After calculating the error using the above constraints, the errors calculated using these constraints are weighted and summed or directly summed to obtain the total error.

[0093] It should be noted that the original method, when dealing with irregular roof shapes, especially those with sloping edges, tends to force orthogonalization in local areas, causing the regularized result to deviate significantly from the actual contour. This solution introduces vertex distance error and shape similarity terms to dynamically balance the fit between orthogonal constraints and the original shape during optimization. This effectively prevents overcorrection while maintaining necessary regularity, making the regularized contour more closely resemble the actual roof shape. Furthermore, considering that the original method only focuses on planar geometric regularity, this solution adds a spatial elevation error term to ensure that the regularized vertex coordinates closely match the 3D model roof, avoiding elevation deviations caused by 2D projection and meeting the 3D spatial accuracy requirements of subsequent intelligent design software.

[0094] In this embodiment, the constraint terms quantify the contour deviation from four dimensions: vertex position, shape, elevation, and orthogonality of adjacent edges, to ensure the comprehensiveness of error assessment and avoid the problem of incomplete contour regularity caused by single-dimensional error calculation.

[0095] The above step S42 determines the total error between the initial profile and the original roof profile based on the errors calculated by each constraint term, including: weighted summation based on the errors calculated by each constraint term and the weight of each constraint term to obtain the total error between the initial profile and the original roof profile.

[0096] Weight: This refers to a pre-defined coefficient used to measure the importance of each constraint. The magnitude of the weight is determined based on the influence of the constraint on the contour regularization accuracy; the higher the importance, the greater the weight. It is used to reflect the priority of each constraint in the total error calculation. Each constraint can be assigned a corresponding weight according to the actual situation.

[0097] In one optional approach: Weights are pre-set according to the importance of each constraint, for example, the weight of the vertex distance error is set to 0.4, the weight of the shape similarity error is set to 0.3, the weight of the spatial elevation error is set to 0.2, and the weight of the adjacent edge orthogonality error is set to 0.1; the error values ​​calculated for each constraint are obtained, and each error value is multiplied by its corresponding weight to obtain the weighted error value for each constraint; the four weighted error values ​​are summed, and the total sum is the total error between the initial profile and the original roof profile. For example, if the vertex distance error is 0.5, the shape similarity error is 0.3, the spatial elevation error is 0.2, and the adjacent edge orthogonality error is 0.1, the total error = 0.5 × 0.4 + 0.3 × 0.3 + 0.2 × 0.2 + 0.1 × 0.1 = 0.2 + 0.09 + 0.04 + 0.01 = 0.34.

[0098] Another optional approach involves dynamically adjusting the weights of each constraint term based on the actual requirements for a regular roof outline. For example, for a planar roof outline, the weight of the spatial elevation error term is set to 0, the weight of the vertex distance error term is set to 0.5, the weight of the shape similarity error term is set to 0.3, and the weight of the adjacent edge orthogonality error term is set to 0.2. The error values ​​of each constraint term are obtained, and each error value is normalized. Then, the normalized error value is multiplied by its corresponding weight to obtain the weighted error value. All weighted error values ​​are summed to obtain the total error, ensuring that the total error is within a reasonable range, which facilitates the termination judgment of the iteration.

[0099] In this embodiment, the total error is calculated by weighted summation, which can comprehensively consider the importance of each constraint and avoid the problem that the total error cannot accurately reflect the core deviation of the contour due to equal weight of each constraint. Furthermore, by setting weights, the influence of different constraints on the contour regularization accuracy can be highlighted, ensuring that the total error can accurately reflect the overall deviation of the contour, and further optimizing the accuracy and effect of contour regularization.

[0100] In other embodiments, the constraints also include a perimeter error term and an area error term.

[0101] When the constraint term is the perimeter error term, calculate the perimeter of the initial profile and the perimeter of the original roof profile. The perimeter error is equal to the sum of the squares of the differences between the perimeter of the initial profile and the perimeter of the original roof profile. The goal is to make the perimeters of the initial profile and the original roof profile similar.

[0102] When the constraint term is the area error term, calculate the area of ​​the initial profile and the area of ​​the original roof profile. The area error is equal to the sum of the squares of the differences between the areas of the initial profile and the original roof profile. The goal is to make the areas of the initial profile and the original roof profile similar.

[0103] After obtaining the vertex distance error, shape similarity error, spatial elevation error, adjacent side orthogonality error, perimeter error, and area error through the above method, the vertex distance error, shape similarity error, spatial elevation error, adjacent side orthogonality error, perimeter error, and area error are weighted and summed to obtain the total error between the initial profile and the original roof profile.

[0104] It should be noted that this scheme unifies geometric similarity (perimeter, area, Hausdorff distance), local fit (vertex distance), structural regularity (orthogonality of adjacent sides), and three-dimensional spatial elevation error into a single weighted error function, thereby achieving refined and multi-dimensional constraints on the contour.

[0105] In step S43 above, the coordinates of the contour points of the initial contour are updated to obtain the updated contour, which includes: Step S431: Using numerical differentiation, calculate the total error between the initial profile and the original roof profile, and the gradient of the coordinates of each profile point of the initial profile. Numerical differentiation: This refers to a method of calculating the derivative of the total error with respect to the coordinates of each contour point in the initial contour using discretized numerical calculations. It eliminates the need for complex analytical derivations, providing a quick and efficient way to obtain the rate of change of the total error with respect to the contour point coordinates. This provides crucial data support for determining the direction of error descent. For example, when the derivative of the total error with respect to the contour point coordinates cannot be directly calculated using analytical formulas, numerical differentiation allows for the approximate derivative value to be obtained by making small changes to the contour point coordinates and calculating the corresponding change in the total error, thus meeting the needs of iterative adjustments.

[0106] Gradient: This refers to the vector formed by the derivative of the total error with respect to the coordinates of each contour point in the initial contour. Each contour point corresponds to a gradient vector. The direction of the vector reflects the direction of the fastest increase in the total error as the coordinates of that contour point change, while the magnitude of the vector reflects the rate of change of the total error. Its function is to accurately indicate the trend of change in the total error, providing a direct basis for determining the direction of error descent and ensuring that the adjustment of the contour point coordinates is in the direction of reducing the total error. For example, if the gradient vector of a contour point is positive, it means that the total error will increase when the coordinates of that point increase and decrease when the coordinates decrease. The magnitude of the gradient vector reflects the drasticness of this change.

[0107] In one optional approach: First, obtain the coordinates of all contour points of the initial contour and the corresponding total error value. For each contour point, make small perturbations to its X-axis and Y-axis coordinates, perturbing only one coordinate dimension at a time while keeping the other coordinate dimension unchanged. For example, increase the X-axis coordinate of a contour point by a small value while keeping the Y-axis coordinate unchanged, and recalculate the total error between the initial contour and the original roof contour. Obtain the partial derivative of the total error with respect to the X-axis coordinate of the contour point by the ratio of the difference between the two total errors to the coordinate perturbation value. Using the same method, perturb the Y-axis coordinate of the contour point and calculate the partial derivative of the total error with respect to the Y-axis coordinate of the contour point. The gradient vector of the contour point is constructed from the X-axis and Y-axis partial derivatives. Repeat this process to calculate the gradient of all contour points.

[0108] In another optional approach: For each contour point of the initial contour, apply a small bidirectional perturbation to its X-axis and Y-axis coordinates, i.e., simultaneously increase and decrease a small perturbation value. For example, increase and decrease the small perturbation value of the X-axis coordinate of a contour point, while keeping the Y-axis coordinate unchanged. Calculate the total error under both perturbation conditions. Obtain the partial derivative of the total error with respect to the X-axis coordinate of the contour point by the ratio of the difference between the two total errors to twice the perturbation value. Similarly, apply a bidirectional perturbation to the Y-axis coordinate of the contour point and calculate the partial derivative of the total error with respect to the Y-axis coordinate. Combine the two to form the gradient vector of the contour point. Iterate through all contour points to complete the calculation of all gradients.

[0109] Understandably, calculating the gradient using numerical differentiation can accurately capture the trend of the total error as the coordinates of each contour point change, providing direct numerical basis for determining the direction of error descent. This solves the problem of not being able to solve the gradient analytically, ensuring the accuracy of the direction of error descent, laying the foundation for reasonable updates of contour point coordinates, and avoiding deviations in the subsequent adjustment direction due to gradient calculation errors.

[0110] Step S432: Determine the error descent direction based on the gradient, and perform a line search along the error descent direction to obtain the iteration step size; Error descent direction: This refers to the direction opposite to the gradient direction. It is the direction in which the total error decreases fastest as the coordinates of the contour points change. Its function is to clarify the adjustment direction of the contour point coordinates, ensuring that each coordinate update effectively reduces the total error between the initial contour and the original roof contour, and avoiding an increase in the total error due to incorrect adjustment direction. For example, if the gradient direction of a contour point is the positive X-axis and positive Y-axis direction, then the error descent direction of that point is the negative X-axis and negative Y-axis direction. Adjusting the coordinates along this direction can quickly reduce the total error.

[0111] Line search: This refers to the process of gradually exploring different step sizes along a defined error descent direction, calculating the corresponding total error, and selecting the step size that minimizes the total error. Its purpose is to determine an appropriate iteration step size, avoiding situations where an excessively large step size leads to fluctuations in the total error or failure to converge, or an excessively small step size results in low iteration efficiency or excessive time consumption. For example, along the error descent direction, different step sizes are selected sequentially, the total error corresponding to each step size is calculated, and the step size with the smallest total error is selected as the final iteration step size.

[0112] Iteration step size: This refers to the magnitude by which the contour point coordinates are adjusted along the error-decreasing direction during each iteration. It is a parameter that controls the update magnitude of the contour point coordinates, and its size directly affects the efficiency of the iteration adjustment and the convergence effect. Its function is to standardize the update magnitude of the contour point coordinates, ensuring that the iteration process can converge stably. This ensures that the total error gradually decreases while avoiding iteration oscillations or slow convergence caused by an inappropriate step size. For example, setting the iteration step size to 0.05 means that in each iteration, the coordinates of each contour point are moved by 0.05 units along the error-decreasing direction.

[0113] In one optional approach: the gradient vector of each contour point is inverted to obtain the error descent direction corresponding to that contour point. The error descent directions of all contour points together constitute the error descent direction of the entire initial contour. Then, a fixed-step trial-and-error line search is performed along this error descent direction. A set of different candidate step sizes is pre-defined, such as 0.001, 0.005, 0.01, 0.05, and 0.1. Each candidate step size is substituted sequentially to calculate the total error after updating the coordinates of each contour point of the initial contour for each step size. The total errors corresponding to all candidate step sizes are compared, and the candidate step size with the smallest total error is selected as the final iteration step size. If multiple step sizes have the same total error, the smallest step size is selected to ensure iteration stability.

[0114] Another optional approach involves first normalizing the gradient vectors of all contour points to eliminate the influence of differences in the magnitude of gradient vectors between different contour points. Then, the normalized gradient vectors are inverted to obtain a uniform error descent direction. An adaptive line search is then performed along this error descent direction, starting from an initial step size and gradually increasing the step size. After each increase, the corresponding total error is calculated. If the total error continues to decrease, the step size is increased further. When the total error begins to increase, the step size is stopped, and the step size corresponding to the minimum total error is selected as the iteration step size. If the total error corresponding to the initial step size begins to increase, the step size is gradually decreased until the step size that minimizes the total error is found.

[0115] Understandably, determining the direction of error descent clarifies the adjustment direction of the contour point coordinates, ensuring that each update effectively reduces the total error. Executing a line search along the error descent direction yields a suitable iteration step size, avoiding the problems of excessively large step sizes leading to iteration oscillations and failure to converge, or excessively small step sizes leading to low iteration efficiency. This balances the efficiency and stability of the iteration adjustment, providing a guarantee for the accurate updating of the contour point coordinates in the future.

[0116] Step S433: Based on the error descent direction and iteration step size, update the coordinates of each contour point of the initial contour to obtain the updated contour.

[0117] In one optional approach: Obtain the current coordinates, corresponding error descent direction, and determined iteration step size for each contour point. Multiply the coordinates of each contour point by the error descent direction vector multiplied by the iteration step size, and then sum the results to obtain the updated coordinates of that contour point. For example, if the current coordinates of a contour point are (X0, Y0), the error descent direction vector is (Dx, Dy), and the iteration step size is α, then the updated coordinates are (X0 + α * Dx, Y0 + α * Dy). Update the coordinates of all contour points sequentially, and then connect all the updated contour points in order to form a closed contour line, which is the updated contour.

[0118] It is understandable that updating the contour point coordinates based on the error descent direction and iteration step size can effectively reduce the total error between the initial contour and the original roof contour, allowing the contour to gradually conform to the original roof contour, thus advancing the iteration process and providing a new contour basis for subsequent recalculation of the total error and determination of the iteration termination condition.

[0119] It should be noted that when faced with the problem of complex weighted error functions that are difficult to analyze for differentiation, this scheme adopts numerical differentiation to approximate the gradient, so that the method does not depend on the specific function form, can be flexibly extended to more constraint terms, and is applicable to various regularization scenarios of irregular contours, thereby improving the versatility and engineering practicality of the algorithm.

[0120] It should be noted that related technologies typically only perform simple contour simplification or single-criterion fitting, such as minimizing distance error. In contrast, this scheme considers multiple mutually constraining factors such as geometric similarity, orthogonality, and elevation error through multi-objective optimization, and uses numerical differential iteration to solve the problem. This ensures that the regularized contour retains the original shape characteristics, meets specific regularization requirements (such as edge orthogonality), and takes into account the elevation accuracy in three-dimensional space, significantly improving the quality and practicality of the contour regularization results.

[0121] In this embodiment, the gradient is calculated using numerical differentiation, which solves the problems of complexity and limited applicability of analytical gradient calculation. This method can quickly and accurately obtain the trend of total error change with the coordinates of contour points, ensuring the accuracy of the error descent direction. The iteration step size is determined by line search, balancing the efficiency and stability of iterative adjustment. This avoids iterative oscillations or slow convergence caused by inappropriate step sizes, ensuring stable and efficient convergence of the iteration process. Through precise gradient calculation, reasonable direction determination, and step size selection, the coordinates of contour points are updated, improving the accuracy and reliability of iterative adjustment and ensuring that the regularized roof contour better fits the original roof contour.

[0122] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in Embodiment 1 above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2Before step S10, the roof outline straightening method of this application further includes: Step S10: Obtain the roof area to be identified and extract the outline of the roof area to be identified to obtain the roof outline to be identified, wherein the roof area to be identified is the area selected by the user. Step S20: Determine the original roof outline corresponding to the roof area to be identified; Step S110: Perform normalization operations on the roof outline to be identified and the original roof outline respectively. The normalization operations include: detecting whether the outline is closed and detecting whether the outline direction is uniform. Standardized operation: This refers to the preprocessing operation of the roof outline to a uniform standard. The purpose is to ensure the consistency and standardization of the outline, providing a reliable foundation for subsequent operations such as outline simplification and vertex alignment. Its function is to avoid deviations or failures in subsequent operations due to outline defects, such as incomplete closure or directional confusion, and to ensure the accuracy of subsequent vertex alignment.

[0123] Contour closure detection: This refers to the operation of checking whether the roof contour is a complete closed line, that is, whether the start and end points of the contour coincide. It is one of the core aspects of standardized operation. Its function is to identify contour closure defects, ensure that the contour can completely present the boundary shape of the roof, and avoid errors in subsequent vertex traversal and alignment due to contour closure. For example, by checking whether the coordinates of the beginning and end of the contour line are consistent, the closure of the contour can be identified.

[0124] Unifying the outline direction: This refers to adjusting the traversal direction of the roof outline so that the outline to be identified and the original roof outline use the same traversal direction, such as both clockwise or both counterclockwise. Its purpose is to ensure that the subsequent vertex traversal and alignment order is consistent, avoiding vertex correspondence errors due to opposite directions, which would affect the construction accuracy of the initial outline. For example, if the roof outline to be identified uses a clockwise traversal direction while the original roof outline uses a counterclockwise traversal direction, the outline direction unification operation adjusts the original roof outline to a clockwise direction, ensuring that the traversal order of the two is consistent.

[0125] Contour point simplification: This refers to reducing the number of contour points on the roof contour to be identified without changing its overall shape. It removes redundant intermediate points that have little impact on the contour's shape, retaining only the vertices and a few key intermediate points that reflect the contour's crucial form. Its purpose is to simplify subsequent vertex traversal and alignment, improving operational efficiency while avoiding alignment deviations caused by redundant contour points, ensuring accurate vertex alignment. For example, for a smooth contour edge with numerous consecutive intermediate points, simplification can remove most of these intermediate points, retaining only the vertices at both ends and a few key intermediate points, thus reducing the data volume without altering the overall shape of the edge.

[0126] In one optional approach: contour closure detection and contour direction unification are performed on the two contours separately. During contour closure detection, the coordinates of all contour points are acquired, and the start and end coordinates of the contour are checked for complete consistency. If they are inconsistent, the distance between the start and end points is calculated. If the distance is less than a preset threshold, the start and end points are automatically connected to form a closed contour. If the distance is greater than the preset threshold, a gap is identified in the contour, the gap location is automatically identified, and the contour points at the gap are filled to form a closed contour. During contour direction unification, the direction vectors of the two contours are calculated, and it is determined whether the traversal direction of the roof contour to be identified and the original roof contour are consistent. If the roof contour to be identified is clockwise and the original roof contour is counterclockwise, the contour point order of the original roof contour is reversed to make it clockwise, ensuring that the directions of the two contours are unified.

[0127] Understandably, standardizing the two contours can prevent errors in subsequent vertex traversal and alignment caused by incomplete contour closures and chaotic orientations, ensuring smooth operation of subsequent steps. It also provides a standardized and reliable contour foundation for subsequent contour simplification and vertex alignment, improving the accuracy of the entire contour standardization process.

[0128] Step S120: Simplify the outline points of the roof outline to be identified after the normalization operation. In one optional approach: the first and last vertices of the normalized roof outline to be identified are used as initial retention points. A straight line is formed by connecting these two points. The distance from each of the remaining intermediate points on the outline to this straight line is calculated. Intermediate points whose distance is less than a preset simplification threshold are identified as redundant points and deleted. Intermediate points whose distance is greater than or equal to the preset simplification threshold are retained. Then, the above process is repeated with the retained intermediate points as new endpoints until all intermediate points are identified as redundant points or retained points. Finally, a simplified outline with a reduced number of outline points and a shape consistent with the original outline is obtained.

[0129] Another optional approach involves calculating the curvature of each contour point on the normalized roof profile to be identified. Curvature reflects the degree of bending at the location of the contour point; a larger curvature indicates a greater influence of the point on the profile shape, while a smaller curvature indicates greater redundancy. A curvature threshold is set, retaining contour points with curvature greater than or equal to the threshold and deleting intermediate points with curvature less than the threshold. Simultaneously, all vertices of the contour are retained to ensure that the simplified contour fully preserves the key bending features and overall shape of the original contour, avoiding over-simplification that could lead to contour distortion.

[0130] Understandably, simplifying the contour points of the roof outline to be identified can remove redundant intermediate points, reduce the workload of subsequent vertex traversal and alignment, and improve operational efficiency; at the same time, it can retain the key shape and vertex information of the outline, avoid vertex alignment deviations caused by redundant points, ensure the accuracy of subsequent vertex alignment, and improve the efficiency and accuracy of the construction of the initial outline.

[0131] Step S33: Traverse each vertex of the roof outline to be identified after the simplification operation, determine the outline points on the original roof outline after the normalization operation that are aligned with each vertex, and construct the initial outline based on the outline points aligned with each vertex. In one optional approach: traverse each vertex of the simplified roof outline to be identified in sequence, obtain the coordinates of each vertex, and simultaneously obtain the coordinates of all outline points of the normalized original roof outline. For each vertex, calculate the distance between the vertex and all outline points on the original roof outline, select the outline point with the shortest distance as the outline point aligned with the vertex, and record the correspondence between each vertex and the corresponding aligned outline point. Then, according to the traversal order of each vertex of the simplified roof outline to be identified, connect the corresponding aligned outline points in sequence to supplement the outline lines and form a closed outline line, which is the initial outline.

[0132] Understandably, traversing the simplified vertices and determining the alignment points with the normalized original roof outline can reduce the workload of vertex traversal, improve alignment efficiency, and avoid alignment deviations caused by redundant vertices. Constructing an initial outline based on the alignment points ensures that the initial outline retains the key shape of the roof outline to be identified and also fits the actual shape of the original roof outline, providing a precise and reliable initial foundation for subsequent iterative adjustments, and further improving the accuracy and efficiency of outline normalization.

[0133] Step S40: Based on the target loss function and the initial contour, the contour points of the initial contour are iteratively adjusted to obtain the regularized roof contour.

[0134] In this embodiment, normalization and contour point simplification operations are added before vertex traversal and initial contour construction to compensate for the inaccuracy and inefficiency caused by contour defects and redundant points in the original process. Normalization corrects the non-closure defect of the contour, unifies the orientation of the two contours, ensures the accuracy of subsequent vertex traversal and alignment, and avoids operation failures or deviations caused by contour defects. Contour point simplification removes redundant intermediate points, reduces the workload of subsequent operations, improves the efficiency of the overall process, and preserves the key shape of the contour to ensure the accuracy of vertex alignment.

[0135] Based on the above embodiments of this application, in the third embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 3 Before step S10, the roof outline straightening method also includes: Step S10: Obtain the roof area to be identified and extract the outline of the roof area to be identified to obtain the roof outline to be identified, wherein the roof area to be identified is the area selected by the user. Step S20: Determine the original roof outline corresponding to the roof area to be identified; Step S210: Traverse each edge of the original roof outline in sequence and identify the start and end points of each edge. In one optional approach: Following the traversal direction of the original roof outline (e.g., clockwise or counterclockwise), all edges of the original roof outline are traversed sequentially. For each edge, the first outline point of that edge is taken as the starting point, and the last outline point of that edge is taken as the ending point. The starting and ending coordinates of each edge are recorded, and each edge is numbered to ensure that the starting and ending points of each edge correspond accurately and to avoid confusion. For example, when traversing the original roof outline in a clockwise direction, the starting point of the first edge is the starting vertex of the outline, and the ending point is the next adjacent vertex. The starting point of the second edge is the ending point of the first edge, and the ending point is the next vertex, and so on, until all edges have been traversed.

[0136] Step S220: Interpolate between the start and end points of each edge according to a preset interpolation interval to obtain each edge after interpolation; Preset interpolation interval: This refers to the pre-defined distance between the start and end points of each edge of the original roof outline when inserting new outline points. A smaller preset interpolation interval results in more interpolated outline points and a smoother outline; a larger preset interpolation interval results in fewer interpolated outline points and a simpler outline. For example, a preset interpolation interval of 0.01 means that a new outline point is inserted every 0.01 units along each edge from start to end.

[0137] In one optional approach: For each edge, first calculate the straight-line distance between the start and end points. Based on the preset interpolation interval, calculate the number of contour points that need to be inserted for that edge. The number of insertion points is equal to the distance between the start and end points divided by the interpolation interval, taking the integer part and adding one. Then, using uniform interpolation, starting from the start point, calculate a new interpolation point coordinate at preset interpolation intervals. The interpolation point coordinates are calculated based on the start point coordinates, end point coordinates, and interpolation ratio. For example, if the start point coordinates of an edge are (X1, Y1), the end point coordinates are (X2, Y2), and the interpolation ratio is k, then the interpolation point coordinates are (X1 + k * (X2 - X1), Y1 + k * (Y2 - Y1)). Calculate all interpolation point coordinates sequentially, and connect the start point, all interpolation points, and the end point in order to obtain the interpolated edge.

[0138] In another optional approach: First, obtain the start and end coordinates of each edge to determine its extension direction. Based on a preset interpolation interval, move the edge gradually from the start to the end along its extension direction, moving the preset interpolation interval each time. Calculate the coordinates of the interpolation point at the current position. If the preset interpolation interval is not reached by the time the edge reaches the end, adjust the position of the last interpolation point to ensure that the interpolation point covers the entire edge and that the distance between adjacent interpolation points does not exceed the preset interpolation interval. Arrange the start point, all interpolation points, and the end point in sequence to form the interpolated edge. Simultaneously, check the rationality of the interpolation points to avoid situations where the interpolation points deviate from the edge's direction.

[0139] Understandably, interpolating along each edge according to a preset interpolation interval increases the number of outline points in the original roof profile, making the lines of each edge smoother and more detailed, improving the accuracy of the original roof profile, providing more candidate outline points for subsequent vertex alignment, avoiding excessive alignment deviations due to insufficient original roof profile points, ensuring the accuracy of subsequent vertex alignment, and providing a more precise reference basis for the construction of the initial profile.

[0140] Step S230: Construct the original roof outline after interpolation based on each interpolated edge; In one optional approach: following the traversal order of the original roof profile, all interpolated edges are connected sequentially, ensuring that the endpoint of the previous edge completely coincides with the starting point of the next edge, avoiding gaps or overlaps. After connection, the closure of the entire profile is checked to ensure that the interpolated original roof profile is a complete closed profile. If gaps exist, the coordinates of the interpolation points on adjacent edges are automatically adjusted to fill the gaps; if overlaps exist, the overlapping interpolation points are deleted, ultimately forming a complete, closed, and smooth interpolated original roof profile, and the coordinates of all interpolation points of this profile are saved.

[0141] Step S34: Traverse each vertex of the roof outline to be identified and determine the outline points on the original roof outline after interpolation that are aligned with each vertex.

[0142] In one optional approach: traverse each vertex of the roof profile to be identified in sequence, obtain the coordinates of each vertex, and simultaneously obtain the coordinates of all interpolated points of the original roof profile after interpolation. For each vertex, calculate the distance between the vertex and all interpolated points on the original roof profile after interpolation, determine the interpolated point with the smallest distance as the profile point aligned with the vertex, and record the correspondence between each vertex and the corresponding aligned profile point to ensure that each vertex can find the best-fitting alignment point and avoid alignment deviation.

[0143] Understandably, by traversing the vertices of the roof contour to be identified and determining alignment points on the interpolated original roof contour, since the interpolated original roof contour has more contour points and higher precision, it can provide a more fitting alignment point selection for each vertex, avoiding alignment deviations caused by too few original roof contour points, ensuring the accuracy of vertex alignment, providing more reliable support for the subsequent construction of the initial contour, and further improving the regularity of the roof contour.

[0144] Step S40: Based on the target loss function and the initial contour, the contour points of the initial contour are iteratively adjusted to obtain the regularized roof contour.

[0145] In this embodiment, an interpolation operation is added after the original roof outline is determined. By interpolating each edge of the original roof outline, the number of outline points is increased, improving the accuracy and detail of the original roof outline and solving the problem of excessive vertex alignment deviation caused by too few points or rough lines in the original roof outline. Finally, the alignment points are determined based on the interpolated outline, improving the accuracy of vertex alignment.

[0146] For example, in order to help understand the implementation process of the roof contour straightening method obtained by combining the above embodiments, the specific technical solution of this application will be described in detail below: Step 1: Input data and standardize the input data.

[0147] Input the 3D model data of the factory area, the original roof outline (precise_contour). Figure 4 The irregular inner contour and the user-selected region to be identified (user_contour) Figure 4 The relatively regular outer contour, i.e., the roof contour to be identified.

[0148] Check the start and end coordinates of the original roof contour `precise_contour` to ensure they are the same, forming a closed contour. Calculate the directed area using the formula for the directed area of ​​a closed contour. If the result is greater than zero, the vertices of the closed contour are in a counter-clockwise direction; if the result is less than zero, the vertices are in a clockwise direction; if the result is equal to zero, the closed contour degenerates into a straight line or a point. The original roof contour `precise_contour` remains counter-clockwise. Perform the same closed contour normalization operation on the user-selected region `user_contour`.

[0149] Simplify the user-selected region (user_contour) to reduce the number of boundary points generated by accidental clicks during user interaction. Since the initial value of the subsequent contour normalization method based on nonlinear optimization needs to use the user_contour, pre-simplification here can improve the simplicity of the closed contour normalization result.

[0150] Step 2: Boundary vertex alignment. Align the user-selected region to be identified (user_contour) to precise_contour to determine the initial solution of the nonlinear optimization problem.

[0151] 2.1 Traverse each edge in the original roof contour precise_contour in sequence, and interpolate between the start and end points of the edge. Alternatively, the interpolation interval can be fixed at 0.1 meters to encrypt the vertex coordinates in the original roof contour precise_contour. The encrypted contour is then denoted as precise_contour_dense.

[0152] 2.2 Traverse each vertex e in the user-selected region user_contour and find the closest point p on the precise_contour_dense contour to vertex e. Use point p as the alignment point of vertex e on the original roof contour precise_contour. After aligning each vertex in the user-selected region user_contour, the aligned point set P is obtained, which can be represented as [p1, p2, ..., pn]. This is also the initial solution initial_solution for the subsequent nonlinear optimization problem (initial_solution is actually P). Subsequently, the position of each vertex in initial_solution will be iteratively adjusted by minimizing the error function until the total error value is minimized.

[0153] Step 3: Define the error function, i.e. the target loss function, and construct a nonlinear optimization problem.

[0154] The points in the initial solution (initial_solution) can be sequentially arranged to construct a closed contour, denoted as contour_tp, i.e., the initial contour. To ensure that the initial contour (contour_tp) approximates the original roof contour (precise_contour) as closely as possible, and satisfies certain normalization objectives (orthogonality, small distance deviation, etc.), the error function mainly consists of the following: (1) Perimeter similarity (the error weight can be set smaller); (2) Area similarity; (3) The sum of the distances from the vertices of the initial contour contour_tp to the original roof contour precise_contour should be small enough; (4) Adjacent edges in the initial contour_tp should be as orthogonal as possible; (5) Shape similarity between the initial contour contour_tp and the original roof contour precise_contour; (6) The sum of the spatial elevation errors from the vertices of the initial contour contour_tp to the original roof contour precise_contour should be as small as possible.

[0155] 3.1 Calculate the perimeter error length_error. Calculate the perimeter of the initial contour contour_tp as L1 and the perimeter of the original roof contour precise_contour as L2. The perimeter error length_error is equal to the sum of the squares of the differences between L1 and L2. The goal is to make the perimeter of the initial contour contour_tp and the original roof contour precise_contour similar. 3.2 Calculate the area error area_error. Calculate the area of ​​the initial contour contour_tp as area1, and calculate the area of ​​the original roof contour precise_contour as area2. The area error area_error is equal to the sum of the squares of the differences between area1 and area2. The goal is to make the areas of the initial contour contour_tp and the original roof contour precise_contour similar. 3.3 Calculate the vertex distance error distance_error. Iterate through each vertex h in contour_tp, calculate the sum of squared distances d_squares from vertex h to the encrypted contour precise_contour_dense, and add the sum of squared distances d_squares to distance_error.

[0156] 3.4 Calculate the orthogonality error (regularity_error) of adjacent edges in contour_tp. Traverse the adjacent edges in the initial contour_tp. Obviously, every two adjacent edges are composed of three vertices p1, p2, and p3. p1-p2 form the direction vector v1 of one edge. After normalizing vector v1, we get v1_norm. p3-p2 form the direction vector v2 of another edge. After normalizing vector v2, we get v2_norm. Calculate the cosine value (cos_angle) between vectors v1 and v2. When cos_angle is close to 0, it obviously means that vectors v1 and v2 are close to 90 degrees and are approximately orthogonal. Add cos_angle to regularity_error.

[0157] 3.5 Calculate the shape similarity error `shape_error`. This involves calculating the Hausdorff distance `d_hausdorff` between the initial contour `contour_tp` and the roof contour `precise_contour_dense`. The Hausdorff distance is a measure of the similarity between two sets of points (here, all points on two closed contours). It is defined as the maximum of the minimum distances from any point in one set to the other. Simply put, it measures the degree of mismatch between two shapes. Let `shape_error` equal to `d_hausdorff`.

[0158] 3.6 Calculate the spatial elevation error h_error. Traverse each vertex f in the initial contour contour_tp, and calculate the nearest point k of f on the refined contour precise_contour_dense. The spatial elevation of each vertex in the 3D model can be located using its 2D coordinates. Let's denote the spatial elevation of vertex f as f_h and the spatial elevation of vertex k as k_h. Add (f_h - k_h)*(f_h - k_h) to h_error. The reason for adding the vertex elevation error term is that if the vertex coordinates in the initial contour contour_tp deviate too far from the actual roof during iteration, the spatial elevation error at that point will increase significantly.

[0159] 3.7 Total error: total_error = w1*length_error + w2*area_error + w3*distance_error + w4*regularity_error + w5*shape_error + w6*h_error; where w1, w2, w3, w4, w5, and w6 are the weighting coefficients of each error term.

[0160] Step 4: Optimize the problem solution.

[0161] When solving nonlinear optimization problems, the gradient information of the objective loss function is usually needed to guide the search direction. If the objective loss function is complex and lacks an analytical derivative, or if automatic differentiation is inconvenient to implement, numerical differentiation can be used to approximate the gradient, combined with iterative algorithms to find the optimal solution. The following are the basic methods and steps.

[0162] 4.1 Initialization: Selecting an initial point Set the step size h (for numerical differentiation) and the convergence tolerance ε.

[0163] 4.2 Calculate the gradient: at the current point Calculate the gradient using numerical differentiation (using forward difference or central difference formulas). .

[0164] 4.3 Determine the search direction: Obtain the descent direction based on the selected algorithm. (in gradient descent) ).

[0165] 4.4 Line Search: Along the direction Finding the right step size ,make A significant decrease.

[0166] 4.5 Update variables: Let .

[0167] 4.6 Check convergence: If If the variable changes very little, stop the iteration; otherwise, return to step two.

[0168] Step 5: Obtain the contour normalization result.

[0169] 5.1 The iterative solution result in step 4 is the vertex coordinates after the original roof contour has been normalized by precision_contour, which is the normalized roof contour.

[0170] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the roof outline regularization method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.

[0171] Based on the same inventive concept, this application provides a roof contour straightening device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the roof contour straightening method in the above embodiments.

[0172] like Figure 5As shown, the roof contour straightening device may include a processing unit 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 1002 or a program loaded from storage device 1003 into random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the roof contour straightening device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the roof contouring device to communicate wirelessly or wiredly with other devices to exchange data. Although roof contouring devices with various systems are shown in the figures, it should be understood that it is not required to implement or possess all the systems shown. More or fewer systems can be implemented alternatively.

[0173] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0174] The roof contour straightening device provided in this application, employing the roof contour straightening method in the above embodiments, can reduce the deviation between the straightened roof contour and the original roof contour, thereby improving the straightening accuracy of the roof contour. Compared with the prior art, the beneficial effects of the roof contour straightening device provided in this application are the same as those of the roof contour straightening method provided in the above embodiments, and other technical features in this roof contour straightening device are the same as those disclosed in the previous embodiment method, and will not be repeated here.

[0175] Based on the same inventive concept, this application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the roof contour straightening method in the above embodiments.

[0176] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory (EPROM), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.

[0177] The aforementioned computer-readable storage medium may be included in the roof profile straightening device; or it may exist independently and not assembled into the roof profile straightening device.

[0178] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the roof contour straightening device, cause the roof contour straightening device to perform the steps of the aforementioned roof contour straightening method.

[0179] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0180] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0181] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0182] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described roof contour straightening method. This reduces the deviation between the straightened roof contour and the original roof contour, improving the straightening accuracy of the roof contour. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the roof contour straightening method provided in the above embodiments, and will not be repeated here.

[0183] The above are only some embodiments of this application and do not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.

Claims

1. A method for regularizing the outline of a roof, characterized in that, The method includes: Obtain the roof area to be identified, and extract the outline of the roof area to be identified to obtain the roof outline to be identified, wherein the roof area to be identified is the area selected by the user; Determine the original roof outline corresponding to the roof area to be identified; Traverse each vertex of the roof outline to be identified, determine the outline points on the original roof outline that are aligned with each vertex, and construct an initial outline based on the outline points aligned with each vertex. Based on the target loss function and the initial contour, the contour points of the initial contour are iteratively adjusted to obtain the regularized roof contour.

2. The roof contour regularization method as described in claim 1, characterized in that, The step of determining the contour points aligned with each vertex on the original roof contour includes: Traverse each vertex of the roof outline to be identified, and for each vertex, determine the distance between that vertex and each outline point on the original roof outline; From all the contour points of the original roof outline, obtain the contour point that is closest to the vertex, and use it as the contour point on the original roof outline that is aligned with the vertex.

3. The roof contour regularization method as described in claim 1, characterized in that, The step of iteratively adjusting the contour points of the initial contour based on the target loss function and the initial contour to obtain the regularized roof contour includes: The initial profile is input into the target loss function, and the error between the initial profile and the original roof profile is calculated through each constraint term of the target loss function. Based on the errors calculated from each of the aforementioned constraints, the total error between the initial profile and the original roof profile is determined; If the total error does not meet the iteration termination condition, the coordinates of the contour points of the initial contour are updated to obtain the updated contour. The updated contour is then input into the target loss function to obtain the total error between the updated contour and the original roof contour. If the total error satisfies the iteration termination condition, the initial profile is taken as the regularized roof profile.

4. The roof contour regularization method as described in claim 3, characterized in that, The constraints include vertex distance error, shape similarity error, spatial elevation error, and adjacent edge orthogonality error; The calculation of the error between the initial profile and the original roof profile using each constraint term of the target loss function includes: When the constraint term is the vertex distance error term, traverse each vertex of the initial contour, and for each vertex, calculate the distance between each vertex and the original roof contour; obtain the vertex distance error between the initial contour and the original roof contour based on the sum of the squares of the distances between each vertex and the original roof contour. When the constraint term is the shape similarity error term, for each vertex of the initial contour, the distance to all contour points of the original roof contour is calculated to obtain the first shortest distance; for each contour point of the original roof contour, the distance to all vertices of the initial contour is calculated to obtain the second shortest distance; the maximum value between the first shortest distance and the second shortest distance is selected as the shape similarity error. When the constraint term is the spatial elevation error term, for each vertex of the initial contour, calculate the distance to all contour points of the original roof contour to obtain the nearest contour point of each vertex; obtain the elevation information of each vertex and the elevation information of each nearest contour point; calculate the square of the elevation difference between the elevation information of each vertex and the elevation information of the corresponding nearest contour point to obtain the spatial elevation error. When the constraint term is the adjacent edge orthogonality error, the adjacent edges of the initial contour are traversed to obtain the direction vector of each of the adjacent edges; the cosine value between two of the adjacent edges is calculated based on the direction vector; and the adjacent edge orthogonality error is determined based on the cosine value. The errors between the initial contour and the original roof contour include: the vertex distance error, the shape similarity error, the spatial elevation error, and the adjacent side orthogonality error.

5. The roof contour regularization method as described in claim 3, characterized in that, The determination of the total error between the initial profile and the original roof profile based on the errors calculated according to each of the constraints includes: The total error between the initial profile and the original roof profile is obtained by weighted summation based on the errors calculated from each constraint term and the weights of each constraint term.

6. The roof contour regularization method as described in claim 3 or 4, characterized in that, The step of updating the contour point coordinates of the initial contour to obtain the updated contour includes: The total error between the initial profile and the original roof profile is calculated using numerical differentiation, and the gradient of the coordinates of each profile point of the initial profile is calculated. Based on the gradient, the error descent direction is determined, and a line search is performed along the error descent direction to obtain the iteration step size; Based on the error descent direction and the iteration step size, the coordinates of each contour point of the initial contour are updated to obtain the updated contour.

7. The roof contour regularization method as described in claim 1, characterized in that, Before traversing each vertex of the roof contour to be identified, determining the contour points aligned with each vertex on the original roof contour, and constructing the initial contour based on the contour points aligned with each vertex, the method further includes: The roof outline to be identified and the original roof outline are respectively normalized. The normalization operation includes: detecting whether the outline is closed and detecting whether the outline direction is uniform. Simplify the outline points of the roof outline to be identified after the standardization operation; The step of traversing each vertex of the roof contour to be identified, determining the contour points on the original roof contour aligned with each vertex, and constructing an initial contour based on the contour points aligned with each vertex includes: Traverse each vertex of the roof outline to be identified after the simplification operation, determine the outline points on the original roof outline after the normalization operation that are aligned with each vertex, and construct the initial outline based on the outline points aligned with each vertex.

8. The roof contour regularization method as described in claim 1, characterized in that, After determining the original roof outline corresponding to the roof area to be identified, the method further includes: Traverse each edge of the original roof outline in sequence and identify the start and end points of each edge; Interpolate between the start and end points of each edge according to a preset interpolation interval to obtain each edge after interpolation; Construct the original roof outline after interpolation based on each interpolated edge; The step of traversing each vertex of the roof contour to be identified and determining the contour points on the original roof contour aligned with each vertex includes: Traverse each vertex of the roof outline to be identified, and determine the outline points on the original roof outline after interpolation that are aligned with each vertex.

9. A roof contour straightening device, characterized in that, The apparatus includes: a memory, a processor, and a roof profile straightening program stored in the memory and executable on the processor, the roof profile straightening program being configured to implement the steps of the roof profile straightening method as described in any one of claims 1 to 8.

10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and the storage medium stores a roof contour straightening program, which, when executed by a processor, implements the steps of the roof contour straightening method as described in any one of claims 1 to 8.