Intelligent OCR (Optical Character Recognition) data extraction method, equipment and medium

By combining color threshold watermark removal and dynamic ROI positioning with multi-threaded processing, the accuracy and efficiency issues of OCR technology in complex PDF documents are solved, achieving efficient extraction of structured information and improving the system's flexibility and traceability.

CN121010980APending Publication Date: 2025-11-25INSPUR ZHUOSHU BIG DATA IND DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510982761.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-16
Publication Date
2025-11-25

AI Technical Summary

Technical Problem

Existing OCR technologies suffer from problems such as watermark interference, inefficient region localization, performance bottlenecks, and insufficient structured extraction when processing complex PDF documents, making it difficult to achieve high-precision, low-latency automated and large-scale processing.

Method used

A vectorized watermark removal technique based on color thresholds is adopted, combined with dynamic ROI region localization and a multi-threaded asynchronous processing framework. The Paddle OCR model is used for recognition, and the results are output in JSON format through a structured data extraction model.

Benefits of technology

It improves the accuracy of OCR recognition, increases processing efficiency, reduces storage costs, enhances system flexibility and traceability, supports custom ROI coordinates and watermark color thresholds, and adapts to the document processing needs of different industries.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121010980A_ABST
    Figure CN121010980A_ABST
Patent Text Reader

Abstract

The invention discloses an intelligent OCR data extraction method and device and a medium, and belongs to the technical field of information processing. The method comprises the steps of receiving a to-be-processed PDF document uploaded by a user, and performing initialization processing on the to-be-processed PDF document; converting the to-be-processed PDF document into a high-resolution image, removing a watermark based on a color threshold value, and intercepting an ROI region corresponding to key information according to a preset coordinate; calling a Paddle OCR (Optical Character Recognition) model to recognize the ROI, and returning an original recognition result containing textbox coordinates, a recognition text and confidence; and post-processing the original identification result, and outputting a JSON format identification result. According to the method, watermark removal and ROI accurate positioning are achieved, interference factors in the to-be-processed PDF document recognition process are reduced, the key information recognition accuracy is remarkably improved, meanwhile, high-concurrency document processing is conducted through a multi-thread parallel framework, document processing efficiency and processing performance are improved, and document processing time consumption is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of information processing, and in particular to an intelligent OCR data extraction method, device and medium. BACKGROUND

[0002] With the acceleration of digitalization, PDF documents have become an important carrier for information storage and exchange. However, the existing optical character recognition (OCR) technology has the following problems when processing complex PDF documents:

[0003] Watermark interference: Watermarks in PDF documents can reduce the accuracy of OCR recognition. Traditional methods rely on manual annotation or fixed threshold processing, and have poor generalization ability;

[0004] Low efficiency of region positioning: Key information such as certificate number and management number is usually located in a fixed region of the document, but existing technologies are difficult to dynamically adapt to the positioning needs of different format documents;

[0005] Performance bottleneck: When processing large-scale PDF documents, the synchronous processing mode leads to high resource occupation and slow response speed;

[0006] Insufficient structured extraction: The results of OCR recognition are mostly unstructured text, and lack intelligent analysis capabilities for specific fields such as approval date and name.

[0007] In summary, although the existing solutions can partially solve the above problems, it is difficult to achieve automatic and large-scale processing while ensuring high precision and low delay. SUMMARY

[0008] The present application provides an intelligent OCR data extraction method, device and medium to solve at least one of the above technical problems.

[0009] The present application adopts the following technical solutions:

[0010] In a first aspect, the present application provides an intelligent OCR data extraction method, which includes receiving a user-uploaded PDF document to be processed and performing initialization processing on the PDF document to be processed; converting the PDF document to be processed into a high-resolution image and removing watermarks based on a color threshold while cutting out an ROI region corresponding to key information according to a preset coordinate; calling a Paddle OCR model to recognize the ROI region and returning an original recognition result containing text box coordinates, recognized text and confidence; and performing post-processing on the original recognition result and outputting a JSON format recognition result.

