Graphics recognition method, device, storage medium and terminal equipment
By obtaining brush information and extracting the tilt parameters of the external rectangle of the candidate figure, the problem of difficult to identify and draw tilt patterns in the prior art is solved, and the accurate identification and drawing of the shape categories and tilt angles of the target figure are achieved.
Patent Information
- Application Number
- CN202111187008.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-12
- Publication Date
- 2025-03-04
- Estimated Expiration
- 2041-10-12
AI Technical Summary
In the prior art, when identifying the graphic outline, it is difficult to accurately process the graphics in the tilted state, resulting in inaccurate drawing results.
By obtaining brush information for drawing the target graphic, determining the image to be processed, and extracting the external rectangle of the candidate graphic to calculate the tilt parameters, the shape category and tilt angle of the target graphic are finally determined.
Accurate identification of the shape categories and inclination angles of the target figure is achieved, and the accuracy of graphic drawing is improved.
Smart Images

Figure CN113963362B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image recognition technology, and in particular to a graphic recognition method, device, storage medium and terminal device. Background Art
[0002] As the technology of manual recognition becomes more and more popular, after the recognition is completed, the outline of the figure is extracted, the target figure is drawn or the target figure is extracted, etc., wherein manual recognition can be achieved through machine learning. However, the outlines of the figures extracted by the currently commonly used manual recognition methods are generally basic figures, such as rectangles, circles, triangles, etc., and the recognition results are still straightened figures, such as straightened rectangles, etc. However, in actual applications, the figure to be drawn may be a figure in a tilted state, such as a rectangle in a tilted state, etc. At this time, there will be a deviation between the drawn figure and the figure actually required to be drawn, which will cause the problem of inaccurate drawing results.
[0003] Therefore the prior art still needs to be improved and enhanced. Summary of the invention
[0004] The technical problem to be solved by the present application is to provide a graphic recognition method, device, storage medium and terminal device in view of the deficiencies in the prior art.
[0005] In order to solve the above technical problems, the first aspect of the embodiment of the present application provides a graphic recognition method, the method comprising:
[0006] Acquire brush information for drawing a target graphic, and determine an image to be processed based on the brush information, wherein the image to be processed includes the target graphic;
[0007] Determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed;
[0008] Extracting a bounding rectangle of the candidate figure, and determining a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate figure;
[0009] A target graphic category of the target graphic is determined based on the candidate graphic category and the tilt parameter, wherein the target graphic category includes a shape category and a tilt angle.
[0010] The graphic recognition method, wherein the step of obtaining the brush information for drawing the graphic is specifically:
[0011] A control instruction for starting to draw a graphic is received, and brush information formed based on the control instruction is recorded to obtain brush information for drawing a target graphic.
[0012] The graphic recognition method, wherein the step of determining the image to be processed based on the brush information specifically comprises:
[0013] Determine a plurality of target positions corresponding to the target graphic based on the brush information, and draw candidate rectangles based on the target positions;
[0014] A candidate image is created with the candidate rectangle as the image edge, and a candidate graphic is drawn in the candidate image based on the brush information to obtain an image to be processed, wherein the background of the image to be processed is white and the candidate graphic is black.
[0015] The graphic recognition method, wherein the step of determining the candidate graphic corresponding to the brush information based on the image to be processed specifically comprises:
[0016] Convert the pattern to be processed into a grayscale image through OpenCV;
[0017] A convex hull point set corresponding to the stroke information is determined based on the grayscale image, and a candidate graph is determined based on the convex hull point set.
[0018] The graphic recognition method, wherein the step of determining the tilt parameter corresponding to the brush information based on the circumscribed rectangle and the candidate graphic specifically comprises:
[0019] Obtaining the rectangular center of the circumscribed rectangle, and rotating the candidate graphic in a preset direction within a preset angle range with the rectangular center as the rotation center;
[0020] Obtain the reference circumscribed rectangle of the candidate figure corresponding to each rotation angle during the rotation process, and record the circumscribed rectangle with the smallest area and the rotation angle corresponding to the circumscribed rectangle with the smallest area;
[0021] Based on the circumscribed rectangle with the smallest area and the rotation angle, a tilt parameter corresponding to the brush information is determined.
[0022] The graphic recognition method, wherein the candidate graphic category includes a rectangle category, and the tilt parameter includes a rotation angle; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes:
[0023] If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, a rectangle is used as a shape category in the target graphic category of the target graphic, and zero degree is used as a tilt angle in the target graphic category of the target graphic;
[0024] If the rotation angle is less than the first angle threshold and greater than the second angle threshold, the rectangle is used as the shape category in the target graphic category of the target graphic, and the rotation angle is used as the tilt angle in the target graphic category of the target graphic.
[0025] The graphic recognition method, wherein the candidate graphic category includes a circular category, the tilt parameter includes a rotation angle and a ratio of a short side to a long side of a circumscribed rectangle of a minimum area; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes:
[0026] If the ratio value is greater than a preset ratio threshold, a circle is used as a shape category in a target graphic category of the target graphic, and zero degree is used as an inclination angle in a target graphic category of the target graphic;
[0027] If the ratio value is less than or equal to a preset ratio threshold, obtaining a rotation angle of the circumscribed rectangle relative to the reference circumscribed rectangle;
[0028] If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, an ellipse is used as the shape category in the target graphic category of the target graphic, and zero degree is used as the tilt angle in the target graphic category of the target graphic;
[0029] If the rotation angle is less than the first angle threshold and greater than the second angle threshold, the ellipse is used as the shape category in the target graphic category of the target graphic, and the rotation angle is used as the tilt angle in the target graphic category of the target graphic.
[0030] A second aspect of an embodiment of the present application provides a graphic recognition device, the graphic recognition device comprising:
[0031] An acquisition module, used for acquiring brush information used for drawing a target graphic, and determining an image to be processed based on the brush information, wherein the image to be processed includes the target graphic;
[0032] A first determination module, configured to determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed;
[0033] An extraction module, configured to extract a bounding rectangle of the candidate graphic, and determine a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic;
[0034] The second determining module is configured to determine a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter, wherein the target graphic category includes a shape category and a tilt angle.
[0035] A third aspect of an embodiment of the present application provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in any of the graphic recognition methods described above.
[0036] A fourth aspect of the embodiments of the present application provides a terminal device, comprising: a processor, a memory, and a communication bus; the memory stores a computer-readable program that can be executed by the processor;
[0037] The communication bus realizes the connection and communication between the processor and the memory;
[0038] When the processor executes the computer-readable program, the steps in any of the above-mentioned graphic recognition methods are implemented.
[0039] Beneficial effects: Compared with the prior art, the present application provides a graphic recognition method, device, storage medium and terminal device, the method comprising obtaining brush information for drawing a target graphic, and determining an image to be processed based on the brush information; determining a candidate graphic category corresponding to the image to be processed, and determining a candidate graphic corresponding to the brush information based on the image to be processed; obtaining a bounding rectangle of the candidate graphic, and determining a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic; and determining a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter. The present application first extracts the candidate graphic category of the target graphic through manual recognition and determines its corresponding bounding matrix based on stroke information, and finally determines the shape category and tilt angle corresponding to the target graphic based on the bounding rectangle and the candidate graphic category, so that not only the shape category of the target graphic can be identified but also its corresponding tilt angle can be obtained, so that a graphic with a tilt angle can be drawn when the target graphic is subsequently drawn, thereby improving the drawing accuracy of the target graphic. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without inventive work.
[0041] Figure 1 A flowchart of the graphic recognition method provided in this application.
[0042] Figure 2 A schematic diagram of a flow chart of an embodiment of a graphic recognition method provided in the present application.
[0043] Figure 3 A flowchart of another embodiment of the graphic recognition method provided in the present application.
[0044] Figure 4 This is a structural principle diagram of the graphic recognition device provided in this application.
[0045] Figure 5 This is a schematic diagram of the structure of the terminal device provided in this application. DETAILED DESCRIPTION
[0046] The present application provides a pattern recognition method, device, storage medium and terminal device. In order to make the purpose, technical solution and effect of the present application clearer and more specific, the present application is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described here are only used to explain the present application and are not used to limit the present application.
[0047] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0048] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0049] It should be understood that the sequence numbers and sizes of the steps in this embodiment do not mean the order of execution. The execution order of each process is determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0050] The inventor has found through research that as the technology of manual recognition becomes more and more popular, after completing the recognition, the outline of the figure is extracted, the target figure is drawn or the target figure is extracted, etc., wherein manual recognition can be achieved through machine learning. However, the outlines of the figures extracted by the currently commonly used manual recognition methods are generally basic figures, such as rectangles, circles, triangles, etc., and the recognition results are still straightened figures, such as straightened rectangles, etc. However, in actual applications, the figure to be drawn may be a figure in an inclined state, such as a rectangle in an inclined state, etc. In this case, there will be a deviation between the drawn figure and the figure actually required to be drawn, which will cause the problem of inaccurate drawing results.
[0051] In order to solve the above problems, in an embodiment of the present application, the brush information used to draw the target graphic is obtained, and the image to be processed is determined based on the brush information; the candidate graphic category corresponding to the image to be processed is determined, and the candidate graphic corresponding to the brush information is determined based on the image to be processed; the circumscribed rectangle of the candidate graphic is obtained, and the tilt parameter corresponding to the brush information is determined based on the circumscribed rectangle and the candidate graphic; the target graphic category of the target graphic is determined based on the candidate graphic category and the tilt parameter. The present application first extracts the candidate graphic category of the target graphic through manual identification and determines its corresponding circumscribed matrix based on the stroke information, and finally determines the shape category and tilt angle corresponding to the target graphic based on the circumscribed rectangle and the candidate graphic category. In this way, not only the shape category of the target graphic can be identified, but also its corresponding tilt angle can be obtained, so that when the target graphic is subsequently drawn, a graphic with a tilt angle can be drawn, thereby improving the drawing accuracy of the target graphic.
[0052] The application content is further explained below through the description of embodiments in conjunction with the accompanying drawings.
[0053] This embodiment provides a graphic recognition method, such as Figure 1 As shown, the method includes:
[0054] S10. Obtain brush information for drawing a target graphic, and determine an image to be processed based on the brush information, wherein the image to be processed includes the target graphic.
[0055] Specifically, the brush information is the brush information formed by the user drawing the target graphic, wherein the brush information includes a plurality of brush points, and the plurality of brush points all carry position information. The sliding brush information can be formed by receiving a drawing operation input by the user, or can be sent by an external device, or can be obtained through the cloud. In a typical implementation of this embodiment, the brush information is formed by receiving a drawing operation input by the user.
[0056] Based on this, in an implementation of this embodiment, the step of obtaining the brush information for drawing a graphic is as follows:
[0057] A control instruction for starting to draw a graphic is received, and brush information formed based on the control instruction is recorded to obtain brush information for drawing a target graphic.
[0058] Specifically, the control instruction may be a control instruction to start drawing a target graphic. After receiving the control instruction, start recording the brush information formed by the received drawing operation. When the drawing operation ends, complete the brush information recording operation, and use all the brush information received from receiving the drawing operation until the drawing operation ends as the brush information for drawing the target graphic. The recorded brush information may be recorded in a list, and the list may be used as a to-be-processed brush list. When the brush information is needed, the brush information may be obtained by reading the to-be-processed brush list.
[0059] In an implementation of this embodiment, determining the image to be processed based on the brush information specifically includes:
[0060] Determine a plurality of target positions corresponding to the target graphic based on the brush information, and draw candidate rectangles based on the target positions;
[0061] A candidate image is created with the candidate rectangle as the image edge, and a candidate graphic is drawn in the candidate image based on the brush information to obtain an image to be processed, wherein the background of the image to be processed is white and the candidate graphic is black.
[0062] Specifically, the image size of the image to be processed is equal to the size of the candidate rectangle. It can be understood that the image of the image to be processed is formed into a rectangle, and the long side of the image to be processed is equal to the long side of the candidate rectangle, and the short side of the image to be processed is equal to the short side of the candidate rectangle. The target positions include extracting the leftmost brush point, the topmost brush point, the bottommost brush point and the rightmost brush point in the brush information, that is, the candidate rectangle is determined based on the leftmost brush point, the topmost brush point, the bottommost brush point and the rightmost brush point in the brush information. Based on this, the determination process of the candidate rectangle can be: obtain the brush information by calling the list of strokes to be processed, then extract the leftmost brush point, the topmost brush point, the bottommost brush point and the rightmost brush point in the brush information, and finally draw a rectangle that passes through the leftmost brush point, the topmost brush point, the bottommost brush point and the rightmost brush point in sequence, and use the drawn rectangle as the candidate rectangle.
[0063] After obtaining the candidate rectangle, a candidate image can be created with the candidate rectangle as the image edge, wherein the candidate image is a blank image and the background of the candidate image is a white background. After obtaining the candidate image, the brush information is drawn on the candidate image to obtain the image to be processed. For example, a candidate image Bitmap with a white background (#FFFFFF) that can accommodate the graphics formed based on the brush information is created with the size of the candidate rectangle and the image size, and then the brush information is drawn on the candidate image. When drawing the brush information, a fixed color of black (#000000) and a brush thickness of 5 pixels are used for drawing, and the candidate image Bitmap after drawing the brush information is used as the image to be processed.
[0064] S20: Determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed.
[0065] Specifically, the candidate graphic categories include shape categories, and the candidate graphic categories are used to reflect the basic categories of the graphics in the image to be processed. The candidate graphic categories can be determined by a trained category recognition model, wherein the category recognition model can adopt a deep learning network model. After determining that the image to be processed is obtained, the image size of the image to be processed can be scaled to a preset image size, and then the scaled image to be processed is input into the trained category recognition model, and the subsequent graphic category corresponding to the image to be processed is output through the category recognition model. The image to be processed only carries the graphics formed based on the brush information, thereby obtaining the candidate graphic category of the graphics formed based on the brush information. In addition, the preset image size is equal to the image size of the input item of the type recognition model, for example, the preset image size is 224*224, etc.
[0066] In an implementation of this embodiment, determining the candidate graphics corresponding to the brush information based on the image to be processed specifically includes:
[0067] Convert the pattern to be processed into a grayscale image through OpenCV;
[0068] A convex hull point set corresponding to the stroke information is determined based on the grayscale image, and a candidate graph is determined based on the convex hull point set.
[0069] Specifically, the background in the image to be processed is white and the graphics are black, so that the image to be processed can be converted into a grayscale image through the interface of OpenCV. After obtaining the grayscale image, the convex hull point set corresponding to the stroke information can be determined based on the grayscale image, wherein the process of determining the convex hull point set can be: firstly, the grayscale image is subjected to line segment endpoint statistics to obtain an endpoint set; then, a candidate convex hull point set is selected from the endpoint set, and finally, the candidate convex hull point set is filtered to obtain a convex hull point set, wherein the endpoint set can be obtained by detecting the image to be processed through the LSD function, the candidate convex hull point set can be extracted from the endpoint set through the convexHull function, and the convex hull point set can be obtained by using the approxPolyDP function to perform operations on the candidate convex hull point set.
[0070] Further, after obtaining the convex hull point set, a polygon srcPath is drawn based on each point in the convex hull point set to obtain a candidate shape, wherein the polygon can be drawn by Path, that is, the convex hull point set is imported into Path, and the polygon is generated by Path.
[0071] S30, extracting a bounding rectangle of the candidate graphic, and determining a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic.
[0072] Specifically, the bounding rectangle is the bounding matrix of the candidate graphic when it is rotated, that is, after obtaining the candidate graphic, the bounding rectangle srcBounds of the candidate graphic is extracted, so as to determine the tilt parameter based on the bounding rectangle srcBounds and the candidate graphic. The tilt parameter is used to reflect the degree of inclination of the target graphic corresponding to the brush information relative to the preset direction, and the tilt parameter can be used as a basis for determining the target graphic category of the target graphic corresponding to the brush information, wherein the preset direction is pre-set, for example, the horizontal direction or the vertical direction. In a specific implementation of this embodiment, the preset direction is the horizontal direction.
[0073] In an implementation of this embodiment, determining the tilt parameter corresponding to the brush information based on the circumscribed rectangle and the candidate graphic specifically includes:
[0074] Obtaining the rectangular center of the circumscribed rectangle, and rotating the candidate graphic in a preset direction within a preset angle range with the rectangular center as the rotation center;
[0075] Obtain the reference circumscribed rectangle of the candidate figure corresponding to each rotation angle during the rotation process, and record the circumscribed rectangle with the smallest area and the rotation angle corresponding to the circumscribed rectangle with the smallest area;
[0076] Based on the circumscribed rectangle with the smallest area and the rotation angle, a tilt parameter corresponding to the brush information is determined.
[0077] Specifically, after obtaining the reference circumscribed rectangle srcBounds, obtain the rectangular center midPoint of the reference circumscribed rectangle, and then use the rectangular center midPoint as the rotation center to train the candidate graphic srcPath within a preset range in a preset direction, wherein the preset range and preset direction are both preset, and the preset range is used to limit the rotation range of the candidate graphic, and the preset direction is used to limit the rotation direction of the candidate graphic. In a specific implementation of this embodiment, the preset range can be 0 degrees to 90 degrees, and the preset direction can be clockwise, that is, the candidate graphic is rotated in a clockwise direction within 0 degrees to 90 degrees. Of course, in actual applications, the preset range and preset direction can be set according to actual needs, for example, the preset range is -90 degrees to 0 degrees, and the preset direction is counterclockwise, etc.
[0078] Furthermore, in the process of rotating the candidate graphics in a preset direction within a preset range, the reference circumscribed rectangle of the candidate graphics srcPath corresponding to each rotation angle is calculated respectively, and the reference circumscribed rectangle minBounds with the smallest area and the rotation angle minDegree corresponding to the reference circumscribed rectangle minBounds with the smallest area are selected to obtain the tilt parameter. In addition, when rotating the candidate graphics, the minimum unit of rotation is 1 degree. For example, when the preset range is -90 degrees to 0 degrees and the preset direction is counterclockwise, when the polygon srcPath is rotated clockwise from 0 to 90 degrees, the candidate graphics srcPath is rotated clockwise with a step size of 1 degree each time, and the starting angle of the rotation is 0 degrees and the ending angle is 90 degrees.
[0079] S30: Determine a target graphic category of the target graphic based on the candidate graphic categories and the tilt parameter.
[0080] Specifically, the candidate graphic categories include circle and rectangle, the target graphic category includes shape category and tilt angle, wherein the shape category includes rectangle, circle and ellipse. There is a corresponding relationship between the candidate graphic category and the target graphic category, the circle category and the ellipse category in the target graphic category are determined based on the circle category in the candidate graphic category, and the rectangle category in the target graphic category is determined based on the rectangle category in the candidate graphic category.
[0081] In an implementation of this embodiment, when the candidate graphic category is a rectangle category, the shape category in the target graphic category is a rectangle category, the tilt angle in the target graphic category is determined based on a tilt parameter, and when the candidate graphic category is a rectangle category, the tilt parameter includes a rotation angle. Based on this, Figure 2 As shown, when the candidate graphic category includes a rectangle category, the tilt parameter includes a rotation angle; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes:
[0082] If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, a rectangle is used as a shape category in the target graphic category of the target graphic, and zero degree is used as a tilt angle in the target graphic category of the target graphic;
[0083] If the rotation angle is less than the first angle threshold and greater than the second angle threshold, the rectangle is used as the shape category in the target graphic category of the target graphic, and the rotation angle is used as the tilt angle in the target graphic category of the target graphic.
[0084] Specifically, the first angle threshold and the second angle threshold are both pre-set and are used as a basis for measuring whether the target graphic is in a tilted state, wherein when the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, it means that the target graphic is not in a tilted state, then a rectangle is used as a shape category in a target graphic category of the target graphic, and zero degrees is used as a tilt angle in a target graphic category of the target graphic; otherwise, the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, indicating that the target graphic is in a tilted state, then the rotation angle is used as a tilt angle in a target graphic category of the target graphic.
[0085] In one implementation of this embodiment, the first angle threshold may be 75°, and the second angle threshold may be 15°, that is, when the rotation angle is within the range of 0-15 degrees or 75-90 degrees, the target figure is determined to be tilted. At this time, a rectangle is drawn in combination with the circumscribed rectangle srcBounds of the candidate figure and the brush color and thickness currently selected by the drawing software to obtain the "recognition result pattern - rectangle; when the rotation angle is within the range of 16-74 degrees, the target figure is considered to be a "tilted rectangle", and the circumscribed rectangle minBounds of the minimum area is rotated counterclockwise by the rotation angle minDegree (or clockwise by 360-minDegree) to obtain a "candidate tilted rectangle", and a quadrilateral is drawn with the "candidate tilted rectangle" and the brush color and thickness currently selected by the drawing software to obtain the "recognition result pattern - tilted rectangle".
[0086] In an implementation of this embodiment, when the candidate graphic category is a circular category, the shape category in the target graphic category is a circular category or an elliptical category, and the tilt angle in the target graphic category and the circular category or the elliptical category can be determined based on a tilt parameter, wherein when the candidate graphic category is a circular category, the tilt parameter includes a rotation angle and a ratio of a short side to a long side of a circumscribed rectangle of a minimum area. Based on this, if Figure 2 As shown, when the candidate graphic category includes a circular category, the tilt parameter includes a rotation angle and a ratio of a short side to a long side of a circumscribed rectangle of a minimum area; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes:
[0087] If the ratio value is greater than a preset ratio threshold, a circle is used as a shape category in a target graphic category of the target graphic, and zero degree is used as an inclination angle in a target graphic category of the target graphic;
[0088] If the ratio value is less than or equal to a preset ratio threshold, obtaining a rotation angle of the circumscribed rectangle relative to the reference circumscribed rectangle;
[0089] If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, an ellipse is used as the shape category in the target graphic category of the target graphic, and zero degree is used as the tilt angle in the target graphic category of the target graphic;
[0090] If the rotation angle is less than the first angle threshold and greater than the second angle threshold, the ellipse is used as the shape category in the target graphic category of the target graphic, and the rotation angle is used as the tilt angle in the target graphic category of the target graphic.
[0091] Specifically, the preset ratio threshold is used to determine whether the shape category of the target graphic is a circular category or an elliptical category, wherein when the ratio value is greater than the preset ratio threshold, the shape category is a circular category, and vice versa, when the ratio value is less than or equal to the preset ratio threshold, the shape category is an elliptical category. In addition, since when the shape category is a circular category, the target graphic does not have a tilted state, when the candidate graphic category is a circular category, the shape category of the target graphic is first determined based on the ratio value, and then the tilt angle of the target graphic is determined based on the rotation angle. In a specific implementation of this embodiment, the preset ratio threshold can be 0.9. Of course, in other implementations, the preset ratio threshold can be set according to actual needs, for example, 0.95, 0.92, etc. In addition, the first angle threshold and the second angle threshold are the same as the candidate graphic category being a rectangular category, and will not be repeated here. For details, please refer to the description of the candidate graphic category being a rectangular category.
[0092] Furthermore, when a circle is used as a shape category in the target graphic category of the target graphic and zero degrees is used as an inclination angle in the target graphic category of the target graphic, the rectangular center of the circumscribed rectangle of the candidate graphic can be selected, and the center of the rectangle is used as the center of the circle and the long side of the circumscribed rectangle is used as the diameter of the circle to obtain a candidate circle, and then a circle is drawn using the "candidate circle" and the brush color and thickness currently selected by the drawing software to obtain the "recognition result pattern - circle". When an ellipse is used as a shape category in the target graphic category of the target graphic, and zero degrees is used as an inclination angle in the target graphic category of the target graphic, the maximum inscribed ellipse of the circumscribed rectangle of the candidate graphic is determined to obtain a candidate ellipse, and then an ellipse is drawn using the "candidate ellipse" and the brush color and thickness currently selected by the drawing software to obtain an "identification result pattern - ellipse." When an ellipse is used as a shape category in the target graphic category of the target graphic, and the rotation angle is used as an inclination angle in the target graphic category of the target graphic, the maximum inscribed ellipse of the circumscribed rectangle with the minimum area is obtained, and then the maximum inscribed ellipse is rotated counterclockwise by the rotation angle or clockwise by 360-the rotation angle to obtain a candidate inclined ellipse, and an ellipse is drawn using the "candidate inclined ellipse" and the brush color and thickness currently selected by the drawing software to obtain an "identification result pattern - inclined ellipse."
[0093] In summary, the present embodiment provides a method for graphic recognition, the method comprising obtaining brush information for drawing a target graphic, and determining an image to be processed based on the brush information; determining a candidate graphic category corresponding to the image to be processed, and determining a candidate graphic corresponding to the brush information based on the image to be processed; obtaining a bounding rectangle of the candidate graphic, and determining a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic; and determining a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter. The present application first extracts the candidate graphic category of the target graphic through manual identification and determines its corresponding bounding matrix based on stroke information, and finally determines the shape category and tilt angle corresponding to the target graphic based on the bounding rectangle and the candidate graphic category. In this way, not only the shape category of the target graphic can be identified, but also its corresponding tilt angle can be obtained, so that a graphic with a tilt angle can be drawn when the target graphic is subsequently drawn, thereby improving the drawing accuracy of the target graphic.
[0094] Based on the above-mentioned graphic recognition method, this embodiment provides a graphic recognition device, such as Figure 4 As shown, the graphic recognition device comprises:
[0095] An acquisition module 100 is used to acquire brush information used to draw a target graphic, and determine an image to be processed based on the brush information, wherein the image to be processed includes the target graphic;
[0096] A first determination module 200 is used to determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed;
[0097] An extraction module 300, configured to extract a bounding rectangle of the candidate graphic, and determine a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic;
[0098] The second determination module 400 is configured to determine a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter, wherein the target graphic category includes a shape category and a tilt angle.
[0099] Based on the above-mentioned graphic recognition method, this embodiment provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the steps in the graphic recognition method as described in the above-mentioned embodiment.
[0100] Based on the above-mentioned graphic recognition method, the present application also provides a terminal device, such as Figure 5 As shown, it includes at least one processor (processor) 20; display screen 21; and memory (memory) 22, and may also include a communications interface (Communications Interface) 23 and a bus 24. Among them, the processor 20, the display screen 21, the memory 22 and the communication interface 23 can communicate with each other through the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setting mode. The communication interface 23 can transmit information. The processor 20 can call the logic instructions in the memory 22 to execute the method in the above embodiment.
[0101] In addition, the logic instructions in the memory 22 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0102] The memory 22 is a computer-readable storage medium that can be configured to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the embodiments of the present disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions or modules stored in the memory 22, that is, implementing the methods in the above embodiments.
[0103] The memory 22 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 22 may include a high-speed random access memory and may also include a non-volatile memory. For example, a variety of media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, may also be a transient storage medium.
[0104] In addition, the specific process of loading and executing the multiple instruction processors in the above-mentioned storage medium and the terminal device has been described in detail in the above-mentioned method, and will not be described one by one here.
[0105] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A pattern recognition method, characterized in that: The method comprises: Acquire brush information for drawing a target graphic, and determine an image to be processed based on the brush information, wherein the image to be processed includes the target graphic; Determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed; Extracting a bounding rectangle of the candidate figure, and determining a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate figure; Determine a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter, wherein the target graphic category includes a shape category and a tilt angle; The step of determining the tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic specifically includes: Obtaining the rectangular center of the circumscribed rectangle, and rotating the candidate graphic in a preset direction within a preset angle range with the rectangular center as the rotation center; Obtain the reference circumscribed rectangle of the candidate figure corresponding to each rotation angle during the rotation process, and record the circumscribed rectangle with the smallest area and the rotation angle corresponding to the circumscribed rectangle with the smallest area; Determining a tilt parameter corresponding to the brush information based on the circumscribed rectangle with the smallest area and the rotation angle; The candidate graphic category includes a rectangle category, and the tilt parameter includes a rotation angle; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes: If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, a rectangle is used as a shape category in the target graphic category of the target graphic, and zero degree is used as a tilt angle in the target graphic category of the target graphic; If the rotation angle is less than the first angle threshold and greater than the second angle threshold, the rectangle is used as the shape category in the target graphic category of the target graphic, and the rotation angle is used as the tilt angle in the target graphic category of the target graphic; The candidate graphic category includes a circular category, the tilt parameter includes a rotation angle and a ratio of a short side to a long side of a circumscribed rectangle of a minimum area; and determining the target graphic category of the target graphic based on the candidate graphic category and the tilt parameter specifically includes: If the ratio value is greater than a preset ratio threshold, a circle is used as a shape category in a target graphic category of the target graphic, and zero degree is used as an inclination angle in a target graphic category of the target graphic; If the ratio value is less than or equal to a preset ratio threshold, obtaining a rotation angle of the circumscribed rectangle relative to the reference circumscribed rectangle; If the rotation angle is greater than or equal to the first angle threshold, or less than or equal to the second angle threshold, an ellipse is used as the shape category in the target graphic category of the target graphic, and zero degree is used as the tilt angle in the target graphic category of the target graphic; If the rotation angle is less than the first angle threshold and greater than the second angle threshold, taking the ellipse as the shape category in the target graphic category of the target graphic, and taking the rotation angle as the tilt angle in the target graphic category of the target graphic; The first angle threshold and the second angle threshold are both preset; The step of determining the candidate graphics corresponding to the brush information based on the image to be processed specifically includes: Convert the image to be processed into a grayscale image using OpenCV; A convex hull point set corresponding to the brush information is determined based on the grayscale image, and a candidate graphic is determined based on the convex hull point set.
2. The pattern recognition method according to claim 1, characterized in that: The specific steps of obtaining the brush information used to draw the target graphics are as follows: A control instruction for starting to draw a graphic is received, and brush information formed based on the control instruction is recorded to obtain brush information for drawing a target graphic.
3. The pattern recognition method according to claim 1, characterized in that: Determining the image to be processed based on the brush information specifically includes: Determine a plurality of target positions corresponding to the target graphic based on the brush information, and draw candidate rectangles based on the target positions; A candidate image is created with the candidate rectangle as the image edge, and a candidate graphic is drawn in the candidate image based on the brush information to obtain an image to be processed, wherein the background of the image to be processed is white and the candidate graphic is black.
4. A pattern recognition device, characterized in that: The method for pattern recognition according to any one of claims 1 to 3 is adopted, wherein the pattern recognition device comprises: An acquisition module, used for acquiring brush information used for drawing a target graphic, and determining an image to be processed based on the brush information, wherein the image to be processed includes the target graphic; A first determination module, configured to determine a candidate graphic category corresponding to the image to be processed, and determine a candidate graphic corresponding to the brush information based on the image to be processed; An extraction module, configured to extract a bounding rectangle of the candidate graphic, and determine a tilt parameter corresponding to the brush information based on the bounding rectangle and the candidate graphic; The second determining module is configured to determine a target graphic category of the target graphic based on the candidate graphic category and the tilt parameter, wherein the target graphic category includes a shape category and a tilt angle.
5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps in the graphic recognition method according to any one of claims 1 to 3.
6. A terminal device, characterized in that: include: A processor, a memory and a communication bus; the memory stores a computer-readable program that can be executed by the processor; The communication bus realizes the connection and communication between the processor and the memory; When the processor executes the computer-readable program, the steps in the graphic recognition method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Target size measurement method and system based on deep learning
CN110246124A
Graph recognition method, intelligent terminal and storage medium
CN112434632A