Hand-drawn graphics regularization method, electronic device and storage medium
Through the opponent's drawing shape, the inflection point extraction and segmentation processing solves the problem of not high accuracy of hand -drawn figures in the existing technologies, and achieves higher accuracy and lower calculation complexity.
Patent Information
- Application Number
- CN202111022297.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-01
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2041-09-01
AI Technical Summary
The existing hand-drawn graphics regularization methods are not very accurate, resulting in hand-drawn graphics being unstandard when outputting smart whiteboards.
By obtaining at least one hand -drawn pen painting of the hand -drawn figure, it is determined whether it is a default ruler line type, and determine whether the hand -drawn graphic is a preset rule graphic. If it is not, and there is a hand -painted strokes in the presence, the inflection point is extracted, which divides them into multiple regular stroke segments, and regularly draws according to these opponents.
It improves the accuracy of hand-drawn graphics regularization, can accurately restore the position of hand-drawn graphics and the user's drawing intention, while reducing the complexity and computational overhead of regularization.
Smart Images

Figure CN113888546B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision technology, and in particular to a method for regularizing hand-drawn graphics, an electronic device, and a computer-readable storage medium. Background Art
[0002] With the development of science and technology, people's office methods are gradually becoming intelligent. One of the manifestations is hand-drawing graphics on smart whiteboards during office work.
[0003] Generally speaking, the graphics obtained by users directly drawing on the smart whiteboard are not standard. In order to output standard graphics on the smart whiteboard, one existing method is that users do not draw directly on the smart whiteboard, but use the software tools provided by the smart whiteboard to select the desired standard graphics. Although this method can obtain the standard graphics that users want, the drawing is complex and time-consuming.
[0004] In order to reduce the complexity and time consumption of hand-drawing, another existing method is to receive the hand-drawn graphics directly drawn by the user on the smart whiteboard, and regularize the hand-drawn graphics into standard graphics. However, the accuracy of regularizing the hand-drawn graphics is not high. Summary of the invention
[0005] The present application provides a method for regularizing hand-drawn graphics, an electronic device, and a computer-readable storage medium, which can solve the problem of low accuracy in regularizing existing hand-drawn graphics.
[0006] In order to solve the above technical problems, a technical solution adopted by the present application is: to provide a method for regularizing a hand-drawn figure. The method includes: obtaining at least one hand-drawn stroke constituting the hand-drawn figure; judging whether each hand-drawn stroke is a preset regular line type, and judging whether the hand-drawn figure is a preset regular figure; if the hand-drawn figure is not a preset regular figure, and there is an irregular hand-drawn stroke that is not a preset regular line type in at least one hand-drawn stroke, then extracting the inflection point in the irregular hand-drawn stroke; segmenting the irregular hand-drawn stroke based on the inflection point to obtain multiple regular stroke segments; regularizing the hand-drawn figure according to the regular stroke segments.
[0007] To solve the above technical problems, another technical solution adopted in the present application is: to provide an electronic device, which includes a processor and a memory connected to the processor, wherein the memory stores program instructions; the processor is used to execute the program instructions stored in the memory to implement the above method.
[0008] In order to solve the above technical problems, another technical solution adopted by the present application is: providing a computer-readable storage medium storing program instructions, which can implement the above method when executed.
[0009] Through the above-mentioned method, the present application takes into account the local features (corresponding to a single hand-drawn stroke) and the overall features (corresponding to the combination of multiple hand-drawn strokes, the hand-drawn graphic itself) of the hand-drawn graphics for regularization, wherein the hand-drawn graphics are judged based on the local features whether there are irregular hand-drawn strokes, and the hand-drawn graphics are judged based on the overall features whether they are preset regular graphics, and the regularization method of the hand-drawn graphics is determined based on the judgment results, that is, when the hand-drawn graphics are not preset regular graphics and there are irregular hand-drawn strokes, the inflection points in the irregular hand-drawn strokes are extracted, and the irregular hand-drawn strokes are divided into multiple regular stroke segments based on the inflection points, and the hand-drawn graphics are regularized according to the regular stroke segments, so as to accurately restore the position of the hand-drawn graphics and the user's drawing intention. Therefore, the regularization method provided by the present application can improve the accuracy of the regularization of hand-drawn graphics. And because there is no need to build a database, the complexity of regularization and the required computational overhead are reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 It is a flow chart of an embodiment of a method for regularizing hand-drawn graphics of the present application;
[0011] Figure 2 yes Figure 1 A specific process diagram of S12;
[0012] Figure 3 yes Figure 1 Another specific flow diagram of S12;
[0013] Figure 4 It is a schematic diagram of the convex hull of a hand-drawn figure;
[0014] Figure 5 yes Figure 1 The specific process diagram of S15;
[0015] Figure 6 It is a flow chart of another embodiment of the method for regularizing hand-drawn graphics of the present application;
[0016] Figure 7 It is a flow chart of another embodiment of the method for regularizing hand-drawn graphics of the present application;
[0017] Figure 8 It is a flowchart of a specific example of a method for regularizing hand-drawn graphics of the present application;
[0018] Fig. 9 It is a structural schematic diagram of an embodiment of the electronic device of the present application;
[0019] Fig.10 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0020] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0021] The terms "first", "second", and "third" in this application are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first", "second", and "third" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0022] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments without conflict.
[0023] Before introducing the method provided by the present application in detail, a brief introduction to the technical idea of the present application is first given.
[0024] A hand-drawn graphic can be a hand-drawn stroke or a combination of multiple hand-drawn strokes. A hand-drawn stroke is composed of a number of points (sampling points) sampled in chronological order during the user's drawing process. The first sampling point corresponding to the hand-drawn stroke is the starting point of the hand-drawn stroke, and the last sampling point corresponding to the hand-drawn stroke is the end point of the hand-drawn stroke. Each sampling point has a corresponding serial number. The closer the sampling point is to the starting point, the smaller the serial number is, and the closer the sampling point is to the end point, the larger the serial number is.
[0025] From the perspective of whether they are closed or not, hand-drawn figures can be divided into closed figures and non-closed figures. Closed figures can include circles (ovals, standard circles), polygons, and polygons include triangles, rectangles, pentagons, etc. Non-closed figures can include straight lines, broken lines (such as angles), curves (such as sine waves, cosine waves, arcs), etc.
[0026] From the perspective of whether it is smooth or not, hand-drawn graphics can be divided into smooth graphics and non-smooth graphics. Smooth graphics have no inflection points, while non-smooth graphics have inflection points. Smooth graphics can include circles, curves, etc. Non-smooth graphics can include polygons, polylines, etc.
[0027] Therefore, combining the closed and smooth angles, hand-drawn figures can be subdivided into smooth closed figures, non-smooth closed figures, smooth non-closed figures (line type), and non-smooth non-closed figures (line type).
[0028] The so-called regularization of hand-drawn graphics refers to determining the user's drawing intention (i.e., the standard graphics that the user actually wants to draw) based on the characteristics of the hand-drawn graphics, and adjusting the hand-drawn graphics to the standard graphics at the original position of the hand-drawn graphics. The regularization of hand-drawn graphics in this application is divided into three situations:
[0029] In the first case, if the hand-drawn figure is a smooth figure, the hand-drawn figure can be directly fitted with an equation to achieve the regularity of the hand-drawn figure. For example, if the hand-drawn figure is a straight line, the straight line equation can be directly fitted on the hand-drawn figure. For another example, if the hand-drawn figure is a sine waveform, the sine equation can be directly fitted on the hand-drawn figure. For another example, if the hand-drawn figure is a circle, the circle equation can be directly fitted on the hand-drawn figure.
[0030] In the second case, the hand-drawn figure is a non-smooth figure, but each hand-drawn stroke included in the hand-drawn figure is a smooth line type, and the equation corresponding to each hand-drawn stroke is obtained to achieve the regularity of the hand-drawn figure.
[0031] In the third case, the hand-drawn figure is a non-smooth figure, and the hand-drawn figure includes hand-drawn strokes of non-smooth linear type. The hand-drawn strokes of non-smooth linear type need to be segmented with the inflection point as the boundary to segment the hand-drawn strokes of non-smooth linear type into multiple smooth hand-drawn strokes, and then the equations corresponding to each hand-drawn stroke included in the segmented hand-drawn figure are obtained respectively to achieve the regularity of the hand-drawn figure.
[0032] The following is a detailed description of the method provided by this application:
[0033] Figure 1 1 is a flow chart of an embodiment of the method for regularizing hand-drawn graphics of the present application. It should be noted that if there are substantially the same results, this embodiment is not limited to Figure 1 The process sequence shown is limited. Figure 1 As shown, this embodiment may include:
[0034] S11: Acquire at least one hand-drawn stroke constituting a hand-drawn graphic.
[0035] S12: Determine whether each hand-drawn stroke is a preset regular line type, and determine whether the hand-drawn graphic is a preset regular graphic.
[0036] The preset regular line type is a smooth line type (smooth non-closed figure), and the preset regular figure is a smooth figure. In the following text of this application, hand-drawn strokes of preset regular line type are referred to as regular hand-drawn strokes, and hand-drawn strokes that are not preset regular line type are referred to as irregular hand-drawn strokes.
[0037] Combine as follows Figure 2 , taking the preset regular line type as a straight line, how to determine whether each hand-drawn stroke is a preset regular line type in S12 is described. Figure 2 As shown, S12 may include the following sub-steps:
[0038] S121: Connect the starting point and the end point of the hand-drawn stroke to obtain a line segment.
[0039] S122: Determine whether the line segment meets a preset condition.
[0040] The preset conditions include that the distance from the sampling point of the hand-drawn stroke to the line segment belongs to a first distance range, and / or the ratio of the sum of the distances between two adjacent sampling points of the hand-drawn stroke to the length of the line segment belongs to a second distance range.
[0041] For example, the first distance range is [-dm, dm], and the second distance range is [0.95, 1]. If the distances from the sampling points of the hand-drawn strokes to the line segments all belong to [-dm, dm], and the ratio of the sum of the distances Lm between two adjacent sampling points of the hand-drawn strokes to the length L of the line segment belongs to [0.95, 1.1], then it is determined that the line segment meets the preset conditions.
[0042] If satisfied, execute S123; if not satisfied, execute S124.
[0043] S123: Determine whether the hand-drawn stroke is a straight line.
[0044] When the hand-drawn stroke is determined to be a straight line, the straight line where the line segment is located can be directly applied to the subsequent second / third cases to regularize the hand-drawn graphics.
[0045] S124: Determine whether the hand-drawn stroke is not a straight line.
[0046] In other embodiments, the judgment of whether each hand-drawn stroke is a preset regular line type can also be performed by directly fitting each hand-drawn stroke, and then judging whether the fitted straight line meets the preset conditions, and if so, judging that the hand-drawn stroke is a straight line. In addition, the fitted straight line can be directly used for the subsequent regularization of the second / third case hand-drawn graphics.
[0047] Combine as follows Figure 3 , taking the preset regular graphic as a circle, how to determine whether the hand-drawn graphic is a preset regular graphic in S12 is described. Figure 3 As shown, S12 may include the following sub-steps:
[0048] S124: Obtain the convex hull of the hand-drawn figure.
[0049] The outermost sampling points of the hand-drawn figure can be connected to form the convex hull of the hand-drawn figure. Figure 4 , Figure 4 is a schematic diagram of the convex hull of a hand-drawn figure. Figure 4 As shown, the hand-drawn figure includes sampling points 1 to 7, and the sampling points 1, 2, 4, 5, and 7 are connected to serve as the convex hull of the hand-drawn figure.
[0050] In order to improve the accuracy of the judgment result, before this step, the sampling points of the hand-drawn graphics may be deduplicated.
[0051] S125: Obtain the maximum inscribed quadrilateral of the convex hull.
[0052] S126: Determine whether the hand-drawn figure is a circle based on the ratio of the area of the largest inscribed quadrilateral to the area of the convex hull.
[0053] If the ratio of the area S2 of the largest inscribed quadrilateral to the area S1 of the convex hull is less than the threshold Rm, the hand-drawn figure is determined to be a circle, otherwise the hand-drawn figure is determined to be a non-circle.
[0054] Thus, through the judgment of S12, it can be determined which of the above three situations the hand-drawn graphic belongs to. That is, whether the hand-drawn graphic is a smooth graphic (the first situation), a non-smooth graphic including only smooth linear hand-drawn strokes (the second situation), or a non-smooth graphic including non-smooth linear hand-drawn strokes (the third situation). Furthermore, the regularization method of the hand-drawn graphic can be determined.
[0055] If the hand-drawn graphic is not a preset regular graphic, and at least one hand-drawn stroke contains irregular hand-drawn strokes that are not of the preset regular line type, that is, the hand-drawn graphic belongs to the third case, then S13 to S15 are executed.
[0056] S13: Extracting inflection points in irregular hand-drawn strokes.
[0057] The inflection point can be selected from the plurality of sampling points by the curvature corresponding to the plurality of sampling points in the non-hand-drawn stroke. Specifically, the curvature corresponding to each sampling point of the irregular hand-drawn stroke can be calculated; and the sampling point whose curvature is greater than the curvature threshold is taken as the inflection point.
[0058] The curvature corresponding to the current sampling point is calculated based on the coordinates of the current sampling point and the coordinates of the previous sampling point. For example, the coordinates of the current sampling point are (x i ,y i ), the coordinates of the previous sampling point are (x i-1 ,y i-1 ). The curvature k of the current sampling point can be calculated by the following formula:
[0059]
[0060]
[0061]
[0062] After the inflection point is extracted, the process may directly proceed to S14. Alternatively, in order to improve the accuracy of subsequent processing, the inflection point may be subjected to denoising. The situations that lead to the noise inflection point may be summarized into at least the following two situations.
[0063] 1) When a user draws the beginning and / or end of an irregular hand-drawn stroke, the instability is high (caused by user hand shaking, etc.), so noise inflection points are likely to appear at the beginning and / or end of the irregular hand-drawn stroke.
[0064] In this case, a first preset number of inflection points near the starting point of the irregular hand-drawn stroke may be removed, and / or a second preset number of inflection points near the end point of the irregular hand-drawn stroke may be removed. The first preset number of inflection points near the starting point of the irregular hand-drawn stroke are inflection points of the beginning part of the irregular hand-drawn stroke, and the second preset number of inflection points near the end point of the irregular hand-drawn stroke are inflection points of the ending part of the irregular hand-drawn stroke.
[0065] 2) The turning point of the irregular hand-drawn stroke includes multiple inflection points, and subsequent processing only requires some of the multiple inflection points, so that the remaining inflection points of the multiple inflection points are noise inflection points.
[0066] Considering that the numbers of adjacent inflection points in the turning point are similar, in this case, the noise inflection points can be removed by limiting the difference in the numbers of adjacent inflection points. Specifically, if the difference in the numbers of the previous inflection point and the next inflection point of the irregular hand-drawn stroke is less than the number threshold, the previous inflection point is removed, where the inflection point closer to the starting point of the irregular hand-drawn stroke has a larger number.
[0067] S14: Segment the irregular hand-drawn strokes based on the inflection points to obtain a plurality of regular stroke segments.
[0068] The irregular hand-drawn stroke can be segmented into a plurality of regular stroke segments of a preset regular line type with the inflection point as a boundary. For example, if the irregular hand-drawn stroke includes two inflection points, the irregular stroke can be segmented into three regular stroke segments.
[0069] S15: regularizing the hand-drawn graphics according to the regular stroke segments.
[0070] The third situation mentioned above can be further divided into two types:
[0071] 1) The hand-drawn graphics include all irregular hand-drawn strokes. Therefore, after segmentation, the hand-drawn graphics include all regular stroke segments. At this time, the hand-drawn graphics need to be regularized according to the regular stroke segments.
[0072] 2) The hand-drawn graphics include both irregular hand-drawn strokes and regular hand-drawn strokes. Therefore, after segmentation, the hand-drawn graphics include both regular stroke segments obtained by segmenting irregular hand-drawn strokes and regular hand-drawn strokes. At this time, this step needs to regularize the hand-drawn graphics according to the regular stroke segments and regular hand-drawn strokes.
[0073] To simplify the description, regular hand-drawn strokes and regular stroke segments are collectively referred to as regular strokes. In the regularization process, the processing of all regular strokes is to obtain the equations corresponding to all regular strokes. For example, for regular strokes that are straight lines, the corresponding straight line equations are obtained; for regular strokes that are wavy, the corresponding waveform equations are obtained; for regular strokes that are arcs, the corresponding arc equations are obtained. Then, the target graphics are obtained based on the equations corresponding to all regular strokes.
[0074] As an embodiment, the target figure can be obtained directly according to the positional relationship (length, angle) of the equations corresponding to different regular strokes.
[0075] As another embodiment, the intersection of equations corresponding to two adjacent regular strokes may be obtained, and the equations corresponding to the regular strokes may be linked together based on the intersection to achieve regularization of the hand-drawn figure.
[0076] Taking the preset regular line type as a straight line as an example, the straight line corresponding to each regular stroke can be obtained, the intersection between two adjacent straight lines can be obtained, and the intersection points can be connected in sequence to obtain the target figure. Among them, the starting point and the end point of the regular stroke can be directly connected to obtain the straight line corresponding to the regular stroke. Alternatively, the regular strokes can be fitted with a straight line to obtain the straight line corresponding to the regular stroke. Among them, for regular hand-drawn strokes, the straight line where the line segment obtained by S12 is located or the straight line obtained by fitting can also be directly used as the corresponding straight line to reduce the amount of calculation.
[0077] Combined with reference Figure 5 In the straight line fitting mode, S15 may include the following sub-steps:
[0078] S151: Perform straight line fitting on all regular strokes to obtain a number of straight lines.
[0079] The number of straight lines obtained by fitting is the same as the number of regular strokes. For example, if the hand-drawn figure is a triangle, three straight lines can be fitted. For another example, if the hand-drawn figure is a quadrilateral, four straight lines can be fitted.
[0080] S152: Obtain the intersection point between two adjacent straight lines.
[0081] For example, if three straight lines are fitted, three intersection points can be obtained. For another example, if four straight lines are fitted, four intersection points can be obtained.
[0082] To illustrate, we can obtain the intersection of two straight lines. The equation of the straight line is:
[0083] y1=a1x+b1,
[0084] The second equation of the line is:
[0085] y2=a2x+b2,
[0086] The intersection point (x,y) of line 1 and line 2 is:
[0087]
[0088] y=a1×x+b1.
[0089] S153: Connect the intersection points in sequence to obtain the target figure.
[0090] For example, if there are three intersection points, the target figure obtained is a triangle; if there are four intersection points, the target figure obtained is a quadrilateral.
[0091] Through the implementation of this embodiment, the present application takes into account the local features (corresponding to a single hand-drawn stroke) and overall features (corresponding to a combination of multiple hand-drawn strokes, the hand-drawn graphic itself) of the hand-drawn graphic for regularization, wherein the hand-drawn graphic is judged based on the local features whether there are irregular hand-drawn strokes, and the hand-drawn graphic is judged based on the overall features whether it is a preset regular graphic, and the regularization method of the hand-drawn graphic is determined based on the judgment result, that is, when the hand-drawn graphic is not a preset regular graphic and there are irregular hand-drawn strokes, the inflection points in the irregular hand-drawn strokes are extracted, and the irregular hand-drawn strokes are divided into multiple regular stroke segments based on the inflection points, and the hand-drawn graphic is regularized according to the regular stroke segments, so as to accurately restore the position of the hand-drawn graphic and the user's drawing intention. Therefore, the regularization method provided by the present application can improve the accuracy of the regularization of hand-drawn graphics; and, since there is no need to build a database, the complexity of regularization and the required computational overhead are reduced.
[0092] In addition, if S12 determines that the hand-drawn graphic is not a preset regular graphic, and includes regular hand-drawn strokes of preset regular line types, that is, it belongs to the second case, then you can directly enter S15 to regularize the hand-drawn graphic according to all the hand-drawn strokes (regular hand-drawn strokes) of the hand-drawn graphic.
[0093] Combine as follows Figure 6 Still taking the preset regular line type as a straight line as an example, in the second / third case, in the process of regularizing the hand-drawn graphics according to the regular strokes, the straight line corresponding to the regular strokes is obtained by straight line fitting the regular strokes.
[0094] S21: constructing a first function based on the sum of squares of distances from sampling points of regular strokes to straight line equations.
[0095] For example, establish a straight line equation y=ax+b, where a (slope) and b (intercept) are the straight line parameters to be determined. i ,y i ) to the equation of the line is:
[0096]
[0097] The first function is:
[0098]
[0099] S22: Calculate the partial derivative of the first function with respect to each straight line parameter to obtain a first partial derivative result.
[0100] Let J find the partial derivative of a Let J find the partial derivative of b make Get 2 first partial derivative results.
[0101] S23: Solve the straight line parameters based on the first partial derivative result.
[0102] The two first partial derivative results are jointly solved to obtain a and b, thereby determining the equation of the line.
[0103] In addition, if it is determined by S12 that the hand-drawn figure is a preset regular figure, that is, it belongs to the first case, then S16 is executed: equation fitting is performed on the hand-drawn figure. That is, the hand-drawn figure is fitted with the equation of the target figure, so as to achieve the regularization of the hand-drawn figure. Figure 7 , still taking the preset regular shape of a circle as an example for explanation.
[0104] S31: Construct a second function based on the sum of squares of distances from the sampling points of the hand-drawn graphic to the circle equation.
[0105] For example, establish the general equation of an ellipse, Q(x,y)=Ax 2 +Bxy+Cy 2 +Dx+Ey+F=0. A, B, C, D and E are the circular parameters to be determined. In order to prevent the fitted parameters A, B, C, D, E, F from being all 0, let F=1. The first function is:
[0106]
[0107] Among them, (x i ,y i ) represents the i-th sampling point.
[0108] S32: Calculate the partial derivative of the second function with respect to each circular parameter to obtain a second partial derivative result.
[0109] Let L find the partial derivative of A, B, C, D, and E respectively make Get 5 second partial derivative results.
[0110] S33: Solve the circular parameters based on the second partial derivative result.
[0111] The five second partial derivative results are jointly solved to obtain A, B, C, D, and E. Thus, the general equation of the ellipse is determined. Furthermore, the general equation of the ellipse can be converted into the standard equation of the ellipse to obtain the coordinates of the ellipse center, the major axis, the minor axis, and the tilt angle of the ellipse.
[0112] In addition, in the first / second / third case above, after the target graph is obtained through fitting, the target graph can be directly used as the regularization result. Alternatively, in order to further improve the accuracy of the regularization result, the target graph can be further corrected.
[0113] Still taking the preset rule line type as a straight line as an example, the correction of the target figure obtained in the second / third case is explained. The target figure includes one or more edges. In the case where the target figure includes multiple edges, the target figure can be corrected based on the angle of the edge and / or the length of the edge of the target figure. Specifically, the category to which the target figure belongs can be determined based on the length relationship of the edge and the angle relationship of the edge of the target figure, and then the length and angle of the edge of the target figure can be corrected based on the properties of the figure of the category to which it belongs.
[0114] For example, the target figure is a triangle, including three sides. The types of triangles include equilateral triangles, isosceles triangles, right triangles and others. Therefore, according to the properties of each type of triangle, the target figure can be processed as follows:
[0115] If the ratio of the lengths of two of the three sides belongs to the first length range (for example, [0.9, 1.1]), the lengths of the two sides are corrected to be the same, that is, it is corrected to an isosceles triangle. If the ratio of one of the three sides to the other two sides is in the first length range, the lengths of the three sides are corrected to be the same, and it is corrected to an equilateral triangle. If the angles of two of the three sides belong to the first angle range (for example, [80°, 95°]), the angles of the first angle range are corrected to 90°, that is, it is corrected to a right triangle. Among them, the larger the length range / angle range, the higher the degree of irregularity of the hand-drawn graphics drawn by the user.
[0116] For another example, the target figure is a quadrilateral, including four sides. Quadrilaterals include trapezoids, parallelograms (squares, rectangles, rhombuses and other parallelograms) and others. Therefore, according to the properties of each type of quadrilateral, the target figure can be processed as follows:
[0117] If the difference between the angles between two of the four sides and the same coordinate axis (such as the x-axis) is less than a preset angle difference (such as 10°), the angle between the two sides is corrected to 0, that is, the two sides are corrected to be parallel.
[0118] On the basis of parallelism, if one set of sides is parallel, the target figure is corrected to a trapezoid; if two sets of sides are parallel, the target figure is corrected to a parallelogram.
[0119] On the basis of the parallelogram, if the length ratio of any two sides belongs to the second length range (for example, [0.85, 1.15]), the target figure is corrected to a rhombus. If the length ratio of any two sides belongs to the third length range (for example, [0.9, 1.1]), the target figure is corrected to a rectangle (square).
[0120] The following describes the correction of the target graphic obtained in the third case by taking the preset regular graphic being a circle as an example.
[0121] If the ratio of the major axis to the minor axis belongs to a third length range (eg, [0.87, 1.13]), the preset regular shape is corrected to a standard circle.
[0122] Combine the following Figure 8 , the regularization method provided by this application is described in detail in the form of an example:
[0123] 1) Obtain the hand-drawn graphics (graphic input) input by the user;
[0124] 2) Determine whether each hand-drawn stroke constituting the hand-drawn figure is a straight line (straight line determination); if all hand-drawn strokes are not straight lines, proceed to step 3); if there are hand-drawn strokes that are all straight lines, proceed to step 4);
[0125] 3) Determine whether the hand-drawn figure is an ellipse (ellipse determination); if it is an ellipse, perform ellipse fitting on the hand-drawn figure; if it is not an ellipse, proceed to step 4);
[0126] 4) Obtain the inflection points of the non-linear hand-drawn strokes, and use the inflection points to segment the non-linear hand-drawn strokes into a number of linear hand-drawn strokes (stroke segmentation); perform straight line fitting on each linear hand-drawn stroke to achieve the regularization of the hand-drawn graphics (graphic regularization).
[0127] Fig. 9 Schematic diagram of the structure of an embodiment of the electronic device of the present application. Fig. 9 As shown, the electronic device includes a processor 21 and a memory 22 coupled to the processor 21 .
[0128] The memory 22 stores program instructions for implementing the method of any of the above embodiments; the processor 21 is used to execute the program instructions stored in the memory 22 to implement the steps of the above method embodiments. The processor 21 may also be referred to as a CPU (Central Processing Unit). The processor 21 may be an integrated circuit chip with signal processing capabilities. The processor 21 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0129] Fig.10 Schematic diagram of the structure of an embodiment of a computer-readable storage medium of the present application. Fig.10 As shown, the computer-readable storage medium 30 of the embodiment of the present application stores program instructions 31, and the program instructions 31 are executed to implement the method provided in the above embodiment of the present application. Among them, the program instructions 31 can form a program file and be stored in the above computer-readable storage medium 30 in the form of a software product, so that a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) executes all or part of the steps of each implementation method of the present application. The aforementioned computer-readable storage medium 30 includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, or a terminal device such as a computer, a server, a mobile phone, and a tablet.
[0130] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0131] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. The above is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made by using the description and drawings of this application, or directly or indirectly used in other related technical fields, is also included in the patent protection scope of the present application.
Claims
1. A method for regularizing hand-drawn graphics, characterized in that: include: Acquire at least one hand-drawn stroke constituting the hand-drawn graphic to be regularized, wherein each of the hand-drawn strokes is composed of a number of sampling points sampled sequentially in time sequence during the drawing process; Determining whether each of the hand-drawn strokes is a preset regular line type, and determining whether the hand-drawn graphics are preset regular graphics; If the hand-drawn figure is not a preset regular figure, and there is an irregular hand-drawn stroke that is not a preset regular line type in the at least one hand-drawn stroke, extracting an inflection point in the irregular hand-drawn stroke; Segmenting the irregular hand-drawn strokes based on the inflection points to obtain a plurality of regular stroke segments; The hand-drawn graphics are regularized according to the regular stroke segments.
2. The tidying method according to claim 1, characterized in that: The preset regular line type is a straight line, and the determining whether each of the hand-drawn strokes is of the preset regular line type includes: For each of the hand-drawn strokes, connecting the starting point and the end point of the hand-drawn stroke to obtain a line segment; Determining whether the line segment satisfies a preset condition, wherein the preset condition includes that a distance from a sampling point of the hand-drawn stroke to the line segment belongs to a first distance range, and / or a ratio of a sum of distances between two adjacent sampling points of the hand-drawn stroke to a length of the line segment belongs to a second distance range; If it is satisfied, it is determined that the hand-drawn stroke is a straight line.
3. The structuring method according to claim 2, characterized in that: If the hand-drawn stroke is a straight line, the regularization method further includes: Constructing a first function based on the sum of squares of distances from sampling points of the hand-drawn strokes to a straight line equation; Calculating the partial derivative of the first function with respect to each straight line parameter to obtain a first partial derivative result; The straight line parameters are solved based on the first partial derivative result.
4. The tidying method according to claim 1, characterized in that: The preset regular graphic is a circle, and the determining whether the hand-drawn graphic is a preset regular graphic includes: Obtaining the convex hull of the hand-drawn figure; Obtain the maximum inscribed quadrilateral of the convex hull; Based on the ratio of the area of the maximum inscribed quadrilateral to the area of the convex hull, it is determined whether the hand-drawn figure is a circle.
5. The structuring method according to claim 4, characterized in that: If the hand-drawn figure is a circle, the regularization method further includes: Constructing a second function based on the sum of squares of distances from the sampling points of the hand-drawn graphic to the circle equation; Calculating the partial derivative of the second function with respect to each circular parameter to obtain a second partial derivative result; The circular parameter is solved based on the second partial derivative result.
6. According to the regularization method of claim 1, the step of extracting the inflection points in the irregular hand-drawn strokes comprises: Calculating the curvature corresponding to each sampling point of the irregular hand-drawn stroke; The sampling point whose curvature is greater than the curvature threshold is taken as the inflection point.
7. The structuring method according to claim 1, characterized in that: Before segmenting the irregular hand-drawn strokes based on the inflection points to obtain a plurality of regular stroke segments, at least one of the following steps is included: removing a first preset number of the inflection points close to the starting point of the irregular hand-drawn stroke; removing a second preset number of the inflection points close to the end point of the irregular hand-drawn stroke; If the difference in sequence numbers between the previous inflection point and the next inflection point of the irregular hand-drawn stroke is less than the sequence number threshold, the previous inflection point is removed, wherein the inflection point closer to the starting point of the irregular hand-drawn stroke has a larger sequence number.
8. The structuring method according to claim 1, characterized in that: The step of regularizing the hand-drawn graphic according to the regular stroke segments includes: If there are regular hand-drawn strokes of a preset regular line type, the hand-drawn graphic is regularized according to the regular stroke segments and the regular hand-drawn strokes of the preset regular line type; If there is no regular hand-drawn stroke of the preset regular line type, the hand-drawn graphic is regularized according to the regular stroke segments.
9. The structuring method according to claim 8, characterized in that: The preset regular line type is a straight line, the regularizing of the hand-drawn graphics according to the regular stroke segments and the regular hand-drawn strokes of the preset regular line type, and the regularizing of the hand-drawn graphics according to the regular stroke segments both include: Perform straight line fitting on all regular strokes to obtain several straight lines; Get the intersection point between two adjacent straight lines; The intersection points are connected in sequence to obtain a target graph.
10. The structuring method according to claim 9, characterized in that: After the intersection points are connected in sequence to obtain the target graph, the regularization method further includes: The target figure is modified based on the angle of the side and / or the length of the side of the target figure.
11. An electronic device, characterized in that: The method comprises a processor and a memory connected to the processor, wherein: The memory stores program instructions; The processor is configured to execute the program instructions stored in the memory to implement the method according to any one of claims 1 to 10.
12. A computer-readable storage medium, characterized in that: The storage medium stores program instructions, and when the program instructions are executed, the method according to any one of claims 1 to 10 is implemented.
Citation Information
Patent Citations
Normalizing method and system of hand drawing geometric figures
CN105719328A