[0011] In a possible implementation of the present application, the method for processing a PDF document uploaded by a user comprises the following steps: receiving the PDF document uploaded by the user through a document uploading interface built by a Fast API framework, wherein the document uploading interface comprises at least an HTTP interface; verifying the file format of the PDF document, and generating a unique request identifier for the PDF document after the verification; reading binary data of the PDF document through an Upload File component to complete initialization acquisition of the PDF document.

[0012] In a possible implementation of the present application, the high-resolution image is a color image; the watermark is removed based on a color threshold, comprising the following steps: converting the color image into a grayscale image through a cv2 library; defining a watermark color range threshold, and screening out a watermark region through a vectorization logical mask algorithm; setting pixel values of the watermark region to pure white to complete elimination of the watermark region.

[0013] In a possible implementation of the present application, before intercepting the ROI region, the method further comprises the following step: customizing the preset coordinates according to the layout of the PDF document to be processed by setting a parameter ROI_COORDINATES.

[0014] In a possible implementation of the present application, after intercepting the ROI region, the method further comprises the following steps: performing noise reduction processing and contrast enhancement processing on the image of the intercepted ROI region.

[0015] In a possible implementation of the present application, before calling the Paddle OCR model to recognize the ROI region, the method further comprises the following steps: creating a thread pool through a Thread Pool Executor; configuring the size of the thread pool by setting a value of a parameter THREAD_POOL_SIZE; and distributing the image of the ROI region to different thread pools for parallel processing.

[0016] In a possible implementation of the present application, the post-processing of the original recognition result comprises the following steps: merging adjacent text boxes based on Y values of the text box coordinates; extracting a target field from the merged text according to a preset mapping field; and parsing the target field to return a recognition result in a JSON format.

[0017] In a possible implementation of the present application, after obtaining the recognition result in the JSON format, the method further comprises the following steps: storing the recognition result in the JSON format to a special database or returning the recognition result to the user; and recording a recognition log through a Rotating FileHandler.

[0018] Secondly, this application also provides an intelligent OCR data extraction device, the device comprising: 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 to enable the at least one processor to perform: receiving a PDF document uploaded by a user and performing initialization processing on the PDF document; converting the PDF document into a high-resolution image and removing the watermark based on a color threshold, while simultaneously cropping the ROI region corresponding to key information according to preset coordinates; calling the Paddle OCR model to recognize the ROI region and returning an original recognition result containing text box coordinates, recognized text, and confidence score; and post-processing the original recognition result to output a recognition result in JSON format.

[0019] Thirdly, this application also provides a non-volatile computer storage medium storing computer-executable instructions configured to execute: receiving a PDF document uploaded by a user and performing initialization processing on the PDF document; converting the PDF document into a high-resolution image and removing the watermark based on a color threshold, while simultaneously cropping the ROI region corresponding to key information according to preset coordinates; calling the Paddle OCR model to recognize the ROI region and returning an original recognition result containing text box coordinates, recognized text, and confidence score; and post-processing the original recognition result to output a recognition result in JSON format.

[0020] The intelligent OCR data extraction method, device, and medium provided in this application have the following beneficial effects:

[0021] Improve recognition accuracy: By vectorized watermark removal and precise ROI positioning, interference factors are reduced, resulting in a significant improvement in the accuracy of key information recognition.

[0022] Improved processing efficiency: The multi-threaded parallel architecture supports high-concurrency document processing, and the average processing time per file is reduced to a level far lower than that of traditional single-threaded methods;

[0023] Reduce storage costs: Structured output reduces invalid data storage, and combined with a log rolling mechanism, storage space usage is reduced;

[0024] Enhanced system flexibility: Supports customizable ROI coordinates, watermark color thresholds, and field mapping rules to adapt to document processing needs across different industries;

[0025] Enhanced traceability: Full-process UUID tracking and detailed logging improve system stability and troubleshooting efficiency. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:

[0027] Figure 1 A flowchart of an intelligent OCR data extraction method provided in this application;

