Method and system for extracting copybook checks
By separating and merging image segments, combining clustering and LP model optimization, copybook grids are automatically extracted, which solves the problem of AI technology's dependence on high-quality training data and inaccurate recognition of complex formats, and achieves efficient and accurate copybook grid generation.
Patent Information
- Application Number
- CN202510780936.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-07-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing AI technologies rely on a large amount of high-quality training data in copybook grid extraction and face the challenge of inaccurate identification of complex copybook formats.
By obtaining the line segment information of the original image, separating horizontal and vertical lines, combining line segments, determining intersection data, performing clustering and clustering analysis, combining LP model optimization information, automatically extracting copybook grids that meet the needs.
It improves the efficiency and accuracy of copybook square extraction, reduces the complexity and error rate of manual operations, and adapts to different scenarios and personalized needs.
Smart Images

Figure CN120340056A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of image processing technologies, and in particular, to a method and system for extracting grid lines from copybooks. Background Art
[0002] In the digital classroom of modern calligraphy teaching, a common challenge is to automatically extract the grid lines from copybook images for further analysis and processing.
[0003] With the rapid development of AI technology, the process of extracting grid lines from copybooks has undergone an innovation. By training a deep learning model, an AI system can intelligently identify and analyze various copybook images, automatically adapting to different formats and personalized requirements, without the need to specifically design special-format copybooks or re-develop image processing algorithms.
[0004] Although AI technology shows high efficiency and flexibility in extracting grid lines from copybooks, it relies on a large amount of high-quality training data and may face challenges in accurately identifying complex copybook formats. Summary of the Invention
[0005] To address the deficiencies of the prior art, the present disclosure provides a method and system for extracting grid lines from copybooks. The present disclosure solves the technical problems that the existing AI technology shows high efficiency and flexibility in extracting grid lines from copybooks, but it relies on a large amount of high-quality training data and may face challenges in accurately identifying complex copybook formats.
[0006] According to a first aspect of the present disclosure, there is provided a method for extracting grid lines from copybooks, including: obtaining an original image, extracting line segment information of each line segment of the original image, and dividing each line segment of the original image into each horizontal line and each vertical line according to the line segment information; merging each vertical line according to a preset merging criterion to obtain each target long vertical line, and merging each horizontal line according to a preset merging criterion to obtain each target long horizontal line; determining intersection data of each target long vertical line and each target long horizontal line, determining each candidate grid according to the intersection data, performing clustering and cluster analysis on each candidate grid, and determining the grid cluster and cluster result of each candidate grid; if demand information sent by a control center is received, inputting the demand information and the cluster result into a preset LP model to obtain grid optimization information of each candidate grid; performing grid filling on the original image according to the grid optimization information, and intercepting a copybook grid image from the original image according to the grid optimization information.
[0007] According to a second aspect of the present disclosure, there is provided a grid extraction system for copybooks, which is used to execute the method described in the first aspect, including: a line segment extraction module, configured to obtain an original image, extract line segment information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line segment information; A line segment merging module, configured to merge each vertical line according to a preset merging criterion to obtain each target long vertical line, and merge each horizontal line according to a preset merging criterion to obtain each target long horizontal line; An analysis module, configured to determine intersection data of each target long vertical line and each target long horizontal line, determine each candidate grid according to the intersection data, perform clustering and cluster analysis on each candidate grid, and determine the grid clusters and clustering results of each candidate grid; A grid optimization information determination module, configured to, if receiving requirement information sent by a control center, input the requirement information and the clustering result into a preset LP model to obtain grid optimization information of each candidate grid; A grid filling module, configured to perform grid filling on the original image according to the grid optimization information, and intercept a copybook grid picture in the original image according to the grid optimization information.
[0008] According to a third aspect of the present disclosure, there is provided an electronic device, which includes: a memory and a processor, where a computer program is stored on the memory, and when the processor executes the program, it implements the method as described above.
[0009] In the copybook grid extraction method and system provided as above, in the embodiments of the present disclosure, by combining line segment detection, merging, cluster analysis, and an optimization model, it is possible to automatically and efficiently generate accurate and demand-compliant copybook grids, adapting to different scenarios and personalized requirements. It not only improves work efficiency and accuracy, but also reduces the complexity and error rate of manual operations, thus providing a more efficient and flexible copybook generation solution for users. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present disclosure. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0011] Figure 1 FIG. shows a schematic flowchart of a copybook grid extraction method according to an embodiment of the present disclosure; Figure 2 FIG. shows a schematic flowchart of a copybook grid extraction method according to an embodiment of the present disclosure; Figure 3 The figure shows a schematic block diagram of a copybook grid extraction system according to an embodiment of the present disclosure; Figure 4 The figure shows a block diagram of an exemplary electronic device according to an embodiment of the present disclosure. Detailed implementation manners
[0012] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that: unless otherwise specifically stated, the relative arrangements of components and steps, numerical expressions, and values set forth in these embodiments do not limit the scope of the present disclosure.
[0013] Those skilled in the art can understand that terms such as "first" and "second" in the embodiments of the present disclosure are only used to distinguish different steps, devices, or modules, etc., and neither represent any specific technical meaning nor indicate an inevitable logical order between them. It should also be understood that in the embodiments of the present disclosure, "a plurality of" may refer to two or more, and "at least one" may refer to one, two, or more. It should also be understood that for any component, data, or structure mentioned in the embodiments of the present disclosure, without clear definition or contrary indication in the context, it can generally be understood as one or more. In addition, the term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in the present disclosure generally represents an "or" relationship between the associated objects before and after. It should also be understood that the present disclosure emphasizes the differences between various embodiments, and the same or similar parts can be referred to each other. For the sake of brevity, they will not be described one by one.
[0014] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship. The following description of at least one exemplary embodiment is actually only illustrative and in no way limits the present disclosure and its application or use. Technologies, methods, and devices known to those of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and devices should be regarded as part of the specification. It should be noted that: similar reference numerals and letters denote similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further discussed in subsequent drawings.
[0015] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without creative efforts shall fall within the scope of protection of the present disclosure.
[0016] Figure 1 This is a schematic flowchart of a method for extracting grid lines of a copybook provided by an embodiment of the present disclosure. As Figure 1 shown, the method includes: S101, obtain an original image, extract line segment information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line segment information.
[0017] The original image can be image data obtained from an actual environment without any processing, usually a digital image file (such as in JPEG, PNG, TIFF, etc. formats). This image contains all the information to be analyzed, which can be a handwritten copybook, etc. The original image can contain various background information, objects, and lines.
[0018] A line segment can refer to a continuous straight-line segment in an image with a clear starting point and ending point. It is extracted from the image through line segment detection (such as methods like Canny edge detection, Hough transform, etc.). These line segments are components of all straight-line shapes in the image and can be vertical, horizontal, or oblique line segments.
[0019] The line segment information can be the geometric features of each line segment, such as the position, direction, length, starting point coordinates, ending point coordinates, angle, color (if it involves a color image), etc. This information can help understand the distribution of line segments in the image and their positions in space.
[0020] A vertical line can refer to a line segment in the image that meets the requirements of a "vertically oriented line segment". A vertical line usually refers to a line segment that forms an angle close to 90° with the horizontal line (the ground or the horizontal direction of the image) and is usually used to indicate a vertical structure or framework.
[0021] A horizontal line can refer to a line segment in the image that meets the requirements of a "horizontally oriented line segment". A horizontal line usually forms an angle close to 90° with the vertical line or is arranged in a horizontal or nearly horizontal direction. A horizontal line is usually used to represent a horizontal structure or boundary.
[0022] The original image can be loaded, which can be any image containing line segments. Convert the original image to a grayscale image. The grayscale image can reduce the impact of color on image processing, making subsequent image processing more efficient. Then, perform binarization on the grayscale image to transform the image into a black-and-white image. Binarization can highlight the main structures in the image, especially lines and boundaries, making subsequent line segment detection more accurate. Then, select an appropriate line segment detector to extract the line segments in the image. Common line segment detectors include: Hough transform: The Hough transform is a classic algorithm for detecting straight lines in an image. It can extract straight lines from a binarized image and returns the polar coordinate representation of each straight line (such as the angle and distance of the straight line).
[0023] Canny edge detection + Hough transform: Canny edge detection is used to detect edges in the image, and then line segments are extracted from these edge points through the Hough transform.
[0024] Adaptive line segment detector: LSD is an efficient algorithm for line segment detection, suitable for various structured images, and can extract real line segments from the image, not just straight lines.
[0025] The line segment information extracted by these detectors includes: Starting point coordinates (x1, y1): The starting position of the line segment. End point coordinates (x2, y2): The ending position of the line segment. Direction / angle of the line segment: Calculate the angle between the line segment and the horizontal or vertical line. Length of the line segment: The actual length of the line segment, which can be calculated using the Euclidean distance formula. During the screening process, it is necessary to define which line segments meet the requirements of the target vertical line and the target horizontal line. The following criteria can be used for definition: Target vertical line: Usually a line segment close to the vertical direction (i.e., the direction angle of the line segment is close to 90 degrees or close to 270 degrees). Target horizontal line: Usually a line segment close to the horizontal direction (i.e., the direction angle of the line segment is close to 0 degrees or close to 180 degrees). The direction of the line segment can be understood as the angle of the line segment relative to the horizontal direction. Direction definition: The calculated angle represents the direction from the horizontal direction (X-axis), rotating clockwise or counterclockwise to this line segment. Once the direction angle of each line segment is calculated, it can be determined whether the line segment is a horizontal line or a vertical line based on this angle. Horizontal line screening: For the direction of the line segment, if the angle is close to 0 degrees or 180 degrees within a certain error range (such as a small threshold), then this line segment is considered a horizontal line. Vertical line screening: For the direction of the line segment, if the angle is close to 90 degrees or 270 degrees and within a certain error range (such as a small threshold), then this line segment is considered a vertical line.
[0026] Based on the above technical solutions, optionally, extracting the line segment information of each line segment of the original image, and classifying each line segment of the original image into each horizontal line and each vertical line includes: Determine the vertical line regions and horizontal line regions of the original image according to the Morphology operator of the OpenCV library, and set the sizes of the vertical line regions and horizontal line regions according to the MORPH_RECT kernel; Determine the line segment information of the vertical line regions and horizontal line regions according to the findContours method, and convert the vertical line regions and horizontal line regions into vertical lines and horizontal lines according to the line segment information.
[0027] In this solution, OpenCV is an open-source computer vision library that contains a large number of tools and algorithms for image processing, computer vision, machine learning, and other fields. OpenCV provides rich function interfaces to help developers perform tasks such as image and video processing, object recognition, feature extraction, and edge detection.
[0028] Process through the MORPH_RECT rectangular kernel and select an appropriate structural element size to highlight vertical or horizontal lines. Vertical line regions: Select an appropriate structural element for operation to make the vertical line parts prominent or connected. Horizontal line regions: Similarly, select an appropriate structural element to process the horizontal line parts. In the morphed image, we can use the findContours method to extract all the contour information. Line segment information of vertical line regions: Using the findContours method on the vertical line regions, we can obtain the contour information of each connected region in the vertical direction. Each contour represents a vertical line segment and contains the edge coordinates of the vertical line segment. Line segment information of horizontal line regions: Similarly, using the findContours method on the horizontal line regions, we can obtain the contour information of each connected region in the horizontal direction. Once the contour information of the vertical line regions and horizontal line regions is obtained through the findContours method, the next task is to convert them into distinct vertical lines and horizontal lines according to this contour information. Here, the main work is to determine the main direction of these contours and fit them into vertical lines or horizontal lines. Vertical line conversion: For the vertical line regions, by analyzing the main direction of the contours, it can be judged that these contours mainly extend in the vertical direction. Therefore, these contours will be converted into vertical lines, and the contours can be fitted into line segments in the vertical direction. Similarly, the horizontal line conversion can be completed by fitting these contours into line segments in the horizontal direction.
[0029] In this solution, the vertical and horizontal line regions are accurately extracted through morphological operations, and the line segment information is extracted using the findContours method, and finally converted into usable vertical and horizontal lines, greatly improving the accuracy, efficiency, and flexibility of image analysis. This provides clearer and more structured data for subsequent image processing tasks.
[0030] S102, merge each vertical line according to a preset merging criterion to obtain each target long vertical line, and, merge each horizontal line according to the preset merging criterion to obtain each target long horizontal line.
[0031] The preset merging criterion can be a combination of the following conditions: Endpoint distance threshold: The endpoint distance between two line segments is less than a preset distance (such as 5 pixels). Angle difference threshold: The angle difference between two line segments is less than a preset threshold (such as 10 degrees). Length similarity: The length difference between two line segments should be within an acceptable range (such as within 10%). Endpoint alignment: The endpoints of the two line segments are aligned or the overlapping part is less than the preset maximum distance. Continuity: The merged line segment should be continuous and smooth without unnecessary breaks.
[0032] The target long vertical line can refer to the long vertical line formed by merging multiple adjacent or close vertical line segments. Through merging, the total length of these vertical lines becomes longer, which can cover multiple vertical regions in the image and form a continuous vertical region, usually used for structured division or meshing in the image.
[0033] The target long horizontal line is similar to the target long vertical line. It can be a long horizontal line formed by merging multiple adjacent or close horizontal line segments. The merged horizontal line can cover multiple horizontal regions and form a continuous horizontal line, which is applicable to structural division, grid filling, etc. in the image.
[0034] For all vertical lines, they can be merged according to the preset merging criterion to obtain the target long vertical line: Determine the relative positions of every two vertical lines: For each pair of vertical lines, check their endpoint distances (i.e., the distance between the left and right endpoints of the vertical lines). If the endpoint distance between two vertical lines is less than a certain preset threshold (such as 5 pixels), it is considered that they are close enough in space to be merged. Direction consistency judgment: Calculate the direction angle of each vertical line to ensure that the direction angles of these two line segments are similar (i.e., the angle difference is less than the preset threshold, such as 5 degrees). If the angle difference between the two vertical lines is within the allowable range, they can be merged into a longer vertical line. Merging operation: If the spatial proximity and direction consistency criteria are met, merge the two vertical lines. The merging method can be to take the leftmost and rightmost endpoints of the two vertical lines to form a new vertical line segment. After merging, update the endpoint information of these two vertical lines to form a new "target long vertical line". Continue to merge other vertical lines: Repeat the above steps to merge all vertical lines. After each merge, update the data of the merged vertical lines until no more vertical lines can be merged. Merging criterion: Spatial proximity: The distance between the endpoints of the vertical line is less than 5 pixels. Direction consistency: The angle difference between the two vertical lines is less than 5 degrees. Merging operation: The merged vertical line is composed of the leftmost and rightmost endpoints of the two vertical lines.
[0035] For all horizontal lines, merge them according to the preset merging criteria to obtain target long horizontal lines: Determine the relative positions of every two horizontal lines: For each pair of horizontal lines, check the distance between their endpoints (i.e., the distance between the upper and lower endpoints of the horizontal line). If the distance between the endpoints of two horizontal lines is less than a certain preset threshold (e.g., 5 pixels), it is considered that they are close enough in space to be merged. Direction consistency judgment: Calculate the direction angle of each horizontal line to ensure that the direction angles of these two horizontal lines are similar (i.e., the angle difference is less than the preset threshold, e.g., 5 degrees). If the angle difference between the two horizontal lines is within the allowable range, they can be merged into a longer horizontal line. Merging operation: If the spatial proximity and direction consistency criteria are met, merge the two horizontal lines. The merging method can be to take the uppermost and lowermost endpoints of the two horizontal lines to form a new horizontal line segment. After merging, update the endpoint information of these two horizontal lines to form a new "target long horizontal line". Continue to merge other horizontal lines: Repeat the above steps to merge all horizontal lines. After each merge, update the data of the merged horizontal lines until no more horizontal lines can be merged. Merging criteria: Spatial proximity: The distance between the endpoints of the horizontal line is less than 5 pixels. Direction consistency: The difference in the direction angles of the two horizontal lines is less than 5 degrees. Merging operation: The merged horizontal line is composed of the uppermost and lowermost endpoints of the two horizontal lines.
[0036] After all the horizontal and vertical lines are merged, multiple target long vertical lines and target long horizontal lines are obtained.
[0037] S103, determine the intersection data of each target long vertical line and each target long horizontal line, determine each candidate square according to the intersection data, cluster and perform cluster analysis on each candidate square, and determine the square clusters and cluster results of each candidate square.
[0038] The intersection data can refer to the positions of all intersections calculated between the target long vertical line and the target long horizontal line. The intersections represent the places where the vertical and horizontal lines meet, and they are the potential corners of the squares.
[0039] The candidate squares can refer to the preliminary, possible rectangular or square areas formed by the intersection data. These squares are the grid areas formed by the intersections, and each square is determined by four intersections.
[0040] The square clusters can be groups obtained by clustering a group of candidate squares that are close in space. Each square cluster contains multiple candidate squares, and these squares are relatively close and may be in the same large grid.
[0041] The cluster results can be obtained by analyzing the spatial positions of the candidate squares through clustering algorithms (such as K-means or DBSCAN), dividing them into several clusters, and each cluster represents a region, which may be a set of squares belonging to the same category.
[0042] The intersection of each vertical line and each horizontal line can be determined by the intersection of line segment equations. Specifically, for a vertical line x = x1 and a horizontal line y = y1, their intersection point is (x1, y1). By combining each vertical line and each horizontal line, calculating the coordinates of all intersection points, an intersection point set is obtained. Combining the intersection points, every two adjacent vertical and horizontal line intersection points form a rectangular area, which is a candidate grid. The "connectivity" of the grid can be calculated based on the center point of the grid. The Euclidean distance between the center points of every two candidate grids can be calculated. Select a suitable clustering algorithm (such as DBSCAN or K-means) to cluster the candidate grids. DBSCAN: A density-based clustering method that can group grids with close distances into one group by setting a distance threshold. It is suitable for situations with noise and can automatically identify different grid clusters. K-means: Cluster the candidate grids into a fixed number of clusters, with each cluster consisting of similar grids. Using the selected clustering algorithm, divide the candidate grids into different clusters based on the distance (or other features) between the grids. Each cluster represents a group of grids with close positions, which may be a region in the image. Then, for each candidate grid, calculate its size (width and height). The size is usually the long side and the short side of the grid, and the width and height can be calculated from the intersection point coordinates. Use a clustering algorithm (such as K-means or hierarchical clustering) to cluster the candidate grids according to their sizes. Through clustering, grids with similar sizes can be grouped into the same category. K-means: Can group grids with similar sizes together, for example, group larger-sized grids into one category and smaller-sized grids into another category. Hierarchical clustering: By gradually merging or splitting grids, a hierarchical structure is formed, and different clustering levels of grids can be generated. After performing size clustering, multiple clusters are obtained, and each cluster contains grids with similar sizes. Based on the clustering and size clustering results, different types of grid clusters can be obtained. Each cluster represents a group of grid regions that are close in space and have similar size characteristics. Each grid cluster consists of multiple candidate grids, and these grids share similar spatial position and size characteristics. These grid clusters can be displayed through visualization tools or other analysis methods.
[0043] S104, if the demand information sent by the control center is received, input the demand information and the clustering result into a preset LP model to obtain the grid optimization information of each candidate grid.
[0044] The control center can refer to a system or platform for centralized management, scheduling, and control. In this context, the control center may be a monitoring system or service platform that is responsible for receiving demands from users or other systems and passing the demands to relevant modules or algorithms for processing. The responsibilities of the control center usually include data collection, instruction issuance, system status monitoring, etc.
[0045] Requirement information can refer to the requirements or instructions sent by the control center regarding tasks, resources, goals, or conditions, etc. Specifically, the requirement information can include the following: the location and size of the goal or requirement (such as grid position, grid size, etc.). Specific constraint conditions (such as maximum allowable error, resource utilization limit, etc.). Optimization goals (such as improving efficiency, reducing costs, achieving resource balance, etc.).
[0046] The requirement information can be transformed into a linear optimization problem, whose goal is to make: - Select as many grids as possible - There is no overlap between grids - The sizes of the grids are as consistent as possible - The grids in the same cluster are as evenly distributed as possible.
[0047] This linear optimization problem is expressed as: ; (1); (2); (3); (4); (5); (6); (7); (8); (9); (10); (11); Among them, (1) indicates whether a grid is selected or not; (2) indicates that at most one grid in the same overlap group can be selected; in (3), is the decision variable of the size cluster The number of grids included in this cluster is , indicating that the optimized solution can contain at most one size cluster, and grids that do not belong to this size cluster cannot be selected; (4) to (7) together constitute the row combination related constraint conditions, where (4) indicates that there can be at most one row combination for each size, indicates the row set under size , (5) and (6) together limit the row combination variables, indicates not belonging to size The set of rows, where (7) indicates that the selected squares do not exceed the size of the corresponding row combination and also do not exceed the maximum number of rows; similarly, (8) to (11) together constitute the constraint conditions related to column combinations.
[0048] The preset LP model can be a mathematical optimization model, usually used to solve optimization problems with linear relationships. In this problem, the preset LP model may be used to optimize the square layout, adjust the distribution of squares, or resource allocation, etc. The LP model consists of the following elements: Objective function: Usually the objective to be optimized, such as minimizing resource usage, maximizing the coverage area, minimizing the number of squares, etc. Constraint conditions: Describe the constraints of the problem, such as the size, position, contact requirements, minimum / maximum size of the squares, etc. Decision variables: Represent the variables that need to be adjusted during the optimization process, such as the size and position of each square.
[0049] The square optimization information can be the result calculated by inputting the requirement information and the clustering result into the preset LP model. It represents how to optimize the candidate squares based on the current requirements and objectives. These optimization information may include: The final position of the square: That is, the optimized position of the square, which may be the adjusted position or size. The size of the square: The optimal size of each square calculated by the optimization algorithm. Resource allocation: How to allocate resources in the optimized squares, which may involve energy, space, or computing power, etc. Constraint satisfaction: Whether all the constraint conditions (such as square size, contact requirements, etc.) are satisfied.
[0050] The requirement information of the control center can include the requirements for the square layout, size, position, constraint conditions, optimization objectives, etc. The content of the requirement information can include the size and position of the target area, optimization objectives (such as minimizing the occupied space, minimizing the time, improving resource utilization rate, etc.), various constraint conditions (such as square size limitations, boundary alignment requirements, connection requirements of adjacent squares, etc.). The requirement information is merged with the clustering result to form the input data required by the optimization model and is passed into the preset LP model. The goal of the preset LP model is to determine the optimal position, size, layout, etc. of each candidate square through linear optimization, so that the entire system meets the requirements of the control center. Once the requirement information and the clustering result are input into the preset LP model, the system will, according to the objective function and constraint conditions, solve the optimal solution through linear programming algorithms (such as the simplex method, interior point method, etc.). Solving objective: The optimization objective may be to minimize the area, minimize the layout change, maximize the square utilization rate, etc. Output result: The solving process will generate a set of optimal solutions, indicating the final position, size, direction, etc. of each candidate square. This optimization result is the square optimization information.
[0051] The preset LP model is a mathematical model defined by a linear programming formula. Its goal is to optimize the layout of grids and resource allocation by solving linear equations. The preset LP model usually includes the following: Objective function: Usually a quantity to be optimized (such as minimizing the total area, maximizing the space utilization rate, etc.).
[0052] Constraints: Define various conditions to be met during the optimization process, such as the size of the grids, distance limitations between grids, contact requirements, etc.
[0053] Decision variables: For example, the size, position, orientation of each grid, etc.
[0054] The form of the model can be expressed as: min / max f(x1, x2,..., xn), where f(x) is the objective function, representing the objective to be optimized (such as grid area, position, etc.); x1, x2,..., xn are decision variables, representing the attributes of each grid to be optimized; at the same time, the constraints will also be reflected in the model, such as: gi(x1, x2,..., xn) ≤ bi, i = 1, 2,..., m, where gi(x) is the constraint condition.
[0055] Usually, the LP model does not require training because it is a mathematical optimization problem and is directly solved through formulas. However, in some situations, the parameters of the LP model (such as the weights of the objective function, constraints, etc.) can be optimized through historical data or manual adjustment. These parameter adjustments can be carried out in the following situations: Historical data feedback: Using historical demand data and grid layout results to optimize the parameters of the model. Expert knowledge: Based on the experience of experts, adjusting the weights or other parameters of the objective function and constraints in the model.
[0056] S105, perform grid filling on the original image according to the grid optimization information, and intercept the copybook grid picture in the original image according to the grid optimization information.
[0057] The copybook grid picture can be extracted from the original image according to the grid optimization information, and is a grid area with a specific layout and size. The size, position, and other parameters of each grid will be adjusted according to the preset optimization information. In this way, each grid picture can be obtained, and usually each grid will contain the content for writing.
[0058] Based on the size and position of the grids, the positions of each grid can be drawn or marked on the original image. This step can be achieved by drawing rectangular frames on the original image to indicate each grid area, ensuring that each grid meets the preset size and layout requirements. Draw the grids on the original image according to the coordinates, sizes, and grid directions given in the grid optimization information. For example, for each grid, determine its upper-left corner coordinates, width, and height, and draw a rectangular frame. If the grid has a rotation angle, the rectangle needs to be rotated according to the angle. According to the position and size of the grids, extract the content of each grid from the original image. Interception area: Use the position and size in the grid optimization information to calculate the rectangular area of each grid in the original image. Then, extract the image content of these rectangular areas to obtain the grid pictures of the copybook. Save the image: Each intercepted grid image can be saved as an independent image file, or stitched together into an image containing all the grid pictures of the copybook as needed.
[0059] In the embodiment of the present application, obtain the original image, extract the line segment information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line segment information; merge each vertical line according to the preset merging standard to obtain each target long vertical line, and, merge each horizontal line according to the preset merging standard to obtain each target long horizontal line; determine the intersection data of each target long vertical line and each target long horizontal line, determine each candidate grid according to the intersection data, perform clustering and clustering analysis on each candidate grid, and determine the grid clusters and clustering results of each candidate grid; if receiving the demand information sent by the control center, input the demand information and the clustering result into the preset LP model to obtain the grid optimization information of each candidate grid; perform grid filling on the original image according to the grid optimization information, and, intercept the grid pictures of the copybook in the original image according to the grid optimization information. Through the above copybook grid extraction method, by combining line segment detection, merging, clustering analysis, and optimization model, it is possible to automatically and efficiently generate accurate and demand-compliant copybook grids, adapting to different scenarios and personalized needs. It not only improves work efficiency and accuracy but also reduces the complexity and error rate of manual operations, thus providing a more efficient and flexible copybook generation solution for users.
[0060] On the basis of the above technical solution, optionally, performing grid filling on the original image according to the grid optimization information includes: Generate a grid matrix according to the grid optimization information, determine the vacant area of the grid matrix, and perform grid filling on the original image according to the grid matrix and the vacant area.
[0061] In this solution, the grid matrix can be a two-dimensional grid structure formed by organizing all candidate grid information according to certain rules (such as position, size, arrangement). Each cell represents a grid, and the size and position of the grid are optimized according to the previous steps. This matrix presents an overall layout method, showing the position and arrangement of each grid in the original image.
[0062] First, according to the optimized information of the grids, all candidate grids are arranged into a two-dimensional matrix according to rules (such as row-column order). The size and position of each grid are determined based on the previous optimization and adjustment results. The grid matrix represents the specific layout of these grids on the image. By checking each position in the grid matrix, identify the areas that are not covered by the grids, and these areas are the vacant areas. The vacant areas can be found by calculating the boundaries of each grid and finding the gaps between these boundaries, or by comparing the size of the grid matrix with the original image to find the uncovered parts. According to the vacant areas, use a filling strategy to supplement these vacant areas with appropriate grids. Different methods can be adopted during filling: Direct filling: Directly fill the vacant areas with appropriate grids to ensure seamless connection. Adjust the size or shape of the grids: According to the specific situation of the vacant areas, it may be necessary to adjust the size or shape of the grids to perfectly fill the vacant areas. Rearrange the grid matrix: Rearrange the grid matrix according to the vacant areas to optimize the layout and position of the grids and avoid excessive gaps.
[0063] In this solution, by filling the vacant areas, the distribution of the grids in the original image becomes more uniform, avoiding information loss or duplication. After filling, the image content is better segmented and organized, making subsequent analysis (such as feature extraction, clustering analysis, etc.) more accurate and stable.
[0064] Figure 2 It is a schematic flowchart of a method for extracting grid characters provided for an embodiment of the present disclosure. As Figure 2 shown, the method includes: S201, obtain the original image, extract the line information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line information.
[0065] S202, merge each vertical line according to a preset merging criterion to obtain each target long vertical line, and, merge each horizontal line according to a preset merging criterion to obtain each target long horizontal line.
[0066] S203, determine the intersection data of each target long vertical line and each target long horizontal line, determine each candidate grid according to the intersection data, obtain the intersection relationship of each candidate grid, and determine the grid cluster of each candidate grid according to the intersection relationship.
[0067] The intersection relationship can refer to the spatial relationship between the four intersection points of a candidate grid (formed by the intersection of two pairs of vertical and horizontal lines), that is, the connectivity between two grids. Specifically, for any two grids, if they have a common vertex or their edges meet on the same line segment, the two grids are considered to intersect and are thus grouped into a cluster.
[0068] Each candidate grid is composed of the intersection points of two vertical lines and two horizontal lines. In the image, after selecting appropriate vertical and horizontal lines, their intersection will produce four intersection points, and these four intersection points together form a grid. For each pair of vertical and horizontal lines, calculate their intersection points to obtain the four corner points of the grid. The criterion for the intersection relationship: Two grids are considered to intersect when at least one of their intersection points (vertices) lies on the same vertical or horizontal line segment. For example, assume that a certain intersection point of two grids is respectively on the same vertical line or the same horizontal line, then these two grids intersect. In this way, the intersection relationship of vertical and horizontal lines can be used to determine whether the grids are connected or crossed. Then check the intersection points of all candidate grids one by one to determine whether each pair of grids shares an intersection point. The specific operation is: For each pair of grids, check whether their four intersection points (vertices) have the same coordinates. If they have the same coordinates, then they share an intersection point. If grid A and grid B have a common intersection point, then they intersect in space. Group the intersecting grids into a cluster according to the intersection relationship. If two grids intersect, they belong to the same cluster. If two grids do not intersect, they belong to different clusters. Clustering rule: The following strategy can be used for clustering: Based on intersection connectivity: All intersecting grids can be grouped through the connected components of a graph. If grid A and grid B share an intersection point, then they belong to the same cluster, and they can be grouped into the same cluster through the adjacency relationship of the graph. Specifically, a pair of vertical lines with a moderate distance can be found, and they are intersected with another pair of horizontal line segments with a moderate distance. Four intersection points obtain a grid; and so on, to obtain grids of different sizes; Group the grids obtained from the same relevant line segments into a cluster, that is, two grids can be grouped into a cluster as long as each has a vertex on the same line segment.
[0069] Based on the above technical solution, optionally, before obtaining the intersection relationship of each candidate grid and determining the grid clusters of each candidate grid according to the intersection relationship, the method further includes: Determine the overlapping candidate grid groups in each candidate grid, obtain the area information of each overlapping candidate grid in the overlapping candidate grid groups, and obtain the overlapping area information between each overlapping candidate grid in the overlapping candidate grid groups; Calculate the overlapping values of each overlapping candidate grid in the overlapping candidate grid groups according to a preset overlapping value calculation formula, area information, and overlapping area information, delete the overlapping candidate grid groups whose overlapping values exceed the preset overlapping degree threshold, and update each candidate grid; Correspondingly, obtain the intersection relationships of each candidate grid, and determine the grid clusters of each candidate grid according to the intersection relationships, including: Obtain the updated intersection relationships of each candidate grid, and determine the updated grid clusters of the updated candidate grids according to the intersection relationships; Correspondingly, obtain the size information of each candidate grid, and determine the clustering results of each candidate grid under each grid cluster according to the size information, including: Obtain the updated size information of each candidate grid, and determine the clustering results of each candidate grid under the updated grid cluster according to the size information.
[0070] In this solution, an overlapping candidate grid group may be that in the original image, there is a certain degree of spatial overlap between multiple candidate grids, and they cover each other to form a set. These grids may represent a specific area or target, but due to slight differences in size or positioning, they overlap with each other.
[0071] An overlapping candidate grid may refer to the partial or complete area overlap between different candidate grids in the image. The edges or areas of these grids overlap, which may indicate that they are trying to capture the same target or area.
[0072] The area information may be the physical area size of each candidate grid, usually in pixels. For each candidate grid, the area of the grid can be obtained by calculating its length and width, or using image processing methods (such as contour analysis).
[0073] The overlapping area information may be the area of the overlapping region between two or more candidate grids. That is, the area of their overlapping part. This information is necessary for calculating the overlapping degree of two candidate grids.
[0074] The overlapping value may be a numerical value used to represent the overlapping degree between two candidate grids, usually calculated using a formula. It is usually related to the ratio of the overlapping area of the two grids to their respective areas.
[0075] By calculating the spatial relationships between each candidate grid, identify those grids with overlapping regions, and combine these overlapping grids into an "overlapping candidate grid group". For each candidate grid, calculate its area size. For each pair of overlapping candidate grids, calculate the area of their overlapping part. Using the area information and the overlapping area information, calculate the overlapping value of each pair of overlapping candidate grids according to a preset formula. If the overlapping value exceeds the preset threshold, it is considered that the grid belongs to the same cluster and can be deleted or merged. According to the calculated overlapping value, delete those candidate grid groups with too large overlapping values to remove redundant information. Update the candidate grids after deleting the overlapping part, calculate their intersection relationships and size information again, and use this information to re - conduct grid cluster and clustering analysis.
[0076] After obtaining the overlap value, the present solution further includes the following steps: Let the number of all overlapping grid pairs be , the number of grids in a grid cluster of a certain size is , and the number of overlapping pairs associated with the grids in the cluster is , then the weight corresponding to each grid cluster of each size is: ; After normalizing the weights of all grid clusters, it is: ; Calculate the weights for the rows or columns where the grids are located, including: constructing a grid matrix based on the coordinates of the upper left vertices of the grids. Each row or column of grids has the same row and column weights. The row weight is equal to the number of grids in that row divided by the total number of rows, and the column weight is equal to the number of grids in that column divided by the total number of columns.
[0077] Divide and combine the grid matrix by rows or columns, and calculate the weight for each grid accordingly, including: In the grid matrix, rows and columns have similar processing methods. Taking rows as an example. Select some rows as a combination, such that: - The row spacing within the combination is as close as possible; - Remove the combinations that are included in other combinations. For example, if combinations 1, 2, 3 include 1, 3, then remove the latter combination; Calculate the number of times each row or column appears in the row and column combinations, and calculate the weight of each grid accordingly: ; Where and are the weights of the row and column where the grid is located as described above, and are the normalized weights of the number of times the row and column where the grid is located appear in the row and column combinations, is the grid size cluster weight as described above, is the difference degree of the length and width of the grid itself, and the formula is: ; Where is the size of the grid size cluster where the grid is located.
[0078] In this solution, by identifying and deleting candidate squares with overly large overlapping values, duplicate or redundant regions can be removed, thereby avoiding repeated calculations or incorrect judgments during subsequent processing. This helps improve the algorithm efficiency and reduce unnecessary computations. Merging squares with similar features can assist in better extracting the target regions and avoiding the loss or misjudgment of target information caused by overlapping. This helps accurately identify the target in the image. By calculating and controlling the overlapping relationships, the uniqueness and consistency of each candidate square in the final result are ensured. This can prevent the occurrence of duplicate information and enhance the stability and consistency of subsequent analysis.
[0079] Based on the above technical solution, optionally, the preset formula for calculating the overlapping value is: ; Wherein, is the overlapping value; is the area information of overlapping candidate square A in the overlapping candidate square group; is the area information of overlapping candidate square B in the overlapping candidate square group; is the overlapping area information.
[0080] Based on the above technical solution, optionally, after updating each candidate square, the method further includes: Obtaining the distance data between each candidate square and the boundary of the original image, calculating the adjusted size information of each candidate square according to the size information, distance data of each candidate square, and the preset size adjustment formula, and adjusting the size of each candidate square according to the adjusted size information.
[0081] In this solution, the boundary of the original image can be the outer frame or the boundary lines around the image, usually the outermost layer of the image. It is the farthest extension of the image and usually exists in the form of a rectangle, defining the width and height of the image.
[0082] The distance data can refer to the relative position distance between each candidate square and the boundary of the original image. Specifically, the distance data includes the shortest distances from the four edges (left, right, top, bottom) of the candidate square to the image boundary. These distance data can help us determine the position of the square in the image and whether it is necessary to adjust the size or position of the square. After obtaining the distances between the candidate square and the four boundaries, the shortest distance is selected as the distance data.
[0083] The adjusted size information can be the new size data calculated through the preset size adjustment formula based on the size information and distance data of the candidate square. Specifically, the adjusted size information includes: the adjusted square width, the adjusted square height.
[0084] For each candidate square, the distances from each of its sides (left, right, top, bottom) to the boundaries of the original image can be calculated. For example, the distance to the left boundary is the horizontal distance from the left edge of the square to the left boundary of the image, the distance to the right boundary is the distance from the right edge of the square to the right boundary of the image, and so on. After obtaining the distances between the candidate square and the four boundaries, the shortest distance is selected as the distance data. Then, the size information and distance data of each candidate square are substituted into a preset size adjustment formula to calculate the adjusted size information of each candidate square, and the calculated adjusted size information is used to adjust the size of each candidate square. The adjustment process may involve expanding or shrinking the width and height of the square, or translating the square to ensure that they appear in the image in the best state.
[0085] In this solution, adjusting the size and position of the candidate squares helps to improve the rationality and accuracy of the square layout, providing more optimized input data for subsequent image analysis.
[0086] Based on the above technical solution, optionally, the preset size adjustment formula is: ; where, is the adjusted size information; is the size information; is a preset adjustment factor used to control the amplitude of size adjustment; is the distance data.
[0087] S204. Obtain the size information of each candidate square, and determine the clustering results of each candidate square under each square cluster according to the size information.
[0088] The size information can be the width and height of each square, or the area and perimeter of the square, etc.
[0089] All candidate squares can be sorted in ascending order according to a certain criterion (usually area, width, or height). Sorting helps to merge squares with relatively small size differences in subsequent steps. Specifically, the sorting criterion (such as area, width, or height) can be selected. Sort the size information of all candidate squares to obtain an ordered size list. For example, if sorted by area, it is sorted from the smallest area to the largest. Determine which squares can be grouped into one category based on the size information. Usually, "relatively small adjacent size difference" is used as the clustering criterion. That is to say, if the sizes of two squares are very close, they can be grouped into one category. Specifically, in the sorted size list, check the size difference between two adjacent squares. If their size difference (such as area difference, width or height difference) is less than a preset threshold, then group them into the same category. Start from the first square in the size list and compare the size difference with the next square. If the difference is less than the threshold, group these two squares into the same category. If the difference is large, start a new square cluster. Compare all squares in turn and group squares with small size differences into the same category. After each merge, update the boundary of the current square cluster until all squares are merged. When merging to a certain square cluster and no two squares meet the merge condition (size difference is less than the threshold), stop the merge, indicating that the clustering is completed, and the clustering results of each candidate square are obtained. After the clustering is completed, all candidate squares will be assigned to different clusters. Each cluster contains a group of squares with relatively small size differences. At this time, the squares within each cluster are of similar size and belong to the same category, while the size differences between squares in different clusters are relatively large.
[0090] S205. If the demand information sent by the control center is received, input the demand information and the clustering result into a preset LP model to obtain the square optimization information of each candidate square.
[0091] S206. Fill the original image with squares according to the square optimization information, and intercept the calligraphy square pictures in the original image according to the square optimization information.
[0092] In this embodiment, by combining the intersection relationship and size information, the accuracy of candidate square clustering is effectively improved. Redundant data can be reduced, and the efficiency of calculation and storage can be enhanced.
[0093] Figure 3 The following is a schematic block diagram of a calligraphy square extraction system provided by an embodiment of the present disclosure, including: A line segment extraction module 301, configured to obtain an original image, extract the line segment information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line segment information; The line segment merging module 302 is configured to merge each vertical line according to a preset merging criterion to obtain each target long vertical line, and merge each horizontal line according to the preset merging criterion to obtain each target long horizontal line; The analysis module 303 is configured to determine the intersection data of each target long vertical line and each target long horizontal line, determine each candidate square according to the intersection data, perform clustering and cluster analysis on each candidate square, and determine the square cluster and the clustering result of each candidate square; The square optimization information determination module 304 is configured to, if receiving the requirement information sent by the control center, input the requirement information and the clustering result into a preset LP model to obtain the square optimization information of each candidate square; The square filling module 305 is configured to perform square filling on the original image according to the square optimization information, and intercept the calligraphy square picture in the original image according to the square optimization information.
[0094] Figure 4 FIG. shows a schematic block diagram of an electronic device 400 that can be used to implement the embodiments of the present disclosure. The electronic device is intended to represent various forms of digital computers, such as, for example, a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, for example, a personal digital processor, a cellular phone, a smart phone, a wearable device, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0095] The electronic device 400 includes a computing unit 401, which can execute various appropriate actions and processes according to the computer program stored in the ROM 402 or the computer program loaded from the storage unit 408 into the RAM 403. In the RAM 403, various programs and data required for the operation of the electronic device 400 can also be stored. The computing unit 401, the ROM 402, and the RAM 403 are connected to each other through a bus 404. The I / O interface 405 is also connected to the bus 404.
[0096] Multiple components in the electronic device 400 are connected to the I / O interface 405, including: an input unit 406, such as a keyboard, a mouse, etc.; an output unit 407, such as various types of displays, speakers, etc.; a storage unit 408, such as a disk, an optical disc, etc.; and a communication unit 409, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 409 allows the electronic device 400 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0097] The computing unit 401 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 401 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 401 executes the various methods and processes described above, such as the method for extracting grid lines of a copybook. For example, in some embodiments, the method for extracting grid lines of a copybook can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 408. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 400 via the ROM 402 and / or the communication unit 409. When the computer program is loaded into the RAM 403 and executed by the computing unit 401, one or more steps of the method for extracting grid lines of a copybook described above can be executed. Alternatively, in other embodiments, the computing unit 401 can be configured to execute the method for extracting grid lines of a copybook in any other suitable manner (e.g., by means of firmware).
[0098] Various embodiments of the systems and techniques described above in this document can be implemented in digital electronic circuitry, integrated circuit systems, field-programmable gate arrays (FPGA), application-specific integrated circuits (ASIC), application-specific standard products (ASSP), system-on-a-chip (SOC), complex programmable logic devices (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit the data and instructions to the storage system, the at least one input device, and the at least one output device.
[0099] The program code for implementing the methods of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the program codes are executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program codes can be executed entirely on the machine, partially on the machine, as a stand-alone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0100] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0101] To provide for interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can also be used to provide for interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic, speech, or tactile input).
[0102] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of a communication network include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0103] A computer system can include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
[0104] It should be understood that the various forms of processes shown above can be used, with steps reordered, added or deleted. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and no limitations are imposed herein.
[0105] The above specific embodiments do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub - combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure shall be included within the scope of protection of this disclosure.
Claims
1. A method for extracting grid lines from a copybook, characterized in that, The method includes: Obtain an original image, extract the line segment information of each line segment in the original image, and divide each line segment in the original image into each horizontal line and each vertical line according to the line segment information; Merge each vertical line according to a preset merging standard to obtain each target long vertical line, and, merge each horizontal line according to a preset merging standard to obtain each target long horizontal line; Determine the intersection data of each target long vertical line and each target long horizontal line, determine each candidate square according to the intersection data, perform clustering and clustering analysis on each candidate square, and determine the square cluster and clustering result of each candidate square; If demand information sent by the control center is received, input the demand information and the clustering result into a preset LP model to obtain the square optimization information of each candidate square; Perform square filling on the original image according to the square optimization information, and, intercept the copybook square picture in the original image according to the square optimization information.
2. The method for extracting grid of a copybook according to claim 1, wherein Wherein, Extracting the line segment information of each line segment in the original image, and dividing each line segment in the original image into each horizontal line and each vertical line according to the line segment information includes: Determine each vertical line region and each horizontal line region of the original image according to the Morphology operator of the OpenCV library, and set the sizes of each vertical line region and each horizontal line region according to the MORPH_RECT kernel; Determine the line segment information of each vertical line region and each horizontal line region according to the findContours method, and convert each vertical line region and each horizontal line region into each vertical line and each horizontal line according to the line segment information.
3. A method for extracting grid lines of a copybook, according to claim 1, characterized in that, Wherein, Performing clustering and clustering analysis on each candidate square, and determining the square cluster and clustering result of each candidate square includes: Obtain the intersection relationship of each candidate square, and determine the square cluster of each candidate square according to the intersection relationship; Obtain the size information of each candidate square, and determine the clustering result of each candidate square under each square cluster according to the size information.
4. A method for extracting grid lines from a copybook according to claim 3, characterized in that, Wherein, Before obtaining the intersection relationship of each candidate square and determining the square cluster of each candidate square according to the intersection relationship, the method further includes: Determine the overlapping candidate square groups in each candidate square, obtain the area information of each overlapping candidate square in the overlapping candidate square groups, and, obtain the overlapping area information between each overlapping candidate square in the overlapping candidate square groups; Calculate the overlapping value of each overlapping candidate square in the overlapping candidate square groups according to a preset overlapping value calculation formula, area information, and overlapping area information, delete the overlapping candidate square groups whose overlapping values exceed a preset overlapping degree threshold, and update each candidate square; Correspondingly, obtaining the intersection relationship of each candidate square and determining the square cluster of each candidate square according to the intersection relationship includes: Obtain the intersection relationship of the updated candidate squares, and determine the updated square cluster of the updated candidate squares according to the intersection relationship; Correspondingly, obtaining the size information of each candidate square and determining the clustering result of each candidate square under each square cluster according to the size information includes: Obtain the size information of the updated candidate squares, and determine the clustering result of the candidate squares under the updated square cluster according to the size information.
5. A method for extracting grid lines of a copybook, according to claim 4, characterized in that The preset overlapping value calculation formula is: ; Among them, is the overlapping value; is the area information of the overlapping candidate square A of the overlapping candidate square group; is the area information of the overlapping candidate square B of the overlapping candidate square group; is the overlapping area information.
6. A method for extracting grid lines of a copybook according to claim 4, characterized in that Wherein, After updating each candidate grid, the method further includes: Obtaining the distance data between each candidate grid and the boundary of the original image, calculating the adjusted size information of each candidate grid according to the size information, distance data of each candidate grid, and a preset size adjustment formula, and adjusting the size of each candidate grid according to the adjusted size information.
7. A method for extracting grid lines from a copybook according to claim 6, characterized in that, Wherein, The preset size adjustment formula is: ; Among them, is for adjusting dimension information; is dimension information; is a preset adjustment factor for controlling the amplitude of dimension adjustment; is distance data.
8. A method for extracting grid lines from a copybook according to claim 1, characterized in that, Wherein, Performing grid filling on the original image according to the grid optimization information, including: Generating a grid matrix according to the grid optimization information, determining the vacant area of the grid matrix, and performing grid filling on the original image according to the grid matrix and the vacant area.
9. A calligraphy copybook grid extraction system for performing the method according to any one of claims 1-8, characterized in that, The system includes: A line segment extraction module, configured to obtain the original image, extract the line segment information of each line segment of the original image, and divide each line segment of the original image into each horizontal line and each vertical line according to the line segment information; A line segment merging module, configured to merge each vertical line according to a preset merging criterion to obtain each target long vertical line, and, merge each horizontal line according to a preset merging criterion to obtain each target long horizontal line; An analysis module, configured to determine the intersection data between each target long vertical line and each target long horizontal line, determine each candidate grid according to the intersection data, perform clustering and cluster analysis on each candidate grid, and determine the grid cluster and clustering result of each candidate grid; A grid optimization information determination module, configured to, if receiving the requirement information sent by the control center, input the requirement information and the clustering result into a preset LP model to obtain the grid optimization information of each candidate grid; A grid filling module, configured to perform grid filling on the original image according to the grid optimization information, and, intercept the copybook grid picture in the original image according to the grid optimization information.
10. An electronic device, characterized in that, Including: At least one processor; And A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method according to any one of claims 1-8.
Citation Information
Patent Citations
Hard-tipped pen calligraphy matts slice image extraction method, system and device
CN113901936A
Table information extraction method and system
CN114419647A
Table recognition method and device, electronic equipment and storage medium
CN116612487A
Text image table structure acquisition method and device and electronic equipment
CN116758568A
Automated document processing for detecting, extracting, and analyzing tables and tabular data
US20220318224A1