Cost detail list identification method and system based on OCR and LLM
Through multi-stage processing technology based on OCR and LLM, the format inconsistency and positional relationship understanding problems in the identification of medical expense detailed lists are solved, efficient and accurate text recognition and specific information extraction are achieved, and the efficiency and reliability of medical expense management are improved. sex.
Patent Information
- Application Number
- CN202410853316.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2044-06-28
AI Technical Summary
The detailed list of medical expenses is not uniform in format and field names among different medical institutions, which makes automatic identification and analysis more difficult. Traditional manual entry is time-consuming, labor-intensive and error-prone. Existing OCR technology is accurate when processing non-standard formats, skewed or deformed documents. The rate is limited, and the LLM model lacks the ability to understand spatial position relationships, making it difficult to effectively extract specific information.
Adopt an expense detail list recognition method based on OCR and LLM, use image processing and multi-stage correction technology to detect and intercept the expense detail area, build an affine transformation matrix for picture horizontal correction, row and column correction, and use a large language model for context understanding and Analyze location relationships and extract detailed cost information.
Significantly improves the text recognition accuracy and text recognition accuracy under complex conditions, reduces manual intervention, improves efficiency, can effectively process detailed pictures of medical expenses from different sources and quality, enhances the flexibility and versatility of the system, and shortens the processing time time, ensuring the reliability of data extraction and providing an efficient tool for medical expense management.
Smart Images