[0028] Figure 2 This is a schematic diagram of the structure of an intelligent OCR data extraction device provided in this application. Detailed Implementation

[0029] To enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this specification, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this application.

[0030] This application proposes an intelligent OCR data extraction method, device, and medium, aiming to solve at least one of the technical problems described in the background art through the following innovations:

[0031] Vectorized watermark removal technology based on color threshold improves OCR recognition accuracy in complex backgrounds;

[0032] By using a dynamic region positioning ROI mechanism, key information regions are adaptively extracted.

[0033] Utilize a multi-threaded asynchronous processing framework to optimize resource utilization and concurrency performance;

[0034] A structured data extraction model, combining text merging rules and field mapping strategies, achieves high-precision information extraction.

[0035] In other words, this application specifically provides an intelligent data extraction method that combines image processing, optical character recognition (OCR) technology, and asynchronous task scheduling, which is particularly suitable for the efficient extraction of structured information from watermarked PDF documents. It features high accuracy, fast processing efficiency, and strong flexibility, reducing manual processing costs and improving the automation level of document digitization.

[0036] The method in this application will be described in detail below with reference to the accompanying drawings.

[0037] Figure 1A flowchart of an intelligent OCR data extraction method provided in this application is shown below. Figure 1 As shown, the intelligent OCR data extraction method in this application includes at least the following execution steps:

[0038] Step 101: Receive the PDF document uploaded by the user and perform initialization processing on the PDF document.

[0039] In one possible implementation of this application, a file upload interface built using the Fast API framework allows users to upload PDF documents they want to recognize. After receiving the uploaded PDF document, the system needs to verify the file format of the uploaded document, allowing only PDF files or documents to be processed. Once the verification is successful, a unique request ID is generated for the uploaded PDF document for end-to-end tracking.

[0040] Furthermore, the binary data of the PDF document to be processed is read through the Upload File component, mainly using the pdf_bytes function of the Upload File component, thereby completing the initial acquisition of the PDF document data to be processed.

[0041] Step 102: Convert the PDF document to be processed into a high-resolution image, remove the watermark based on the color threshold, and extract the ROI region corresponding to the key information according to the preset coordinates.

[0042] This step involves two processes: removing the watermark and cropping the ROI region.

[0043] For the watermark removal process, a vectorized logical mask algorithm is used. Specifically, the first page of the PDF document to be processed is first converted into a high-resolution image, for example, setting its DPI to 300. It should be noted that this high-resolution image is a color image. Then, the color image is converted to a grayscale image using the cv2 library. In the grayscale image, the watermark color range threshold is defined by setting the value of the WATEMARK_COLOR_RANGE parameter, for example, configuring WATEMARK_COLOR_RANGE = (70, 200). Then, the watermark area is filtered out using a logical mask, and the pixel values ​​of the watermark area are set to pure white, for example, setting the pixel values ​​of the watermark area to [255, 255, 255] to achieve lossless watermark removal. In this process, the process of filtering out the watermark area using a logical mask can be implemented using existing algorithms or procedures, which will not be elaborated in this implementation.

[0044] Finally, to determine the image clarity after watermark removal, the image was rendered at high resolution. Specifically, the PyMu PDF library was used to parse the first page of the PDF at 300 DPI to ensure image clarity.

[0045] Furthermore, regarding the ROI (Region of Interest) extraction process, the ROI is first located using a custom coordinate parameter ROI_COORDINATES. For example, configuring ROI_COORDINATES = (1720, 900, 2597, 1647) allows for the precise extraction of a rectangular region containing key information. Then, the coordinate parameters (x1, y1, x2, y2) are parsed to extract the ROI region image. This process supports user-defined ROI parameters to adapt to different document layouts. After extracting the ROI region, noise reduction and contrast enhancement are performed on the corresponding image to improve the accuracy of subsequent OCR recognition.

[0046] This step allows you to remove watermarks from PDF documents and accurately extract ROI regions containing key information.

