Data management method based on paper test report
Through the combination of OpenCV and Pandas library, the digital processing of paper test reports is realized, which solves the problems of low efficiency and poor accuracy in the existing technology, improves the efficiency and accuracy of data entry, and realizes the electronic operation of test reports.
Patent Information
- Application Number
- CN202410637116.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the existing technology, the processing method of paper test report data is inefficient and error-prone, especially when identifying scanned pictures of test reports through OCR technology, the accuracy is low and structured text cannot be formed, resulting in inconvenient operations such as data entry into the database, and Table diversity leads to low versatility.
The OpenCV library is used to convert paper test reports into digital images. Through contour recognition and cell mapping, the DataFrame object is created in combination with the Pandas library, and templates are customized for data filling and verification to achieve automated data entry.
It effectively solves the text entry problem of paper reports, reduces manual duplication of work, improves work efficiency, realizes electronic data operations of paper reports, and converts unstructured data into structured data to facilitate automatic entry into the database.
Smart Images

Figure CN118587727A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of paper report data, and in particular to a method for managing paper test report data. Background Art
[0002] In all walks of life, the importance of testing is self-evident. The test report is a record of the test process and the output of the results. It is an important basis for the detection and evaluation of equipment, engineering and other information. At present, the main way to process the relevant test report data is to screen one by one against paper records or word document test reports and manually enter them into the management system. This manual and mechanical data processing method is not only inefficient and error-prone, but also unable to form a digital comparison.
[0003] At present, the main processing method for relevant test report data is to screen one by one against paper records or word document test reports and manually enter them into the management system. This manual and mechanical data processing method is not only inefficient and error-prone, but also unable to form a digital comparison. Among them, the difficulty of entering paper reports into the system is particularly great, and the general OCR technology mainly recognizes the text content in the picture, and has strict requirements on the picture size, text position, etc., especially for scanned pictures of test reports, the recognition accuracy is extremely low, and the recognition content cannot indicate the row and column to which the text cell belongs, making it difficult to structure the text, and inconvenient for other data operations such as entering the database. In addition, due to the diversity of tables, the correspondence between the front, back, left and right of the test data is uncertain. It is defined for a single file, the workload is huge, and the versatility is extremely low. To this end, we propose a data management method based on paper test reports to solve the above problems. Summary of the invention
[0004] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.
[0005] In view of the above problems existing in the existing paper-based test report data management method, the present invention is proposed.
[0006] Therefore, the purpose of the present invention is to provide a data management method based on paper test reports, which can convert paper test reports into electronic information, can be directly used for data operations, and arrange them according to the row and column relationships in the cells. This can effectively solve the problem of text entry in paper reports, reduce manual repetitive labor, and improve work efficiency.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions: a method for managing data based on paper test reports, comprising the following steps:
[0008] Step 1: Image acquisition: First, the table in the paper test report needs to be converted into a digital image by scanning or taking a photo;
[0009] Step 2: Use the OpenCV library to read the image file and convert it into a grayscale image, binarize the image, and use the cv2.findContours() function to find the contour;
[0010] Step 3: Traverse each contour and extract cell information. Based on the extracted features, create a mapping relationship to associate the position of each cell with its content and add it to the data map.
[0011] Step 4: Template customization and test data location: According to the test report structure, refer to the test-related procedures to customize the template and locate the position in the project data report, and store the relevant data;
[0012] Step 5: Fill in the customized template: Combined with data positioning, intercept the specified fragment of the read data and fill in the customized template.
[0013] As a preferred solution of the paper-based test report data management method described in the present invention, wherein: the cv2.findContours() function in step 2 returns two results: contour and hierarchy; contour is a list containing all contours, each contour is a list composed of points; hierarchy is a list containing the relationship between each contour.
[0014] As a preferred solution of the paper-based test report data management method of the present invention, the function formula of the cv2.findContours() function is:
[0015] contours,hierarchy=cv2.findContours(image,mode,method);
[0016] Among them, image is the input binary image, mode is the contour detection mode, and method is the contour approximation method.
[0017] As a preferred solution of the paper-based test report data management method of the present invention, the cell mapping relationship in step 3 is: for each grid, its position is associated with the corresponding cell content, using the following formula:
[0018] -Cell upper left corner coordinates: (x, y)
[0019] -Cell width: w
[0020] -Cell height: h
[0021] -Cell content: c
[0022] The cell mapping relationship is expressed as: (x, y, w, h)->c
[0023] The position of each cell is accurately associated with its content through the position information of the grid.
[0024] As a preferred solution of the paper-based test report data management method of the present invention, wherein: in step 3, after adding to the data map, a DataFrame object is created and printed using the pd.DataFrame() function. The specific steps are as follows:
[0025] 1) Import the Pandas library: First, you need to import the Pandas library so that you can use its functions and methods. In Python code, use the import pandas as pd statement to import the Pandas library.
[0026] 2) Prepare data: Before using the pd.DataFrame() function to create a DataFrame object, you need to prepare the data to be stored in the DataFrame, which includes lists, dictionaries and other formats;
[0027] 3) Call the pd.DataFrame() function: Use the pd.DataFrame() function to create a DataFrame object and pass the prepared data as a parameter to the function;
[0028] 4) Set column names: If you need to specify column names when creating a DataFrame, use the columns parameter to pass the column names in the form of a list;
[0029] 5) Set the index: If you need to specify the index when creating a DataFrame, use the index parameter to pass the index to the parameter in the form of a list;
[0030] 6) Print DataFrame: Use the print() function or directly output the name of the DataFrame object in the interactive shell to view its contents.
[0031] As a preferred solution of the paper-based test report data management method of the present invention, wherein: after the completion of step three, the validity of the table data needs to be verified: the extracted data is verified to ensure its accuracy, and the specific steps of verifying the validity of the data are:
[0032] S1. Format check: Use regular expressions or string processing methods to verify whether the data conforms to the expected format;
[0033] S2, completeness check: by traversing each cell in the table, ensure that all necessary fields are filled and there are no omissions;
[0034] S3. Consistency check: Compare duplicate records or similar records to ensure that data of the same type remains consistent; check whether the relationship between data is reasonable, such as whether the calculated total matches the sum of each part.
[0035] As a preferred solution of the paper-based test report data management method described in the present invention, the template customization in step four needs to be customized according to the nature of the test and the report itself, and the hierarchical relationships such as test items, sub-items, parts, phases, etc. corresponding to each test value are clarified. Accordingly, the template can be stored in XML format, and each test value is numbered for subsequent filling operations. The structure that cannot be friendly expressed in the test report itself can be further refined in the template.
[0036] As a preferred solution of the paper-based test report data management method described in the present invention, according to the hierarchical relationship in the template, it is necessary to clarify the position of the test data values at each level in the test report table, which is specifically expressed in the clear form of row and column, and the test name is used as the key to establish a mapping between each test value and the position in the corresponding table.
[0037] As a preferred solution of the paper-based test report data management method described in the present invention, wherein: in the step five, the test value is directly filled in through the table position, the test value number in the template customization is obtained, the corresponding table position is obtained in the mapping table according to the number, and the extracted data is directly obtained and filled, and the predetermined placeholders or tags are found in the template, Python is used to locate these placeholders, and they are replaced with actual data to ensure that all placeholders are correctly replaced and the format and layout of the document remain consistent.
[0038] As a preferred solution of the paper-based test report data management method described in the present invention, the filled document is manually checked after the customization is completed to ensure that all data are correct. If any problems are found, it is necessary to return to the data extraction stage for adjustment and re-verification.
[0039] The beneficial effects of the present invention are as follows: the present invention can convert paper test reports into electronic information, which can be directly used for data operations, and arranged according to the row and column relationships in the cells, which can effectively solve the problem of text entry in paper reports, reduce manual repetitive labor, and improve work efficiency; the present invention can automatically convert unstructured data such as tables in electronic test reports into structured data, which is convenient for data operations such as automatic entry of test report data into a database; the customized template corresponds to the position in the report, and is implemented in a semi-automatic method, which can avoid the problem that the comparison according to the table content cannot be accurately matched due to the diversity of the table. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:
[0041] Figure 1 The figure is a schematic diagram of the process structure of the paper-based test report data management method of the present invention.
[0042] Figure 2 This is a schematic diagram of some test records in an embodiment of the method for managing paper-based test report data of the present invention.
[0043] Figure 3 A schematic diagram of a customized XML template for an embodiment of the method for managing paper test report data according to the present invention. DETAILED DESCRIPTION
[0044] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0045] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0046] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0047] Secondly, the present invention is described in detail with reference to the schematic diagram. When describing the embodiments of the present invention in detail, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.
[0048] Reference Figure 1 , provides a method for managing data based on paper test reports, comprising the following steps:
[0049] Step 1: Image acquisition: First, the table in the paper test report needs to be converted into a digital image by scanning or taking a photo;
[0050] Step 2: Use the OpenCV library to read the image file and convert it into a grayscale image, binarize the image, and use the cv2.findContours() function to find the contour;
[0051] Step 3: Traverse each contour and extract cell information. Based on the extracted features, create a mapping relationship to associate the position of each cell with its content and add it to the data map.
[0052] Step 4: Template customization and test data location: According to the test report structure, refer to the test-related procedures to customize the template and locate the position in the project data report, and store the relevant data;
[0053] Step 5: Fill in the customized template: Combined with data positioning, intercept the specified fragment of the read data and fill in the customized template.
[0054] Among them, the cv2.findContours() function in step 2 returns two results: contour and hierarchy; contour is a list containing all contours, each contour is a list of points; hierarchy is a list containing the relationship between each contour. Specifically, the function formula of the cv2.findContours() function is:
[0055] contours,hierarchy=cv2.findContours(image,mode,method);
[0056] Among them, image is the input binary image, mode is the contour detection mode, and method is the contour approximation method. The specific sample code demonstration is:
[0057] Python
[0058] import cv2
[0059] #Read the image file and convert it to grayscale image
[0060] img = cv2.imread('image.jpg')
[0061] gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
[0062] # Binarize the grayscale image
[0063] ret,thresh=cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
[0064] #Find contours
[0065] contours,hierarchy=cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
[0066] #Traverse each contour and draw the contour
[0067] for contour in contours:
[0068] x,y,w,h=cv2.boundingRect(contour)
[0069] cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
[0070] # Display the image
[0071] cv2.imshow('Contours',img)
[0072] cv2.waitKey(0)
[0073] cv2.destroyAllWindows().
[0074] Among them, the cell mapping relationship in step 3 is: for each grid, its position is associated with the corresponding cell content, using the following formula:
[0075] -Cell upper left corner coordinates: (x, y)
[0076] -Cell width: w
[0077] -Cell height: h
[0078] -Cell content: c
[0079] The cell mapping relationship is expressed as: (x, y, w, h)->c
[0080] The position of each cell is accurately associated with its content through the position information of the grid.
[0081] In step 3, after adding to the data map, use the pd.DataFrame() function to create a DataFrame object and print it. The specific steps are as follows:
[0082] 1) Import the Pandas library: First, you need to import the Pandas library so that you can use its functions and methods. In Python code, use the import pandas as pd statement to import the Pandas library.
[0083] 2) Prepare data: Before using the pd.DataFrame() function to create a DataFrame object, you need to prepare the data to be stored in the DataFrame, which includes lists, dictionaries and other formats;
[0084] 3) Call the pd.DataFrame() function: Use the pd.DataFrame() function to create a DataFrame object and pass the prepared data as a parameter to the function;
[0085] 4) Set column names: If you need to specify column names when creating a DataFrame, use the columns parameter to pass the column names in the form of a list;
[0086] 5) Set the index: If you need to specify the index when creating a DataFrame, use the index parameter to pass the index to the parameter in the form of a list;
[0087] 6) Print DataFrame: Use the print() function or directly output the name of the DataFrame object in the interactive shell to view its contents; the specific sample code is demonstrated as follows:
[0088] import pandas as pd
[0089] #Prepare data
[0090] data={
[0091] 'Name':['Zhang San', 'Li Si', 'Wang Wu'],
[0092] 'Age':[25,30,35],
[0093] 'City':['Beijing', 'Shanghai', 'Shenzhen']
[0094] }
[0095] #Create DataFrame object
[0096] df = pd.DataFrame(data)
[0097] #Print DataFrame
[0098] print(df).
[0099] After the completion of step 3, the validity of the table data needs to be verified: the extracted data needs to be verified to ensure its accuracy. The specific steps for verifying the validity of the data are as follows:
[0100] S1. Format check: Use regular expressions or string processing methods to verify whether the data conforms to the expected format;
[0101] S2, completeness check: by traversing each cell in the table, ensure that all necessary fields are filled and there are no omissions;
[0102] S3. Consistency check: Compare duplicate records or similar records to ensure that data of the same type remains consistent; check whether the relationship between data is reasonable, such as whether the calculated total matches the sum of each part.
[0103] Furthermore, the template customization in the step four needs to be customized according to the nature of the test and the report itself, and the hierarchical relationships such as test items, sub-items, parts, phases, etc. corresponding to each test value must be clarified. Accordingly, the template can be stored in XML format, and each test value is numbered for subsequent filling operations. The structure that the test report itself cannot represent in a friendly manner can be further refined in the template. Specifically, according to the hierarchical relationship in the template, the position of the test data values at each level needs to be clarified in the test report table, which is specifically expressed in the form of a clear row and column, and the test name is used as the key to establish a mapping between each test value and the corresponding position in the table.
[0104] Among them, in step five, the test value is directly filled in through the table position, the test value number in the template customization is obtained, the corresponding table position is obtained in the mapping table according to the number, and the extracted data is directly obtained and filled, and the predetermined placeholders or tags are found in the template. Python is used to locate these placeholders and replace them with actual data to ensure that all placeholders are correctly replaced and the format and layout of the document are consistent.
[0105] After the customization is completed, manually check the filled document to ensure that all data is correct. If any problems are found, return to the data extraction stage to make adjustments and re-verify.
[0106] Specific embodiments:
[0107] Based on part of the test records of "220kV Metal Oxide Surge Arrester Acceptance Test Report" ( Figure 2 ) as an example, customize the xml template ( Figure 3 ):
[0108] The insulation resistance test is a test item in the acceptance test of the 220kV metal oxide arrester. The factory number is the information of the equipment itself. Due to the design of the test report, it cannot be displayed in a friendly manner and needs to be presented separately. The hierarchical relationship of the insulation resistance test is as follows: Project: Insulation resistance; Sub-project: Insulation resistance; Test part: upper section main insulation, lower section main insulation, allowable value, base insulation, allowable value; Test phases: A, B, C.
[0109] Further calibration of the position of each test value, taking the test value under the main insulation of the above section as an example, this part contains 3 values, namely A, B, and C. The 3 test values are data No. 17, 18, and 19, and the corresponding positions in the table are: (10, 2), (10, 3), (10, 4), where 10 represents the 11th row, 2, 3, 4 represent the 3rd, 4th, and 5th columns (the program generally starts counting from 0).
[0110] Create a mapping table in the form of: {“220kV Metal Oxide Arrester Acceptance Test Report”: […(10,2),(10,3),(10,4)…]}, where (10,2) is the 17th position in the list.
[0111] 2. Data reading: read data from word, excel and other tables;
[0112] In particular, the test report header needs to be identified to match the template customized in the first step;
[0113] In particular, the read content needs to be deduplicated, sorted, and adjusted to ensure that the location of each data is consistent with the table structure.
[0114] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for managing data based on paper test reports, characterized in that: The following steps are involved: Step 1: Image acquisition: First, the table in the paper test report needs to be converted into a digital image by scanning or taking a photo; Step 2: Use the OpenCV library to read the image file and convert it into a grayscale image, binarize the image, and use the cv2.findContours() function to find the contour; Step 3: Traverse each contour and extract cell information. Based on the extracted features, create a mapping relationship to associate the position of each cell with its content and add it to the data map. Step 4: Template customization and test data location: According to the test report structure, refer to the test-related procedures to customize the template and locate the position in the project data report, and store the relevant data; Step 5: Fill in the customized template: Combined with data positioning, intercept the specified fragment of the read data and fill in the customized template.
2. The method for managing data based on paper test reports according to claim 1, characterized in that: In the step 2, the cv2.findContours() function returns two results: contours and hierarchies; contours is a list containing all contours, each contour is a list of points; and hierarchies is a list containing the relationship between each contour.
3. The method for managing data based on paper test reports according to claim 2, characterized in that: The functional formula of the cv2.findContours() function is: contours,hierarchy=cv2.findContours(image,mode,method); Among them, image is the input binary image, mode is the contour detection mode, and method is the contour approximation method.
4. The method for managing data based on paper test reports according to claim 1, characterized in that: The cell mapping relationship in step 3 is as follows: for each grid, its position is associated with the corresponding cell content, using the following formula: -Cell upper left corner coordinates: (x, y) -Cell width: w -Cell height: h -Cell content: c The cell mapping relationship is expressed as: (x, y, w, h)->c The position of each cell is accurately associated with its content through the position information of the grid.
5. The method for managing data based on paper test reports according to claim 4, characterized in that: In step 3, after adding to the data map, use the pd.DataFrame() function to create a DataFrame object and print it. The specific steps are as follows: 1) Import the Pandas library: First, you need to import the Pandas library so that you can use its functions and methods. In Python code, use the import pandas as pd statement to import the Pandas library. 2) Prepare data: Before using the pd.DataFrame() function to create a DataFrame object, you need to prepare the data to be stored in the DataFrame, which includes lists, dictionaries and other formats; 3) Call the pd.DataFrame() function: Use the pd.DataFrame() function to create a DataFrame object and pass the prepared data as a parameter to the function; 4) Set column names: If you need to specify column names when creating a DataFrame, use the columns parameter to pass the column names in the form of a list; 5) Set the index: If you need to specify the index when creating a DataFrame, use the index parameter to pass the index to the parameter in the form of a list; 6) Print DataFrame: Use the print() function or directly output the name of the DataFrame object in the interactive shell to view its contents.
6. The method for managing data based on paper test reports according to claim 1, characterized in that: After completing step 3, you need to verify the validity of the table data: verify the extracted data to ensure that it is accurate. The specific steps for verifying the validity of the data are: S1. Format check: Use regular expressions or string processing methods to verify whether the data conforms to the expected format; S2, completeness check: by traversing each cell in the table, ensure that all necessary fields are filled and there are no omissions; S3. Consistency check: Compare duplicate records or similar records to ensure that data of the same type remains consistent; check whether the relationship between data is reasonable, such as whether the calculated total matches the sum of each part.
7. The method for managing data based on paper test reports according to claim 1, characterized in that: The template customization in the step 4 needs to be customized according to the nature of the test and the report itself, and the hierarchical relationships such as test items, sub-items, parts, phases, etc. corresponding to each test value must be clarified. Accordingly, the template can be stored in XML format, and each test value is numbered for subsequent filling operations. The structure that cannot be friendly expressed in the test report itself can be further refined in the template.
8. The method for managing data based on paper test reports according to claim 7, characterized in that: According to the hierarchical relationship in the template, the position of the test data values at each level needs to be clearly defined in the test report table, specifically in the form of rows and columns. Using the test name as the key, a mapping is established between each test value and the corresponding position in the table.
9. The method for managing data based on paper test reports according to claim 1, characterized in that: In the step five, the test value is directly filled in through the table position, the test value number in the template customization is obtained, the corresponding table position is obtained in the mapping table according to the number, and the extracted data is directly obtained and filled, and the predetermined placeholders or tags are found in the template. Python is used to locate these placeholders and replace them with actual data to ensure that all placeholders are correctly replaced and the format and layout of the document are consistent.
10. The method for managing data based on paper test reports according to claim 9, characterized in that: After the customization is completed, manually check the filled document to ensure that all data is correct. If any problems are found, return to the data extraction stage to make adjustments and re-verify.
Citation Information
Patent Citations
Efficient OCR recognition algorithm based on visual sense
CN108564064A
Paper test report generation method based on scanned copy
CN113569677A
Method and system for realizing table digital processing based on image processing and character recognition
CN114627482A
Electrical test report data automatic acquisition system and method
CN116976293A
Apparatus and Method for Generating Electronic CaseReport Form, System and Method for Providing ElectronicCase Report Form Service Using the Same
KR1020080019870A