Figure CN118747899A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence and medical information technology, and in particular, relates to an expense list recognition method and system based on OCR and LLM. Background Art
[0002] In the process of medical expense reimbursement and claims, accurately and quickly parsing the detailed list of medical expenses has become a major challenge. Since the detailed lists of expenses of various medical institutions have different formats and inconsistent field names, it is more difficult to automatically identify and parse the detailed lists of expenses.
[0003] Traditional manual data entry is not only time-consuming and labor-intensive, but also prone to errors. Although current OCR technology can initially recognize text information, its accuracy is limited when processing documents in non-standard formats, tilted or deformed documents. In addition, it lacks the ability to understand the context of the recognized data, making it difficult to directly apply it to the extraction of specific information.
[0004] To address this problem, the LLM large language model has demonstrated strong capabilities in text processing and context understanding. The LLM large model can be used to interpret the results of OCR recognition and extract information; however, the expense list often contains a large number of data items, which are presented in the form of rows and columns, and each column usually has a specific meaning, such as project name, unit price, quantity, amount, etc.; therefore, for the LLM model, although it has a strong context understanding ability, it often cannot achieve good results for tasks that require a certain ability to understand spatial position relationships in order to better parse text information. Summary of the invention
[0005] The purpose of the present invention is to provide a method and system for recognizing detailed expense lists based on OCR and LLM, so as to solve the problem that images are deformed under various shooting angles and specific information cannot be accurately extracted using the LLM model.
[0006] To achieve one of the above-mentioned purposes, an embodiment of the present invention provides a method for identifying a detailed expense list based on OCR and LLM, the method comprising:
[0007] Collecting an image to be processed, detecting a cost detail area of the image to be processed and capturing a first sub-image;
[0008] Using OCR to identify the first sub-image to obtain a first set, constructing an affine transformation matrix based on the first set to perform horizontal correction on the image, and obtaining a second sub-image after horizontal correction;
[0009] Recognize the second sub-image by OCR to obtain a second set, perform row and column correction on the text lines in the second sub-image based on the second set, and the corrected text line information constitutes a third set;
[0010] A prompt is constructed based on the third set, and expense detail identification information is acquired using a large language model.
[0011] As a further improvement of an embodiment of the present invention, the method further includes detecting the fee detail area in the image to be processed using the target detection model, intercepting the image to be processed according to the bounding box in the detection result, and generating a first sub-image having only the fee detail area.
[0012] As a further improvement of an embodiment of the present invention, the method further includes: the step of using OCR to identify the first sub-image / the second sub-image to obtain the first set / the second set includes:
[0013] Perform text recognition on the first sub-image / the second sub-image using OCR recognition to obtain position information of the minimum bounding rectangle of the text line and a text content recognition result, and store the position information of the minimum bounding rectangle of the text line and the text content in the first set / the second set.
[0014] As a further improvement of an embodiment of the present invention, the method further includes: constructing an affine transformation matrix based on the first set includes:
[0015] Select the longest text line in the first set, calculate the inclination angle θ of the longest text line according to the coordinate information of the four vertices of the minimum circumscribed rectangle of the longest text line, and use the inclination angle θ as the inclination angle of the first subgraph. c ,y c ) as the rotation center, the tilt angle θ as the rotation angle, and construct the affine transformation matrix M;
[0016] The calculation formula of the tilt angle θ is expressed as:
[0017] The affine transformation matrix M is expressed as:
[0018]
[0019] Among them, θ represents the tilt angle, (x1, y1), (x2, y2) represent the coordinates of the upper left corner vertex and the upper right corner vertex of the minimum bounding rectangle of the longest text line; M represents the affine transformation matrix, (x c ,y c ) are the coordinates of the center point of the first sub-graph.
[0020] As a further improvement of an embodiment of the present invention, the method further includes that performing horizontal correction on the image and obtaining a second sub-image after horizontal correction includes:
[0021] Use the affine transformation matrix M to perform affine transformation on the first sub-image to obtain a candidate sub-image after horizontal correction; determine whether the candidate sub-image is positive, if the candidate sub-image is positive, use the candidate sub-image as the second sub-image; if the candidate sub-image is inverted, rotate the candidate sub-image 180° around the center point of the image to obtain the second sub-image;
[0022] The affine transformation is expressed as:
[0023]
[0024] Where M is the affine transformation matrix, (X i ,Y i ) is the coordinate of the i-th pixel in the first sub-image, is the coordinate of the i-th pixel after affine transformation.
[0025] As a further improvement of an embodiment of the present invention, the method further includes: performing line correction on the text line in the second sub-image includes:
[0026] S31: Traverse the text lines in the second set, and for each text line l that is traversed j , according to the text line l j The minimum bounding rectangle of the text line l is calculated by using the coordinate information of the four vertices j The center point coordinates (x j ,y j ), text line l j Height h j , text line j The tilt angle α j , and construct the text line l j The row domain Q j ;
[0027] S32: Calculate the center point coordinates of all text lines in the second set, and select the text lines in the second set whose center point coordinates are in the line range Q. j All text lines in the range; and will be located in the line field Q j The vertical coordinates of the center point coordinates of all text lines in the range are changed to text line l j The vertical coordinate y j , then sort the text lines with the same center point ordinates in ascending order according to the horizontal coordinates of the center points of the text lines, and record the changed center point coordinates of the text lines, the coordinates of the four vertices of the minimum circumscribed rectangle of the text lines, and the character information recognized by OCR in a third set;
[0028] S33: removing the text lines in the third set from the second set;
[0029] S34: repeating steps S31 to S33 until all text lines in the second set are moved to the third set;
[0030] The constructed text line l j The row domain Q j Include: Connect text lines j The upper left corner vertex and the upper right corner vertex of the minimum circumscribed rectangle of the text line l j The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s1, connecting the text line l j The lower right corner vertex and the lower left corner vertex of the minimum circumscribed rectangle are used to enclose the text line l j The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s2, and the area enclosed by the lines s1, s2 and the left and right boundaries of the second subgraph is denoted as text line l j The row domain Q j .
[0031] As a further improvement of an embodiment of the present invention, the method further includes: j The center point coordinates (x j ,y j ) The calculation formula is expressed as:
[0032]
[0033] The text line l j Height h j The calculation formula is expressed as:
[0034] The text line l j Tilt angle α j The calculation formula is expressed as:
[0035] Among them, j∈[1,N], N is the number of text lines in the second set, (x j1 ,y j1 ),(x j2 ,y j2 ),(x j3 ,y j3 ) represents the coordinates of the top left, top right, and bottom right vertices of the minimum bounding rectangle of the j-th text line in the second set, (x j ,y j ) represents the coordinates of the center point of the jth text line.
[0036] As a further improvement of an embodiment of the present invention, the method further includes that the column correction of the text line in the second sub-image includes:
[0037] S35: Traverse the text lines in the third set, and for each text line l that is traversed k , where k∈[1,N], N is the number of text lines in the third set, according to the text line l k Get the text line l by using the coordinate information of the four vertices of the minimum bounding rectangle k The center point coordinates ( x k,y k ) and construct the column domain W k ;
[0038] S36: Filter out the text lines in the third set whose center points are located in column domain W k All text lines in the range will be located in column domain W k The horizontal coordinates of the center points of all text lines in the range are changed to text line l k The horizontal coordinate x of the center point k , and mark the modified text lines;
[0039] S37: repeat the process of S35 to S36, skipping the text line marked in S36, until the traversal process of the third set is completed;
[0040] The constructed column domain W k Include: Connect text lines k The upper left corner vertex and lower left corner vertex of the minimum circumscribed rectangle of the text line l k The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s3, connecting the text line l k The upper right corner vertex and the lower right corner vertex of the minimum circumscribed rectangle are k The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s4, and the area enclosed by the lines s3, s4 and the upper and lower boundaries of the second subgraph is denoted as text line l k The column domain W K .
[0041] As a further improvement of an embodiment of the present invention, the method further includes: constructing a prompt based on the third set and obtaining expense detail identification information using a large language model includes:
[0042] Constructing a prompt based on the coordinates of the center points of the text lines in the third set and the OCR content recognition results, including setting a task description, providing contextual information or display related to the task, setting an input format, setting a placeholder, setting output format requirements, inputting the constructed prompt into a large language model for context understanding and position relationship analysis, extracting expense detail identification information, and outputting results.
[0043] To achieve one of the above-mentioned purposes, an embodiment of the present invention further provides an expense list recognition system based on OCR and LLM, the system comprising:
[0044] Image acquisition module: used to acquire the image to be processed;
[0045] Target detection module: used to detect the cost detail area of the image to be processed and capture the first sub-image;
[0046] OCR recognition module: used to perform OCR recognition on the first sub-image to obtain a first set; perform OCR recognition on the second sub-image to obtain a second set;
[0047] Correction processing module: used for performing horizontal correction on the first sub-image and row and column correction on the text lines in the second sub-image;
[0048] Large language model processing module: used to build prompts and use large language models to obtain expense detail identification information;
[0049] The image acquisition module is connected to the target detection module, and transmits the acquired image data to the target detection module; the target detection module is connected to the OCR recognition module, and transmits the target area screenshot data to the OCR recognition module; the output of the OCR recognition module is connected to the correction processing module, and the recognition result is passed to the correction processing module for correction; the output of the correction processing module is connected to the large language model processing module, and the corrected text position information and text content are sent to the large language model for analysis, and the target information is output.
[0050] Compared with the prior art, the expense list recognition method based on OCR and LLM provided by the present invention significantly improves the accuracy of text recognition under complex conditions while also improving the text recognition precision through multi-stage image processing and OCR text recognition optimization; introduces a large language model to enable the ability to understand spatial position relationships, realizes an intelligent leap from text data to specific information extraction, reduces manual intervention, and improves efficiency; the present invention can effectively process medical expense list images of different sources and qualities, and enhances the flexibility and versatility of the system in practical applications; through algorithm optimization, the processing time is shortened, while ensuring the reliability of data extraction, providing an efficient tool for medical expense management. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 It is an overall flow chart of the expense detail list recognition method based on OCR and LLM described in the present invention.
[0052] Figure 2It is a cost detail area sub-map provided by an embodiment of the cost detail list recognition method based on OCR and LLM described in the present invention.
[0053] Figure 3 It is a flowchart of image horizontal correction in the expense list recognition method based on OCR and LLM described in the present invention.
[0054] Figure 4 It is a flow chart of performing row and column correction on text rows in the second sub-graph in the expense list recognition method based on OCR and LLM of the present invention.
[0055] Figure 5 It is a schematic diagram of the text line field Q in the expense list recognition method based on OCR and LLM of the present invention.
[0056] Figure 6 It is a schematic diagram of the system structure of the expense list recognition system based on OCR and LLM of the present invention. DETAILED DESCRIPTION
[0057] The present invention will be described in detail below in conjunction with the specific embodiments shown in the accompanying drawings. However, these embodiments do not limit the present invention, and any structural, methodological, or functional changes made by a person skilled in the art based on these embodiments are all within the scope of protection of the present invention.
[0058] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0059] In the first embodiment of the present invention, the present invention provides a method for identifying a detailed expense list based on OCR and LLM, such as Figures 1 to 5 As shown, the method includes,
[0060] S1: Collect the image to be processed, detect the cost detail area of the image to be processed and capture the first sub-image;
[0061] In a specific embodiment of the present invention, Figure 2 As shown, "detecting the cost detail area of the image to be processed and intercepting the first sub-image" includes using the target detection model to perform target detection on the image to be processed, determining whether there is a cost detail area in the image, and if there is a cost detail area, intercepting the image according to the bounding box in the detection result to generate a first sub-image A with only the cost detail area, and deleting the non-cost area to eliminate interference.
[0062] In a specific embodiment of the present invention, the "target detection model" includes using a deep learning neural network to train the target detection model for the expense detail area.
[0063] In a specific embodiment of the present invention, "training the target detection model" includes collecting expense detail pictures uploaded by customers, manually annotating them using LabelImg, and dividing them into training set, validation set, and test set in a ratio of 8:1:1; using the PP-YOLOE neural network model to train the data set and output a target detection model for the expense detail area.
[0064] In a specific embodiment of the present invention, the structure of the target detection model includes: selecting a PP-YOLOE model as a target detection model; sending the image to be detected as input into the target detection model, performing feature extraction through a convolutional neural network CNN, and extracting meaningful feature information in the image, including edges, textures, shapes, etc.; based on the feature extraction, generating a series of candidate areas, which may contain the target to be detected; for each candidate area, classification and regression are performed, the classification operation is used to determine whether the area contains the target, and the regression operation is used to determine the pixel position of the target in the image; after classification and regression, the model may output multiple overlapping bounding boxes. In order to eliminate these redundant bounding boxes, a non-maximum suppression algorithm is used to eliminate redundant bounding boxes, and finally the detected target and its corresponding bounding box information are output.
[0065] It should be noted that the selection of a lightweight backbone network can effectively reduce the complexity of the model while ensuring the feature extraction capability, thereby improving the detection speed; the use of feature pyramid fusion technology to integrate feature information at different levels can enhance the model's detection capabilities for targets of different scales; by optimizing the loss function, the target detection model can better balance positive and negative samples during the training process, thereby improving the convergence speed and performance of the model; the combined application of these structures enables PP-YOLOE to perform well in target detection tasks, ensuring both detection accuracy and improving detection speed.
[0066] It should also be noted that PP-YOLOE also uses a multi-scale prediction head, which enables the model to predict targets of different sizes at the same time, further improving the accuracy and robustness of detection.
[0067] S2: using OCR to identify the first sub-image to obtain a first set, constructing an affine transformation matrix based on the first set to perform horizontal correction on the image, and obtaining a second sub-image after horizontal correction;
[0068] In a specific embodiment of the present invention, Figure 3 As shown, “perform OCR recognition on the first sub-image to obtain the first set” includes,
[0069] OCR recognition is used to perform text recognition on the first sub-graph A of the expense details area to obtain the position information of the minimum circumscribed rectangle of the text line and the text content recognition result, forming the text line information list set L1 in the second sub-graph, that is, the first set is expressed as: {"points":[(x1,y1),(x2,y2),(x3,y3),(x4,y4)],"text":"text line content"}, where points represents the coordinates of the four vertices of the minimum circumscribed rectangle of the text line, corresponding to the upper left, upper right, lower right, and lower left vertices, and text represents the text information of the text line.
[0070] In a specific embodiment of the present invention, "constructing an affine transformation matrix based on the first set" includes:
[0071] The longest text line l1 in the first set L1 is selected, and the inclination angle θ of the text line l1 is calculated according to the coordinate information of the four vertices of the minimum circumscribed rectangle of the longest text line. The calculation formula is expressed as: The tilt angle θ is used as the tilt angle of the entire text area, and the center point (x c ,y c ) is used as the rotation center, the tilt angle θ is the rotation angle, and the affine transformation matrix M is constructed as follows:
[0072]
[0073] Among them, (x1, y1), (x2, y2), (x3, y3), (x4, y4) represent the coordinates of the upper left corner, upper right corner, lower right corner, and lower left corner of the minimum circumscribed rectangle of the longest text line; (x c ,y c ) are the coordinates of the center point of the first sub-graph.
[0074] In a specific embodiment of the present invention, “obtaining a horizontally corrected second sub-image B” includes: performing an affine transformation on the first sub-image A using an affine transformation matrix M to obtain a horizontally corrected candidate sub-image; determining whether the candidate sub-image is positive;
[0075] The affine transformation is expressed as:
[0076]
[0077] Where M is the affine transformation matrix, (X i ,Y i ) is the coordinate of the i-th pixel in the first sub-image, is the coordinate of the i-th pixel after affine transformation.
[0078] The specific implementation steps for determining whether the candidate subgraph is positive are:
[0079] Use the affine transformation matrix M to perform an affine transformation on the longest text line l1 in the first set L1 to obtain a horizontally corrected text line l2;
[0080] Then use a general text direction classification model to perform text direction binary classification on the text line l2 to obtain the direction of the text line l2. If the text line l2 is forward, it indicates that the candidate sub-image is forward, and the candidate sub-image is used as the second sub-image B; if the text line l2 is reversed, it indicates that the candidate sub-image is reversed, and the candidate sub-image is rotated 180° around the center point of the image to obtain the second sub-image B.
[0081] In a specific embodiment of the present invention, a text direction classification model is used to classify the direction of text lines, including intercepting a text line sub-image based on the coordinate information of the minimum circumscribed rectangle of the text line, and sending the intercepted sub-image as input to the ch_ppocr_mobile_v2.0_cls network model for algorithm reasoning. The reasoning result indicates whether the text line is forward or reverse.
[0082] S3: using OCR to recognize the second sub-image to obtain a second set, and performing text row correction and text row and column correction on the text in the second sub-image based on the second set, and the corrected text row information constitutes a third set;
[0083] In a specific implementation scenario of the present invention, the second set is expressed as:
[0084] {"points":[(x1,y1),(x2,y2),(x3,y3),(x4,y4)],"text":"Text line content"}
[0085] Among them, points represents the coordinates of the four vertices of the minimum circumscribed rectangle of the text line, corresponding to the upper left, upper right, lower right, and lower left vertices, and text represents the text information of the text line.
[0086] In a specific embodiment of the present invention, Figure 4 As shown, performing text line correction on the text in the second sub-image based on the second set includes:
[0087] S301: Traverse the text lines in the second set, and for each text line l that is traversed j , where j∈[1,N], N is the number of text lines in the second set, according to the text line l j The location information is the coordinates of the four vertices of the minimum circumscribed rectangle [(x j1 ,y j1 ),(x j2 ,y j2 ),(x j3 ,yj3 ),(x j4 ,y j4 )] Count text lines l j The center point coordinates (x j ,y j ), text line l j Height h j , text line j Tilt angle α in the horizontal direction j , and construct the text line l j The row domain Q j ;
[0088] Text line j The center point coordinates (x j ,y j ) The calculation formula is expressed as:
[0089]
[0090] Text line j Height h j The calculation formula is expressed as:
[0091] Text line j Tilt angle α in the horizontal direction j The calculation formula is expressed as:
[0092] Among them, (x j1 ,y j1 ),(x j2 ,y j2 ),(x j3 ,y j3 ),(x j4 ,y j4 ) represents the coordinates of the top left, top right, bottom right, and bottom left vertices of the minimum bounding rectangle of the j-th text line in the second set, (x j ,y j ) represents the coordinates of the center point of the jth text line.
[0093] S302: Calculate the center point coordinates of all text lines in the second set L2, and select the text lines in the second set whose center point coordinates are in the line domain Q j The text line in the range; and will be located in the line field Q j The vertical coordinate of the center point of the text line in the range is changed to the text line l j The vertical coordinate y j , and sort the text lines according to the horizontal coordinates of the center points of the text lines, and record the center point coordinates of the text lines, the coordinate information of the four vertices of the minimum circumscribed rectangle, and the character information in a third set L3,
[0094] S303: remove text lines in the third set L3 from the second set L2;
[0095] S304: Repeat steps S301 to S303 until all text lines in the second set L2 are moved to the third set L3.
[0096] In a specific real-time scenario of the present invention, the third set L3 constructed after text line correction is expressed as:
[0097] {"center":(x0,y0),"points":[(x1,y1),(x2,y2),(x3,y3),(x4,y4)],"text":"Text line content"}, where center represents the coordinates of the center point of the text line, points represents the coordinates of the four vertices of the minimum circumscribed rectangle of the text line, corresponding to the upper left, upper right, lower right, and lower left vertices, and text represents the text information of the text line;
[0098] In a specific embodiment of the present invention, Figure 5 As shown, "construct the text line l j The row domain Q j "Includes, connect text lines l j The upper left corner vertex and the upper right corner vertex of the minimum circumscribed rectangle of the text line l j The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s1, connecting the text line l j The lower right corner vertex and the lower left corner vertex of the minimum circumscribed rectangle are used to enclose the text line l j The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s2, and the area enclosed by the lines s1, s2 and the left and right boundaries of the second subgraph is denoted as text line l j The row domain Q j .
[0099] In a specific embodiment of the present invention, performing text row and column correction based on the third set includes:
[0100] S305: Traverse the text lines in the third set, and for each text line l that is traversed k , where k∈[1,N], N is the number of text lines in the third set, according to the text line l k Get the text line l by using the coordinate information of the four vertices of the minimum bounding rectangle k The center point coordinates (x k ,y k ) and construct the column domain W k ;
[0101] S306: Filter out the text lines in the third set whose center points are located in column domain W k All text lines in the range will be located in column domain W k The horizontal coordinates of the center points of all text lines in the range are changed to text line l k The horizontal coordinate x of the center point k , and record which text lines have been modified;
[0102] S307: Repeat the process of S305 to S306, skipping the modified text lines recorded in S306, until the traversal process of the third set is completed.
[0103] In a specific embodiment of the present invention, "constructing column domain W K "Includes, connect text lines l k The upper left corner vertex and lower left corner vertex of the minimum circumscribed rectangle of the text line l k The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s3, connecting the text line l k The upper right corner vertex and the lower right corner vertex of the minimum circumscribed rectangle are k The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s4, and the area enclosed by the lines s3, s4 and the upper and lower boundaries of the second subgraph is denoted as text line l k The column domain W K .
[0104] In a specific implementation scenario of the present invention, the third set L3 after text row correction and text column correction is expressed as: [{"p":[1462,830],"t":"within medical insurance"},{"p":[1658,833],"t":"outside medical insurance"},{"p":[146,857],"t":"level II care"}];
[0105] Among them, p represents the coordinates of the center point of the text line, and t represents the text character information recognized by the OCR of the text line.
[0106] It should be noted that the vertical coordinates of the center points of the same row of text lines in the third set L3 are consistent, and the horizontal coordinates of the center points of the same column of text lines are consistent. The text lines with consistent vertical coordinates are sorted in sequence according to the values of the horizontal coordinates, and the text lines with consistent horizontal coordinates are sorted in sequence according to the values of the vertical coordinates.
[0107] S4: construct a prompt based on the third set, and use a large language model to obtain expense detail identification information.
[0108] In a specific embodiment of the present invention, "constructing a prompt" includes setting a task description: briefly describing the task that you want the model to perform; setting a context or example: providing context information related to the task or showing one or more examples to help the model understand how to parse the expense details; setting an input format description: detailing the format and structure of the input data so that the model can parse it correctly; setting a placeholder: reserving a place in the prompt template for inserting the actual expense detail data; setting an output format requirement: explicitly indicating the output format and structure that the model is expected to return.
[0109] In a specific implementation scenario of the present invention, the prompt data is constructed as follows: "Your current task is to extract the key information I specify from the results of OCR text recognition of the expense details image. The OCR text recognition results are surrounded by ``` symbols, including the recognized text and the coordinate information of the text in the image, and the order is from left to right and from top to bottom in the original image; examples of OCR text recognition results: [{"p":[1462,830],"t":"Inside medical insurance"},{"p":[1658,833],"t":"Outside medical insurance"}], where the value of p is the horizontal pixel coordinate and vertical pixel coordinate of the text, and t is the recognized text content. The key information I specify is surrounded by [] symbols; please note that OCR text recognition The results may have problems such as long sentences being cut off, unreasonable word segmentation, corresponding misalignment, multiple results being paginated, etc. You need to make a comprehensive judgment based on the context semantics and text coordinate information to extract accurate key information. When returning the results, use the json format, which contains a key-value pair. The key value is the key information I specify, the value value is the extracted result, and the value value is a string array. If it is believed that there is no key information key in the OCR recognition result, the value is assigned to "No relevant information found"; please only output the results in json format, and do not include other redundant text! Let's officially start: OCR text: ``````Key information to be extracted: [The data in the column where the medical insurance is located is 0.00. Details of expenses]"
[0110] In a specific embodiment of the present invention, "using a large language model to obtain expense detail identification information" includes placing the third set L3 into the constructed prompt template, enclosing it with ``` symbols, and sending the generated prompt data to the large language model LLM for model reasoning. LLM will analyze the input prompt, understand its context, and identify the positional relationship between each field. Based on context understanding and positional relationship analysis, LLM will try to extract the value of the target field, and output the extracted field value in the specified JSON format. The output result is the expense detail identification information.
[0111] It should be noted that the LLM large model adopts the Transformer architecture, especially the architecture based on the self-attention mechanism, which enables LLM to capture complex dependencies in language and generate high-quality natural language text. The advantages of this architecture lie in its parallel computing capabilities, long-distance dependency capture capabilities and interpretability, which enables the LLM large model to achieve remarkable results in the field of NLP.
[0112] In the second embodiment of the present invention, the present invention provides a method and system for identifying a detailed expense list based on OCR and LLM, such as Figure 6 As shown, the system comprises:
[0113] Image acquisition module: used to acquire the image to be processed;
[0114] Target detection module: used to detect the cost detail area of the image to be processed and capture the first sub-image;
[0115] OCR recognition module: used to perform OCR recognition on the first sub-image to obtain a first set; perform OCR recognition on the second sub-image to obtain a second set;
[0116] Correction processing module: used for performing horizontal correction on the first sub-image and row and column correction on the text lines in the second sub-image;
[0117] Large language model processing module: used to construct prompt data and use large language models to obtain expense detail identification information;
[0118] Output module: used to output the information extracted by the large language model processing module in a visual or editable format for users to view or use.
[0119] It should be noted that the image acquisition module is connected to the target detection module, and the acquired image data is transmitted to the target detection module; the target detection module is connected to the OCR recognition module, and the target area screenshot data is transmitted to the OCR recognition module; the output of the OCR recognition module is connected to the correction processing module, and the recognition result is passed to the correction processing module for correction; the output of the correction processing module is connected to the large language model processing module, and the corrected text position information and text content are sent to the LLM large model for analysis; the output of the large language model processing module is connected to the output module, and the extracted information is output to the user interface.
[0120] In a third embodiment of the present invention, the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the program is executed on the processor, the steps in the method for identifying an expense list based on OCR and LLM as described in any one of the above items are implemented.
[0121] In a fourth embodiment of the present invention, the present invention provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps in the method for identifying an expense list based on OCR and LLM as described in any one of the above items.
[0122] In summary, the expense list recognition method based on OCR and LLM provided by the present invention significantly improves the accuracy of text recognition under complex conditions and also improves the text recognition accuracy through multi-stage image processing and OCR text recognition optimization; introduces a large language model to enable the ability to understand spatial position relationships, realizes an intelligent leap from text data to specific information extraction, reduces manual intervention, and improves efficiency; the present invention can effectively process medical expense list pictures of different sources and qualities, and enhances the flexibility and versatility of the system in practical applications; through algorithm optimization, the processing time is shortened, while the reliability of data extraction is guaranteed, providing an efficient tool for medical expense management.
[0123] It should be understood that although this specification is described according to implementation modes, not every implementation mode contains only one independent technical solution. This description of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each implementation mode may also be appropriately combined to form other implementation modes that can be understood by those skilled in the art.
[0124] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the modules described above can refer to the corresponding process in the aforementioned method implementation, and will not be repeated here.
[0125] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present implementation scheme.
[0126] In addition, each functional module in each embodiment of the present application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0127] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for a computer system (which can be a personal computer, a server, or a network system, etc.) or a processor to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program codes.
[0128] Finally, it should be noted that the above implementation modes are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned implementation modes, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned implementation modes, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various implementation modes of the present application.
Claims
1. A method for recognizing detailed expense lists based on OCR and LLM, characterized in that: include, Collecting an image to be processed, detecting a cost detail area of the image to be processed and capturing a first sub-image; Using OCR to identify the first sub-image to obtain a first set, constructing an affine transformation matrix based on the first set to perform horizontal correction on the image, and obtaining a second sub-image after horizontal correction; Recognize the second sub-image by OCR to obtain a second set, perform row and column correction on the text lines in the second sub-image based on the second set, and the corrected text line information constitutes a third set; A prompt is constructed based on the third set, and expense detail identification information is acquired using a large language model.
2. The method for recognizing detailed expense list based on OCR and LLM according to claim 1, characterized in that: The target detection model is used to detect the fee detail area in the image to be processed, and the image to be processed is intercepted according to the boundary box in the detection result to generate a first sub-image containing only the fee detail area.
3. The method for identifying detailed expense list based on OCR and LLM according to claim 1, characterized in that: The using OCR to identify the first sub-image / the second sub-image to obtain the first set / the second set comprises: Perform text recognition on the first sub-image / the second sub-image using OCR recognition to obtain position information of the minimum bounding rectangle of the text line and a text content recognition result, and store the position information of the minimum bounding rectangle of the text line and the text content in the first set / the second set.
4. The method for recognizing detailed expense list based on OCR and LLM according to claim 1, characterized in that: The constructing an affine transformation matrix based on the first set includes: Select the longest text line in the first set, calculate the inclination angle θ of the longest text line according to the coordinate information of the four vertices of the minimum circumscribed rectangle of the longest text line, and use the inclination angle θ as the inclination angle of the first subgraph. c ,y c ) as the rotation center, the tilt angle θ as the rotation angle, and construct the affine transformation matrix M; The calculation formula of the tilt angle θ is expressed as: The affine transformation matrix M is expressed as: Among them, θ represents the tilt angle, (x1, y1), (x2, y2) represent the coordinates of the upper left corner vertex and the upper right corner vertex of the minimum bounding rectangle of the longest text line; M represents the affine transformation matrix, (x c ,y c ) are the coordinates of the center point of the first sub-graph.
5. The method for recognizing detailed expense list based on OCR and LLM according to claim 1 or 3, characterized in that: The performing horizontal correction of the picture and obtaining the second sub-picture after the horizontal correction includes: Use the affine transformation matrix M to perform affine transformation on the first sub-image to obtain a candidate sub-image after horizontal correction; determine whether the candidate sub-image is positive, if the candidate sub-image is positive, use the candidate sub-image as the second sub-image; if the candidate sub-image is inverted, rotate the candidate sub-image 180° around the center point of the image to obtain the second sub-image; The affine transformation is expressed as: Where M is the affine transformation matrix, (X i ,Y i ) is the coordinate of the i-th pixel in the first sub-image, is the coordinate of the i-th pixel after affine transformation.
6. The method for recognizing detailed expense list based on OCR and LLM according to claim 1, characterized in that: The performing line correction on the text line in the second sub-image comprises: S31: Traverse the text lines in the second set, and for each text line l that is traversed j , according to the text line l j The minimum bounding rectangle of the text line l is calculated by using the coordinate information of the four vertices j The center point coordinates (x j ,y j ), text line l j Height h j , text line j The tilt angle α j , and construct the text line l j The row domain Q j ; S32: Calculate the center point coordinates of all text lines in the second set, and select the text lines in the second set whose center point coordinates are in the line range Q. j All text lines in the range; and will be located in the line field Q j The vertical coordinates of the center point coordinates of all text lines in the range are changed to text line l j The y-coordinate j , then sort the text lines with the same center point ordinates in ascending order according to the horizontal coordinates of the center points of the text lines, and record the changed center point coordinates of the text lines, the coordinates of the four vertices of the minimum circumscribed rectangle of the text lines, and the character information recognized by OCR in a third set; S33: removing the text lines in the third set from the second set; S34: repeating steps S31 to S33 until all text lines in the second set are moved to the third set; The constructed text line l j The row domain Q j Include: Connect text lines j The upper left corner vertex and the upper right corner vertex of the minimum circumscribed rectangle of the text line l j The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s1, connecting the text line l j The lower right corner vertex and the lower left corner vertex of the minimum circumscribed rectangle are used to enclose the text line l j The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s2, and the area enclosed by the lines s1, s2 and the left and right boundaries of the second subgraph is denoted as text line l j The row domain Q j .
7. The method for recognizing detailed expense list based on OCR and LLM according to claim 6, characterized in that: The text line l j The center point coordinates (x j ,y j ) The calculation formula is expressed as: The text line l j Height h j The calculation formula is expressed as: The text line l j Tilt angle α j The calculation formula is expressed as: Among them, j∈[1,N], N is the number of text lines in the second set, (x j1 ,y j1 ),(x j2 ,y j2 ),(x j3 ,y j3 ) represents the coordinates of the top left, top right, and bottom right vertices of the minimum bounding rectangle of the j-th text line in the second set, (x j ,y i ) represents the coordinates of the center point of the jth text line.
8. The method for recognizing detailed expense list based on OCR and LLM according to claim 1 or 5, characterized in that: The column correction of the text line in the second sub-image comprises: S35: Traverse the text lines in the third set, and for each text line l that is traversed k , where k∈[1,N], N is the number of text lines in the third set, according to the text line l k Get the text line l by using the coordinate information of the four vertices of the minimum bounding rectangle k The center point coordinates (x k ,y k ) and construct the column domain W k ; S36: Filter out the text lines in the third set whose center points are located in column domain W k All text lines in the range will be located in column domain W k The horizontal coordinates of the center points of all text lines in the range are changed to text line l k The horizontal coordinate x of the center point k , and mark the modified text lines; S37: repeat the process of S35 to S36, skipping the text line marked in S36, until the traversal process of the third set is completed; The constructed column domain W k Include: Connect text lines k The upper left corner vertex and lower left corner vertex of the minimum circumscribed rectangle of the text line l k The straight line containing the upper left and upper right corner vertices of the minimum circumscribed rectangle is denoted as s3, connecting the text line l k The upper right corner vertex and the lower right corner vertex of the minimum circumscribed rectangle are k The line containing the lower left and right corner vertices of the minimum circumscribed rectangle is denoted as s4, and the area enclosed by the lines s3, s4 and the upper and lower boundaries of the second subgraph is denoted as text line l k The column domain W K .
9. The method for recognizing detailed expense list based on OCR and LLM according to claim 1, characterized in that: The step of constructing a prompt based on the third set and obtaining expense detail identification information using a large language model includes: A prompt is constructed based on the coordinates of the center point of the text line in the third set and the character information recognized by OCR, including setting a task description, providing contextual information or display related to the task, setting an input format, setting a placeholder, setting output format requirements, inputting the constructed prompt into a large language model for context understanding and position relationship analysis, extracting cost detail identification information, and outputting the result.
10. An expense list recognition system based on OCR and LLM, characterized by: include, Image acquisition module: used to acquire the image to be processed; Target detection module: used to detect the cost detail area of the image to be processed and capture the first sub-image; OCR recognition module: used to perform OCR recognition on the first sub-image to obtain a first set; perform OCR recognition on the second sub-image to obtain a second set; Correction processing module: used for performing horizontal correction on the first sub-image and row and column correction on the text lines in the second sub-image; Large language model processing module: used to build prompts and use large language models to obtain expense detail identification information; The image acquisition module is connected to the target detection module, and transmits the acquired image data to the target detection module; the target detection module is connected to the OCR recognition module, and transmits the target area screenshot data to the OCR recognition module; the output of the OCR recognition module is connected to the correction processing module, and the recognition result is passed to the correction processing module for correction; the output of the correction processing module is connected to the large language model processing module, and the corrected text position information and text content are sent to the large language model for analysis, and the target information is output.
Citation Information
Patent Citations
Image tilt correction method and device, electronic equipment and storage medium
CN111260569A
Picture information structuring method and device, equipment and medium
CN113850208A
Enterprise information auditing method and system based on image recognition and big data
CN117523569A
Multi-modal Web information retrieval static sorting learning method, system, equipment and medium
CN117828216A
OCR key information extraction method and model for medical bills
CN117831043A
Cited By
Method and framework for optimizing scanning copy content recognition quality by using large model
CN120689894A