[0047] In one example, the key information in the above process could be the text portion of the PDF document to be processed.

[0048] Step 103: Call the Paddle OCR model to identify the ROI region and return the raw recognition result containing the text box coordinates, the recognized text, and the confidence score.

[0049] After the ROI region is extracted, which is actually the ROI image, the recognition process for this ROI image is as follows:

[0050] A parallel processing framework is built by using Thread Pool Executor, and multiple thread pools of fixed or preset size are created by configuring the THREAD_POOL_SIZE parameter value. For example, if THREAD_POOL_SIZE=10 is configured, the ROI images extracted in the previous process are distributed to different thread pools for parallel processing. This enables the simultaneous recognition of key information in multiple ROI images, improves the recognition efficiency of OCR, and enables high-concurrency document processing.

[0051] Furthermore, during the recognition of the ROI image, the Paddle OCR deep learning model is invoked, such as paddleocr.Paddle OCR, to perform text detection and recognition on the ROI image. This model supports Chinese character classification (lang = "ch") and angle correction (use_angle_cls = True). After recognition, the raw recognition result containing the text box coordinates, recognized text, and confidence score is returned. It should be noted that the process of using a deep learning model to identify key information in the ROI image can be implemented using existing processes, which will not be elaborated upon in this implementation.

[0052] Step 104: Post-process the original recognition results and output the recognition results in JSON format.

[0053] After obtaining the raw recognition results, this application will not output them directly. Instead, they will undergo the following post-processing steps before obtaining the recognition results in JSON format. Specifically, the post-processing steps are as follows:

[0054] Text box merging: Based on the text box coordinates output in the previous steps, and according to the Y-axis coordinate threshold, such as y_threshold=10, adjacent or neighboring text boxes are merged to eliminate the line break segmentation problem in the recognition results and reduce fragmented results;

[0055] Structured parsing: Based on preset field mappings, such as "level" → "level" and "ID number" → "idCard", special information is extracted from the merged text;

[0056] Result filtering: Only retain the corresponding information of the target fields, such as level, approvalDate, managementNumber, etc., and generate structured JSON output.

[0057] In one possible implementation of this application, before performing the aforementioned structured parsing, a field mapping configuration process is also included, allowing users to customize the correspondence between Chinese tags and structured fields, such as “approval date” → “approvalDate”.

[0058] In one possible implementation of this application, after obtaining the respective recognition results in JSON format, the recognition results are stored in a dedicated database or returned to the user. The recognition process is logged, specifically using RotatingFileHandler to implement rolling log recording, storing request details, processing time, exception information, etc., facilitating system monitoring and problem tracing. During log recording, to achieve rolling recording, temporary files are automatically cleaned up, such as user-input PDF documents to be processed and intermediate images generated during the recognition process, avoiding storage redundancy.

[0059] Furthermore, this application is also equipped with a global anomaly capture mechanism, which can compensate for errors in scenarios such as incorrect file format during OCR recognition and OCR failure, and return standardized error codes for maintenance personnel to perform maintenance.

[0060] Based on the same inventive concept, this application also provides an intelligent OCR data extraction device, the structure of which is as follows: Figure 2 As shown.

[0061] Figure 2 This is a schematic diagram of the structure of an intelligent OCR data extraction device provided in this application. Figure 2 As shown, the intelligent OCR data extraction device 200 in this application specifically includes: at least one processor 201; and a memory 203 communicatively connected to at least one processor 201 (connected via a bus 202); wherein the memory 203 stores instructions executable by at least one processor 201 to enable at least one processor 201 to execute an intelligent OCR data extraction method as described in any of the above implementations.

[0062] In one possible implementation of this application, the aforementioned processor is configured to: receive a PDF document uploaded by a user and perform initialization processing on the PDF document; convert the PDF document into a high-resolution image and remove the watermark based on a color threshold, while simultaneously cropping the ROI region corresponding to key information according to preset coordinates; call the Paddle OCR model to recognize the ROI region and return the original recognition result containing text box coordinates, recognized text, and confidence score; and post-process the original recognition result to output the recognition result in JSON format.

[0063] In addition, this application also provides a non-volatile computer storage medium storing computer-executable instructions configured to execute an intelligent OCR data extraction method as described in any of the above implementations.

[0064] In one possible implementation of this application, the aforementioned computer-executable instructions are configured to execute: receive a PDF document uploaded by a user and perform initialization processing on the PDF document; convert the PDF document into a high-resolution image and remove the watermark based on a color threshold, while simultaneously cropping the ROI region corresponding to key information according to preset coordinates; call the Paddle OCR model to recognize the ROI region and return the original recognition result containing text box coordinates, recognized text, and confidence score; perform post-processing on the original recognition result and output the recognition result in JSON format.

[0065] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0066] The equipment and method provided in this application are one-to-one correspondences. Therefore, the equipment also has similar beneficial technical effects as its corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the equipment will not be repeated here.

[0067] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.

[0068] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0069] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for intelligent OCR data extraction, characterized in that, The method includes: Receive the PDF document uploaded by the user and perform initialization processing on the PDF document; The PDF document to be processed is converted into a high-resolution image, and the watermark is removed based on a color threshold. At the same time, the ROI region corresponding to the key information is cropped according to preset coordinates. The Paddle OCR model is invoked to identify the ROI region, and the raw recognition result containing the text box coordinates, the recognized text, and the confidence score is returned. The original recognition results are post-processed to output recognition results in JSON format.

2. The intelligent OCR data extraction method according to claim 1, characterized in that, Receive user-uploaded PDF documents to be processed, including: The document upload interface built using the Fast API framework is used to receive PDF documents uploaded by users and to be processed. The document upload interface includes at least an HTTP interface. Next, the file format of the PDF document to be processed is verified, and a unique request identifier is generated for the PDF document to be processed after the verification is successful. The binary data of the PDF document to be processed is read by the Upload File component to complete the initial acquisition of the PDF document to be processed.

3. The intelligent OCR data extraction method according to claim 1, characterized in that, The high-resolution image is a color image; Watermark removal based on color thresholds includes: Convert a color image to a grayscale image using the cv2 library; Define a threshold for the watermark color range and filter out the watermark area using a vectorized logical mask algorithm; Set the pixel values ​​of the watermark area to pure white to complete the removal of the watermark area.

4. The intelligent OCR data extraction method according to claim 1, characterized in that, Before truncating the ROI region, the method further includes: Based on the layout of the PDF document to be processed, the preset coordinates are customized by setting the parameter ROI_COORDINATES.

5. The intelligent OCR data extraction method according to claim 1, characterized in that, After extracting the ROI region, the method further includes: The image of the captured ROI region is subjected to noise reduction and contrast enhancement processing.

6. The intelligent OCR data extraction method according to claim 1, characterized in that, Before calling the Paddle OCR model to identify the ROI region, the method further includes: Create a thread pool using Thread Pool Executor; The size of the thread pool can be configured by setting the value of the parameter THREAD_POOL_SIZE; The images of the ROI region are assigned to different thread pools for parallel processing.

7. The intelligent OCR data extraction method according to claim 1, characterized in that, Post-processing of the original recognition results includes: Based on the Y value of the text box coordinates, adjacent text boxes are merged; Extract the target field from the merged text based on the preset mapping fields; The target field is parsed, and the recognition result is returned in JSON format.

8. The intelligent OCR data extraction method according to claim 1, characterized in that, After obtaining the recognition result in JSON format, the method further includes: The recognition results in JSON format are stored in a dedicated database or returned to the user; The identification log is recorded using the Rotating File Handler.

9. An intelligent OCR data extraction device, characterized in that, The device includes: 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 to enable the at least one processor to perform an intelligent OCR data extraction method according to any one of claims 1-8.

10. A non-volatile computer storage medium storing computer-executable instructions thereon, characterized in that, The computer-executable instructions are configured to execute an intelligent OCR data extraction method according to any one of claims 1-8.