Scanned document trimming system and method
By introducing document type recognition and multi -level accuracy tailoring modules in the scanning document cutting system, dynamically adjust the number of tailoring parameters, solve the problem of inaccurate cutting of the existing system, and achieve higher tailoring accuracy and adaptability, improved the improvement, improved User experience and document processing efficiency.
Patent Information
- Application Number
- CN202411001464.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-07-25
AI Technical Summary
The existing scanning document edge trimming system lacks intelligence and adaptability, and it is impossible to effectively identify different types of documents, resulting in poor cutting effects and prone to missed or omissions, affecting user experience and document processing efficiency.
Design a system that includes image capture modules, edge detection modules, document type recognition modules, and multi -level accuracy tailoring modules. By identifying the type of documentation and detecting the edge of the documentation Essence
A higher cutting accuracy and adaptability have been achieved, the content of the document is complete and the edges are clear, the user experience and document processing efficiency are improved, and the user's custom output format and OCR recognition function supports users.
Smart Images

Figure CN118540418B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a scanned document trimming system and method. Background Art
[0002] Scanned document trimming systems usually rely on basic image processing algorithms and simple edge detection techniques to achieve the trimming function. These systems usually include an image capture module to obtain the initial image of the document to be scanned, and then use edge detection algorithms to identify the document edges and finally trim the required document area.
[0003] The main problem in the existing technologies is that their trimming systems are not intelligent and adaptive enough. These systems cannot effectively identify different types of documents, and thus cannot automatically adjust the trimming parameters according to the specific characteristics of the documents and the personalized needs of users. In addition, when processing images with complex backgrounds or a lot of noise, the existing systems have poor trimming effects and are prone to mis-trimming or omissions, affecting the user experience and document processing efficiency.
[0004] Therefore, there is an urgent need to develop a system and method for trimming scanned documents. Summary of the invention
[0005] The present application provides a scanned document trimming system and method to improve the efficiency and accuracy of document trimming.
[0006] The present application provides a scanning document trimming system, comprising:
[0007] An image capture module, used for acquiring an initial image of a document to be scanned;
[0008] an edge detection module, in communication with the image capture module, for identifying and detecting document edges in the initial image;
[0009] a document type recognition module, communicating with the edge detection module, for identifying the document type in the initial image;
[0010] a multi-level precision trimming module, communicating with the document type recognition module and the edge detection module, and used to determine trimming parameters based on the recognized document type, the detected document edge, and the user's preference settings; trimming the document area in the initial image according to the determined trimming parameters to remove the non-document area; wherein the trimming parameters include a trimming margin, a trimming area shape, a trimming area size, and a trimming precision level; and the user's preference settings include an output format of the trimmed document and whether the trimmed document supports an OCR recognition function;
[0011] An output module communicates with the multi-level precision trimming module and is used for outputting the trimmed document.
[0012] The present application provides a method for trimming a scanned document, comprising:
[0013] Acquire an initial image of the document to be scanned;
[0014] identifying and detecting document edges in the initial image;
[0015] identifying a document type in the initial image;
[0016] Determining cropping parameters based on the identified document type, the detected document edge, and user preferences, wherein the cropping parameters include a cropping margin, a cropping region shape, a cropping region size, and a cropping precision level, and the user preferences include an output format of the cropped document and whether the cropped document supports an OCR recognition function;
[0017] Cropping the document area in the initial image according to the determined cropping parameters to remove the non-document area;
[0018] Output the cropped document.
[0019] The beneficial effects of the present application mainly include: (1) The system automatically adjusts the cropping parameters, such as the cropping margin, cropping area shape and cropping area size, according to the document type and edge detection results through a multi-level precision trimming module, thereby achieving higher cropping accuracy and ensuring that the document content is complete and the edges are clear. (2) The document type recognition module can automatically identify the document type in the initial image, enabling the system to dynamically adjust the cropping strategy according to different types of documents (such as invoices, ID cards, contracts, etc.), thereby improving the adaptability and effect of trimming. (3) Users can customize the output format (such as PDF, JPEG) of the cropped document and whether to support the OCR recognition function through preference settings to meet personalized needs. This customization function enhances the user experience and makes the system more flexible and practical. (4) Through automated edge detection and document type recognition, the system can quickly and accurately complete the trimming task, reducing the time and workload of manual adjustment and greatly improving document processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 It is a schematic diagram of a trimming system for scanning documents provided in the first embodiment of the present application.
[0021] Figure 2 This is a flow chart of a method for trimming a scanned document provided in the second embodiment of the present application. DETAILED DESCRIPTION
[0022] Many specific details are described in the following description to facilitate a full understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of the present application, so the present application is not limited by the specific implementation disclosed below.
[0023] The first embodiment of the present application provides a system for trimming the edges of scanned documents. Figure 1 , which is a schematic diagram of the first embodiment of the present application. Figure 1 A first embodiment of the present application provides a scanned document trimming system which is described in detail.
[0024] The scanned document trimming system comprises an image capturing module 101 , an edge detecting module 102 , a document type identifying module 103 , a multi-level precision trimming module 104 and an output module 105 .
[0025] The image capturing module 101 is used to obtain an initial image of the document to be scanned.
[0026] The image capture module 101 is one of the core components of the trimming system, and is used to obtain the initial image of the document to be scanned. The module can be composed of hardware and software parts, wherein the hardware part includes a high-resolution image sensor, a light source, an optical lens, and a control circuit, and the software part includes image acquisition software and a driver.
[0027] First, image sensors can use CCD (charge-coupled device) or CMOS (complementary metal oxide semiconductor) technology. These sensors can capture high-quality, high-resolution images to ensure that every detail of the scanned document is accurately recorded. The resolution of image sensors is usually between 300 DPI and 1200 DPI, which can be adjusted according to specific application requirements. High-resolution sensors can capture more delicate images, which is crucial for subsequent edge detection and cropping processes.
[0028] The light source usually uses LED light source, and the selection and configuration of the light source has an important impact on the image quality. LED light source has the characteristics of high brightness, low power consumption and long life, and can provide stable and uniform lighting to avoid image distortion caused by uneven light. The position and angle of the light source are carefully designed to ensure that the document surface is evenly illuminated, thereby reducing the impact of shadows and reflections on image quality.
[0029] Optical lenses are used to focus document images onto image sensors. The quality and design of optical lenses directly affect the clarity and distortion of images. Lens systems usually contain multiple groups of lenses. Through precise optical design and manufacturing, clear images can be obtained throughout the field of view. The focal length and aperture size of the lens are also selected and adjusted according to specific application requirements.
[0030] The control circuit is responsible for the overall operation of the image capture module, including the driving of the image sensor, the control of the light source, and the acquisition and transmission of image data. The control circuit is usually composed of a microcontroller (MCU) or a digital signal processor (DSP), which can quickly process and transmit large amounts of image data to ensure efficient operation of the system.
[0031] The software part includes image acquisition software and driver. The image acquisition software is responsible for controlling the image capture process, including parameters such as image exposure time, gain control, and white balance adjustment. These parameters can be automatically adjusted according to different document types and scanning environments to obtain the best image quality. The driver is responsible for communicating with the operating system and other modules to ensure that the image data can be smoothly transmitted to the edge detection module 102 and the document type recognition module 103.
[0032] The working process of the image capture module 101 is as follows: when the user places the document to be scanned in the scanning area and the system is started, the light source is first turned on to provide uniform illumination for the document. Subsequently, the image sensor starts to capture the image and focuses the document image onto the sensor through the optical lens. The control circuit receives and processes the image data captured by the image sensor, and optimizes the image through the image acquisition software to finally generate high-quality initial image data. The initial image data is transmitted to the edge detection module 102 through the driver program to provide a basis for subsequent edge recognition and trimming operations.
[0033] Through the coordinated work of the above hardware and software, the image capture module 101 can efficiently and accurately obtain the initial image of the document to be scanned, providing a solid foundation for the efficient operation of the entire trimming system.
[0034] Furthermore, the image capture module includes a high-resolution image sensor and an autofocus system to ensure that the acquired initial image has clear edges and high-quality image details.
[0035] Specifically, the image capture module provides excellent image capture capabilities through the combination of high-resolution image sensors and autofocus systems, thus providing a reliable data basis for subsequent trimming processing.
[0036] The high-resolution image sensor is one of the core components of the image capture module. It uses advanced photosensitive element technology to capture more pixel information, making the initial image acquired with extremely high clarity and detail expression. This is essential for accurately identifying the edges and features of documents. The working principle of the high-resolution sensor is to convert light signals into electrical signals, and digitize these signals through the internal image processing unit to generate high-resolution image data. Specifically, when a document is placed in the scanning area, the image sensor captures the entire image of the document, including its edges and internal details, and outputs it in the form of a digital image.
[0037] At the same time, the autofocus system ensures the clarity of the image under different scanning conditions. The autofocus system works through a closed-loop control system to adjust the distance between the image sensor and the document in real time to obtain the best focus position. The system usually includes a focus motor, a focus lens, and a control circuit. The focus control circuit controls the focus motor to adjust the lens position by analyzing the image clarity feedback signal until the image reaches the clearest state. This autofocus mechanism can effectively cope with situations such as uneven document thickness and irregular placement angles, ensuring that a clear image is obtained every time a scan is performed.
[0038] The high-resolution image sensor and the autofocus system work together to enable the image capture module to always capture clear and high-quality initial images in a variety of usage scenarios. This provides a solid foundation for subsequent edge detection, document type recognition, and accurate calculation of cropping parameters. After the high-resolution image sensor captures detailed image data, the autofocus system further ensures the clarity of these images under different conditions, thereby avoiding recognition errors or inaccurate cropping due to blurred images.
[0039] The combined design of high-resolution image sensor and autofocus system ensures that the trimming system can obtain initial images with clear edges and high-quality image details under different working conditions, providing a reliable foundation for subsequent trimming processing.
[0040] The edge detection module 102 communicates with the image capture module and is used to identify and detect the document edge in the initial image.
[0041] The edge detection module 102 is a key component in the trimming system, and its function is to identify and detect the document edge in the initial image. The design and implementation of this module combines image processing algorithms and technologies to ensure that the document boundary can be accurately and efficiently identified, providing a reliable data basis for the subsequent trimming process.
[0042] First, the edge detection module 102 receives the initial images from the image capture module 101. These images are usually high-resolution to ensure the accuracy of edge detection. In order to achieve accurate edge detection, a variety of image processing techniques are used within the module, such as grayscale conversion, Gaussian blur, edge enhancement and edge detection operators.
[0043] In the first step of image processing, the initial image is usually converted to a grayscale image. This step helps simplify subsequent calculations because each pixel in a grayscale image only contains brightness information, without considering color information. Next, in order to reduce noise interference in the image, the edge detection module usually applies Gaussian blur. This blurring process uses a Gaussian kernel to convolve the image, thereby smoothing the image and reducing the impact of small noise points on edge detection.
[0044] Next, the module uses edge enhancement technology to highlight the edges in the image. Common edge enhancement algorithms include the Laplace operator, Sobel operator, and Canny edge detection algorithm. Among them, the Canny edge detection algorithm is widely used in edge detection modules due to its high detection accuracy and strong noise resistance. The Canny algorithm includes multiple steps: first, the gradient of the image is calculated to obtain the direction and amplitude of the largest change in pixel value in the image, then non-maximum suppression is performed to retain pixels that may belong to the edge, and finally the edges are connected through the double threshold method to form a complete edge line.
[0045] During the edge detection process, the module generates an edge image that contains all the document edge lines that have been identified. To ensure that the edge detection results are accurate and reliable, the module usually combines morphological operations such as dilation and erosion to further process the edge image. These operations can connect broken edge lines and remove isolated noise points, thereby generating clear and continuous edge contours.
[0046] Once the edge detection is completed, the edge detection module 102 transmits the processed edge image data to the document type recognition module 103 and the multi-level precision trimming module 104. The edge detection module can also analyze the detected edge data, such as calculating the geometric features (length, angle, shape, etc.) of the document edge to provide support for the subsequent determination of trimming parameters.
[0047] By combining the above-mentioned multiple image processing technologies, the edge detection module 102 can efficiently and accurately identify the document edge in the initial image, ensuring that the trimming system can work accurately under various complex image backgrounds. Such design and implementation not only improves the accuracy and efficiency of trimming, but also provides a solid technical foundation for the system to process various types of documents.
[0048] Furthermore, the edge detection module uses an edge detection technique based on a Canny algorithm to accurately identify and detect the document edge in the initial image.
[0049] Specifically, the edge detection module can accurately extract document edges under various image qualities and complex backgrounds by implementing the Canny algorithm, providing precise boundary information for subsequent trimming processing.
[0050] The Canny algorithm is a widely used technology in the field of edge detection. It is favored because it can effectively reduce noise interference, maintain edge details and has high accuracy. The implementation of the Canny algorithm includes several key steps: Gaussian filtering, gradient calculation, non-maximum suppression and dual threshold detection. The implementation process of these steps in the edge detection module is described in detail below.
[0051] First, Gaussian filtering is used to smooth the initial image to reduce the impact of noise. Noise in the image may cause errors in edge detection, so the image must be smoothed by a Gaussian filter before edge detection. The Gaussian filter performs a weighted average of each pixel in the image with its surrounding pixels, effectively reducing random noise while retaining the main structure of the image.
[0052] Next, the edge detection module calculates the gradient of each pixel in the image. The gradient is calculated by applying the Sobel operator to the image. The Sobel operator is a discrete difference operator that is used to calculate the gradient of the image in the horizontal and vertical directions. By squaring and taking the square root of the gradient in the horizontal and vertical directions, the gradient magnitude of each pixel is obtained, thereby determining the area with the most dramatic changes in the image, that is, the possible edge location.
[0053] After calculating the gradient, non-maximum suppression is performed. The purpose of non-maximum suppression is to refine the edge and make the detection result more accurate. Specifically, for each pixel, its gradient magnitude is compared with the gradient magnitudes of the two adjacent pixels along the gradient direction. If the gradient magnitude of the pixel is not the largest, it is suppressed to zero. This process ensures that the edge finally detected is the thinnest and is accurately located at the true edge position.
[0054] Finally, double threshold detection is performed. Double threshold detection is one of the key steps of the Canny algorithm. By setting high thresholds and low thresholds, the gradient amplitude is divided into strong edges, weak edges, and non-edges. Strong edges refer to pixels with gradient amplitudes greater than the high threshold, weak edges refer to pixels with gradient amplitudes between the low threshold and the high threshold, and non-edges refer to pixels with gradient amplitudes less than the low threshold. In the double threshold detection process, all strong edges are first retained, and then according to the connectivity principle, weak edges connected to strong edges are retained, and isolated weak edges are suppressed. This can effectively remove pseudo-edges while retaining real edge information.
[0055] Through the above steps, the edge detection module can accurately identify and detect the document edge in the initial image. Gaussian filtering reduces the impact of noise, gradient calculation determines the edge position, non-maximum suppression refines the edge, and dual threshold detection removes pseudo-edges, ultimately obtaining accurate edge information. This edge information will serve as the input of the subsequent trimming module to ensure that the document is trimmed accurately.
[0056] The module can work stably under various image qualities and background complexities, providing accurate edge detection results and providing reliable guarantee for the efficient operation of the document trimming system.
[0057] The document type identification module 103 communicates with the edge detection module and is used to identify the document type in the initial image.
[0058] The document type recognition module 103 is a key component of the trimming system, and its main function is to recognize the document type in the initial image. The module automatically analyzes and classifies documents through advanced image processing and machine learning techniques, thereby providing accurate document type information for subsequent trimming operations.
[0059] During operation, the document type recognition module 103 first receives processed image data from the edge detection module 102. These data contain the edge information of the document, which provides a basis for the identification of the document type. The module optimizes the image quality through a series of pre-processing steps, such as graying, denoising, and normalization of the image, to ensure the efficiency and accuracy of the recognition process.
[0060] The document type recognition module uses feature extraction and classification algorithms to identify document types. In the feature extraction stage, the module extracts features that represent the document type by analyzing the visual features of the document, such as text arrangement, font size, image layout, etc. These features may include the number of text lines, text density, image and text ratio, color histogram, etc. The module uses deep learning technologies such as convolutional neural networks (CNN) to efficiently extract and process these features to form feature vectors.
[0061] The document type recognition module needs to process and recognize multiple types of documents, each of which has its own unique characteristics and uses. Common document types include:
[0062] Invoices usually contain information such as the company name, address, list of purchased items, total amount, and invoice number. The text on the invoice is neatly arranged and usually presented in a table format for easy identification and processing.
[0063] An ID card is a common personal identity verification document that typically contains information such as the holder's name, photo, date of birth, and ID number.
[0064] A contract is a formal legal document that records an agreement between two or more parties. It usually includes the terms and conditions, the rights and obligations of each party, a signing date, and a signature page. Contracts can come in a variety of formats, but they generally have clearly numbered sections and clauses.
[0065] A business card is a short document used for introduction and contact, usually containing information such as the holder's name, position, company name, contact information (such as phone, email) and company address. Business cards are concise in design, information-dense, and usually have unique layouts and design elements.
[0066] Medical records are documents that record patients' health information, including medical records, prescriptions, laboratory reports, surgical records, etc. These documents usually include patients' personal information, descriptions of their conditions, doctors' diagnoses and recommendations, etc., and the amount of information is large and complex.
[0067] A resume is a document that job seekers use to present their education and work experience. It usually includes personal information, education, work experience, skills, certificates, awards, etc. Resumes come in a variety of formats, but all are designed to clearly and concisely present the applicant's strengths and experience.
[0068] A bill is a notice of charges issued by a service provider, which usually includes information about the service provider, the billing period, details of charges, and the total amount. Bills come in a variety of formats, but usually have clear details of charges and payment instructions.
[0069] These different types of documents vary in format, content, and layout, and the document type recognition module needs to be able to accurately distinguish them for appropriate processing and trimming. The recognition and processing of these documents are critical for various application scenarios such as office automation, identity authentication, and medical information management. By identifying different types of documents, the trimming system can better optimize the trimming parameters to ensure the efficiency and accuracy of the processing results.
[0070] In the classification stage, the document type recognition module uses pre-trained machine learning models to classify the extracted feature vectors. These models may include support vector machines (SVM), random forests, deep neural networks (DNN), etc. Through training with a large amount of document data, the model can accurately distinguish different types of documents, such as invoices, ID cards, contracts, business cards, etc. The module can adjust the parameters of the classifier according to the diversity of the training set and the complexity of the model to improve the accuracy and generalization of recognition.
[0071] To enhance the accuracy of recognition, the document type recognition module can also combine contextual information and prior knowledge. For example, the module can use OCR technology to recognize the text content in the document and further confirm the document type based on keywords and text structure. If specific words or formats such as "invoice" are recognized in the text, the reliability of document type recognition can be effectively improved.
[0072] After the recognition is completed, the document type recognition module transmits the document type information to the multi-level precision trimming module 104. The multi-level precision trimming module determines the most suitable trimming parameters according to the received document type information, combined with the edge detection data and the user's preference settings, and performs efficient and accurate trimming operations.
[0073] By combining image processing and machine learning techniques, the document type recognition module 103 can efficiently and accurately recognize various types of documents, provide important document type information to the trimming system, and ensure the intelligence and efficiency of the trimming process.
[0074] Furthermore, the document type identification module includes a pre-trained convolutional neural network model for classifying the initial image to identify the document type in the image.
[0075] The document type recognition module includes a pre-trained convolutional neural network model for classifying the initial image to identify the document type in the image. Specifically, the document type recognition module uses the powerful feature extraction and classification capabilities of the convolutional neural network (CNN) to automatically identify the document type in the initial image, such as invoices, ID cards, contracts, etc., and provide important classification information for subsequent trimming processing.
[0076] Convolutional neural network is a deep learning model that is particularly suitable for image classification tasks. The model consists of multiple layers of convolutional layers, pooling layers, and fully connected layers, which gradually extract high-level features from the image through layer-by-layer processing. During the training process, the convolutional neural network is trained with a large amount of labeled image data to learn the characteristic patterns of various types of documents. Pre-trained convolutional neural network means that the model has been trained on a large dataset and has strong feature extraction and classification capabilities. Applying this pre-trained model to document type recognition can greatly improve the accuracy and efficiency of recognition.
[0077] In the document type recognition module, the initial image is first received, which may contain various types of documents. The initial image is input to the input layer of the convolutional neural network. The first convolutional layer of the network performs a convolution operation on the input image to extract low-level features such as edges, corners, etc. The convolution operation performs a sliding window operation on the image through a set of learnable filters to generate a feature map. Next, the pooling layer downsamples the feature map to reduce the size of the feature map, retaining important features while reducing the amount of computation and the risk of overfitting.
[0078] As the network deepens, the convolutional and pooling layers gradually extract high-level features from the image. These high-level features can better describe the specific type of document, such as the complex layout of an invoice, the unique texture and text distribution of an ID card, etc. In the last few layers, the fully connected layers integrate these high-level features and map the features to the document type label space through a series of linear transformations and nonlinear activation functions. Finally, the network outputs a probability distribution, indicating the probability that the initial image belongs to each type of document. The category corresponding to the highest probability is the identified document type.
[0079] In order to ensure the reliability of the recognition results, the convolutional neural network uses a large and diverse set of document image data for training during the pre-training process. These data sets cover document images of various types and formats, allowing the network to learn the characteristic patterns of different document types. During the training process, the network parameters are adjusted through the back-propagation algorithm to minimize the classification error and improve the classification accuracy of the network.
[0080] When the document type recognition module completes the classification of the initial image, the recognition result will be passed to the multi-level precision trimming module. Depending on the recognized document type, the trimming module can apply different cropping parameters and strategies. For example, for invoices, more detailed cropping may be required to ensure that all key information is retained; for ID cards, the trimming strategy may focus on maintaining the integrity and clarity of the edges.
[0081] Through the pre-trained convolutional neural network model, this module can efficiently and accurately identify the document type in the initial image, providing key support for the efficient operation of the document trimming system.
[0082] The multi-level precision trimming module 104 communicates with the document type recognition module and the edge detection module, and is used to determine the cropping parameters based on the recognized document type, the detected document edge and the user's preference settings; the document area in the initial image is cropped according to the determined cropping parameters to remove the non-document area; wherein the cropping parameters include the cropping margin, the cropping area shape, the cropping area size and the cropping precision level; the user's preference settings include the output format of the cropped document and whether the cropped document supports the OCR recognition function.
[0083] The multi-level precision trimming module 104 is one of the core components of the trimming system. Its main function is to determine suitable trimming parameters according to the document type, detected edge information and user preference settings, and trim the document area in the initial image accordingly, thereby removing the non-document area. The implementation of this module combines multiple technical means to ensure high precision and adaptability of the trimming process.
[0084] When the multi-level precision trimming module 104 receives data from the document type recognition module 103 and the edge detection module 102, it first performs data integration and preprocessing. By integrating the edge information provided by the edge detection module and the document type data provided by the document type recognition module, the multi-level precision trimming module can fully understand the characteristics and edge details of the current document. This step is crucial because different types of documents (such as invoices, ID cards, contracts, etc.) have different edge features and content layouts, requiring different trimming strategies.
[0085] During the preprocessing phase, the multi-level precision trimming module will initialize parameters according to the user's preferences. The user's preferences include the trimming margin, the trimming region shape, the trimming region size, and the trimming precision level. These parameters directly affect the trimming results and precision. For example, the user can set a larger trimming margin to ensure that the document content is not truncated, or select a specific trimming region shape (such as rectangle, circle) to suit different document requirements.
[0086] Next, the multi-level precision trimming module starts to calculate and determine the specific trimming parameters. During this process, the module uses a multi-level trimming algorithm to dynamically adjust the trimming strategy according to the document type and edge detection results. For documents with complex edges, the module will select a high-precision trimming mode to ensure the accuracy of edge recognition and the fineness of the trimming results. For documents with simple and regular edges, a low-precision mode can be selected to improve the trimming speed and efficiency. The multi-level trimming algorithm includes image processing techniques such as edge refinement, morphological operations (such as dilation and erosion), contour extraction, and region growing to accurately locate the boundaries of the document.
[0087] During the cropping process, the multi-level precision trimming module also monitors and adjusts the cropping parameters in real time to deal with possible problems such as document tilt, lighting changes or background noise. By automatically correcting document tilt and optimizing lighting uniformity, the module can further improve the accuracy and stability of cropping. For images with background noise, the module will apply a noise filtering algorithm to remove interference from non-document areas to ensure the clarity and accuracy of the cropping results.
[0088] After the cropping is completed, the multi-level precision trimming module transmits the processed document image to the output module 105. The output module generates the final cropped document according to the output format (such as PDF, JPEG) set by the user and whether the OCR recognition function is supported. Through this series of fine cropping operations and parameter adjustments, the multi-level precision trimming module can efficiently and accurately complete the document cropping task and adapt to the processing requirements of different types of documents.
[0089] Whether the cropped document supports OCR recognition refers to whether the system can perform optical character recognition (OCR) on the document content after the document is cropped. OCR is a technology that can convert the text in the scanned image into editable text. Supporting OCR recognition means that the cropped document is not only in the form of an image, but also can extract the text content through OCR technology, making it a digital text that can be searched, edited and copied.
[0090] When the user selects the OCR function for the cropped document, the system will further process the cropped image after the cropping operation is completed. First, the system will pre-process the image, including grayscale, denoising, and contrast adjustment to optimize the image quality. Next, the system will use the OCR algorithm to recognize the text in the image. Common OCR algorithms can recognize multiple fonts and languages, extract text information from the image, and convert it into a computer-readable text format.
[0091] The implementation of this feature is very useful for users who need to further edit or process the content of documents. For example, when processing invoices, contracts or other text-intensive documents, users can quickly obtain the text content in the document without manual input. In addition, cropped documents that support OCR recognition function can be more conveniently searched and indexed for text, which is of great significance for document management and information retrieval.
[0092] Therefore, whether the cropped document supports OCR recognition function is an option to enhance the practicality of the system. Through this function, users can convert the cropped document from a simple image file into a digital document containing editable text, greatly improving the efficiency of document processing and utilization.
[0093] Furthermore, the multi-level precision trimming module determines the trimming parameters using a trained hybrid neural network model based on the identified document type, the detected document edge, and the user's preference settings; wherein the hybrid neural network model includes an input layer, a multi-head self-attention layer, a convolutional long short-term memory network layer, a conditional generative adversarial network layer, and an output layer;
[0094] Among them, the input layer is used to receive the identified document type, the detected document edge and the user's preference settings, and perform data standardization and encoding on the received data to generate an initial feature vector; the multi-head self-attention layer processes the initial feature vector through the attention mechanism to obtain an enhanced feature vector; the convolutional long short-term memory network layer processes the enhanced feature vector through the convolutional long short-term memory unit to obtain a time series feature vector; the conditional generative adversarial network processes the time series feature vector through the generative adversarial mechanism to obtain an optimized cropping parameter vector; the output layer decodes the optimized cropping parameter vector and outputs the cropping parameters.
[0095] First, the input layer is used to receive data from the document type recognition module, the edge detection module, and the user's preferences. Specifically, the data received by the input layer includes the recognized document type (e.g., invoice, ID card, contract, etc.), document edge information (e.g., document boundary coordinates), and user preferences (e.g., cropping margins, cropping area shape, cropping accuracy level, etc.). The input layer processes these received data through standardization and encoding techniques to generate an initial feature vector. This step ensures that the input data has a uniform scale and format, so that it is suitable for processing by subsequent neural network layers.
[0096] Next, the initial feature vector is passed to the multi-head self-attention layer. The multi-head self-attention layer uses the attention mechanism to process the initial feature vector, with the goal of capturing the correlation between document types, marginal information, and user preferences. Through multiple parallel attention heads, each attention head processes a different subset of information in the initial feature vector, and calculates the correlation weights between different information through the attention mechanism. These weights are then applied to the initial feature vector to generate an enhanced feature vector. This approach enables the multi-head self-attention layer to effectively fuse information from different sources and improve the richness and accuracy of feature representation.
[0097] The enhanced feature vector is then passed to the Convolutional Long Short-Term Memory (ConvLSTM) layer. The Convolutional Long Short-Term Memory (ConvLSTM) layer processes the enhanced feature vector through a Convolutional Long Short-Term Memory (ConvLSTM) unit to capture the temporal features in the feature vector. Specifically, the ConvLSTM unit is able to retain temporal information while processing spatial information, which is very important for processing data that contains temporal or sequential relationships. During this process, the ConvLSTM unit calculates the input gate, forget gate, output gate, and cell state to dynamically update and maintain the temporal features of the feature vector. Finally, the ConvLSTM layer outputs a temporal feature vector that contains both temporal and spatial information of the document, further improving the accuracy and completeness of the feature representation.
[0098] The temporal feature vector is then input into the Conditional GAN layer. The Conditional GAN layer consists of two parts: the generator and the discriminator. The generator receives the temporal feature vector and user preference settings, and embeds the user preference information into the feature vector through the conditional embedding module. Subsequently, the generator processes the feature vector through a series of convolutional and deconvolutional layers to generate a cropping parameter image with high resolution and detail information. At the same time, the discriminator receives the generated cropping parameter image and the real cropping parameter image, extracts the local features of the image through multiple convolutional layers, and then passes through the fully connected layer to output the probability of whether the image is real or generated. Through the adversarial training of the generator and the discriminator, the conditional GAN layer can continuously optimize the generated cropping parameters to ensure its high accuracy and robustness.
[0099] Finally, the optimized cropping parameter vector is passed to the output layer. The output layer is responsible for decoding the optimized cropping parameter vector into specific cropping parameters, including cropping margins, cropping region shape, cropping region size, and cropping accuracy level. The decoding process of the output layer ensures that the final cropping parameters meet the user's preferences and the specific characteristics of the document, thereby achieving accurate cropping operations.
[0100] In summary, the multi-level precision trimming module, by combining the input layer, multi-head self-attention layer, convolutional long short-term memory network layer, conditional generative adversarial network layer and output layer, can efficiently process various input data, generate accurate trimming parameters, and ensure high precision and high robustness of document trimming.
[0101] The workflow of the multi-head self-attention layer is as follows:
[0102] First, receive the initial feature vector ,in Indicates Initial feature vectors are generated by the input layer and include standardized and encoded document types, edge information, and user preferences. The data received by the input layer is processed into a set of feature vectors so that the subsequent neural network layers can effectively use them.
[0103] Next, the query vector is calculated according to the following formula: , key vector Sum value vector :
[0104]
[0105]
[0106]
[0107] in, , and are the weight matrices for query, key, and value, respectively. These weight matrices are learned through the training process, and their function is to map the input feature vector to different subspaces so that the query, key, and value vectors are represented in these subspaces.
[0108] For each attention head , calculate the attention score matrix :
[0109]
[0110] In this formula, It is The query vector of the attention head, It is The key vector of the attention head, is the square root of the dimension of the key vector, used to scale the inner product result to maintain a stable gradient, is the activation function used for normalization, normalizing the attention score matrix into a probability distribution, is a matrix used for masks to filter out invalid or irrelevant attention scores, ensuring that the model focuses on relevant information.
[0111] The specific steps to generate a location mask include:
[0112] Create a basic mask matrix: First, generate a basic mask matrix with the same length as the input sequence. Set the value to negative infinity in the padding position ( ), set the value to zero in the valid position.
[0113] Apply mask: When calculating the attention score, the base mask matrix is added to the unnormalized attention score matrix. Since negative infinity values will cause their corresponding weights to be close to zero in the softmax operation, this achieves the effect of ignoring the padding positions or invalid areas.
[0114] Then, using the attention score matrix Pair value vector Weighted, calculate the output vector :
[0115]
[0116] In this formula, It is The value vector of the attention head, is the output bias vector, which is learned through the training process and used to adjust the final output value. The purpose of this step is to apply the attention score to the value vector to highlight the information that is highly relevant to the query vector.
[0117] Finally, the output vectors of all attention heads are concatenated together and linearly transformed to generate the final enhanced feature vector EFV:
[0118]
[0119] In this formula, is the output weight matrix, is the output bias vector, is the number of attention heads, Represents the concatenation of all attention head outputs. The concatenation operation combines the output vectors from different attention heads and generates a comprehensive enhanced feature vector through linear transformation and bias adjustment.
[0120] In summary, the multi-head self-attention layer can effectively capture the correlation between different information in the initial feature vector through the above process and calculation, and generate an enhanced feature vector with higher expressive power. Each step of calculation and transformation is precisely designed and optimized to ensure the high quality and efficiency of the final output.
[0121] The CSTM layer consists of multiple CSTM units. Each CSTM unit is processed through a series of steps to obtain a temporal feature vector.
[0122] First, for each enhanced feature vector , calculate the weighted enhanced feature vector . This calculation is performed using the following formula:
[0123]
[0124] in is at the time step The enhanced feature vector of is the weight matrix of the edge detection result, which is used to adjust the impact of the edge detection result. EB is the edge detection result. This step combines the edge detection result with the enhanced feature vector so that the edge information can be fully utilized in the subsequent time series processing.
[0125] Next, the weighted enhanced feature vector Input to the convolutional long short-term memory unit, calculate the input gate, forget gate, output gate and cell state. The specific calculation formula is as follows:
[0126] 1. Input Gate:
[0127]
[0128] in, is the weight matrix of the input gate, is the weight matrix associated with the hidden state at the previous time step, is the hidden state of the previous time step, is the bias vector of the input gate, is the Sigmoid activation function, which is used to compress the result between 0 and 1.
[0129] 2. Forget Gate:
[0130]
[0131] in, is the weight matrix of the forget gate, is the weight matrix associated with the hidden state at the previous time step, is the bias vector of the forget gate, is the hidden state of the previous time step, is the Sigmoid activation function.
[0132] 3. Output Gate:
[0133]
[0134] in, is the weight matrix of the output gate, is the weight matrix associated with the hidden state at the previous time step, is the bias vector of the output gate, is the hidden state of the previous time step, is the Sigmoid activation function.
[0135] 4. Cell status:
[0136]
[0137] in, is the cell state, is the weight matrix of the cell state, is the weight matrix associated with the hidden state at the previous time step, is the bias vector of the cell state, is the hidden state of the previous time step, is the cell state at the previous time step, is the hyperbolic tangent function, used for activation.
[0138] Through the above calculation, we get the input gate of the current time step , Forget Gate , output gate and cell status These gating mechanisms ensure the delivery of relevant information in a time series by controlling the flow of information.
[0139] Then, the output hidden state of the current time step is calculated :
[0140]
[0141] in, is the output of the output gate, is the result of the activation of the cell state, Represents the product at the element level. This step generates the hidden state of the current time step by controlling the cell state through the output gate .
[0142] Finally, the output hidden states of all time steps are Connect them to form a time series feature vector SFV:
[0143]
[0144] in, They are from the first time step to the This step forms a complete time series feature vector by concatenating the hidden states of all time steps, providing a global representation of the sequence data.
[0145] In summary, these steps generate a temporal feature vector by combining edge detection results and enhanced feature vectors, and using convolutional long short-term memory units to capture temporal features. This method ensures that when processing document trimming, the temporal information and edge features can be fully utilized to improve the trimming accuracy and robustness.
[0146] Furthermore, the conditional generative adversarial network layer includes a generator and a discriminator.
[0147] The generator includes multiple convolutional layers, deconvolutional layers, and conditional embedding modules. The main task of the generator is to receive the temporal feature vector and the user's preferences, and generate a cropping parameter image with high resolution and detail information. Specifically, the generator first receives the temporal feature vector output from the convolutional long short-term memory network layer and the user's preferences. The user's preferences may include information such as cropping margins, cropping area shapes, and cropping accuracy levels. Then, these user preference information is embedded into the temporal feature vector through the conditional embedding module. The conditional embedding module can take the form of an embedding layer or a linear layer to convert the discrete user preference information into a continuous feature vector and fuse it with the temporal feature vector.
[0148] The fused feature vector is first processed by a series of convolutional layers. Each convolutional layer is responsible for extracting local features from the feature vector and processing it through batch normalization and nonlinear activation functions (such as ReLU activation function) to ensure that the output of the generator has good stability and diversity. Batch normalization is used to stabilize the training process and accelerate convergence, while nonlinear activation functions are used to introduce nonlinearity so that the model can learn more complex feature representations.
[0149] After the convolution layer, the generator processes the feature vector through a series of deconvolution layers. The deconvolution layer is used to upsample the feature vector to gradually restore the spatial resolution of the image. The deconvolution layer is also equipped with batch normalization and nonlinear activation functions to ensure that the generated image has high resolution and detailed information. Finally, the cropping parameter image output by the generator should have the same size as the input image and contain detailed information of the cropping parameters.
[0150] The design of the discriminator is different from that of the generator. Its main task is to distinguish the cropping parameter images generated by the generator from the real cropping parameter images. The discriminator first receives the generated cropping parameter images and the real cropping parameter images, and extracts the local features of the images through multiple convolutional layers. Each convolutional layer is also equipped with batch normalization and nonlinear activation functions to improve the model's discriminative ability and convergence speed.
[0151] After the convolutional layer, the discriminator further processes the extracted features through the fully connected layer. The function of the fully connected layer is to integrate the local features extracted by the convolutional layer to generate a global feature representation. Finally, the discriminator outputs the probability of whether the image is real or generated. This probability value is used to guide the training of the generator, and the generator is continuously optimized through adversarial training to make the images it generates more and more realistic.
[0152] In the specific implementation, the various layers of the generator and discriminator need to be adjusted according to the specific tasks and data. For example, the number of convolutional and deconvolutional layers, the size of the convolution kernel, the parameters of batch normalization, and the choice of activation function can all be optimized based on experimental results.
[0153] Through the above design, the conditional generative adversarial network layer can effectively generate high-resolution cropped parameter images, which are then discriminated and optimized by the discriminator. The adversarial training of the generator and the discriminator ensures that the final generated cropped parameter images have high accuracy and high robustness.
[0154] The following is the implementation code of the conditional generation adversarial network layer:
[0155] import numpy as np
[0156] # Generator implementation
[0157] class Generator:
[0158] def __init__(self, input_dim, embedding_dim, output_dim):
[0159] """
[0160] Initializing the Generator
[0161] :param input_dim: the dimension of the time series feature vector
[0162] :param embedding_dim: The dimension of user preference embedding
[0163] :param output_dim: The dimension of the output image
[0164] """
[0165] self.input_dim = input_dim
[0166] self.embedding_dim = embedding_dim
[0167] self.output_dim = output_dim
[0168] self.initialize_layers()
[0169] def initialize_layers(self):
[0170] """
[0171] Initialize the layers of the generator, including convolutional layers, deconvolutional layers, and conditional embedding modules
[0172] """
[0173] # Conditional embedding module, embedding user preferences into time series feature vectors
[0174] self.embedding_layer = self.init_weight_matrix(self.embedding_dim, self.input_dim)
[0175] # Initialization of convolutional and deconvolutional layers
[0176] self.conv_layers = [
[0177] self.init_conv_layer(64, 128, 3, 1), # Input channel 64, output channel 128, convolution kernel size 3, step size 1
[0178] self.init_conv_layer(128, 256, 3, 1) # Input channel 128, output channel 256, convolution kernel size 3, step size 1 ]
[0180] self.deconv_layers = [
[0181] self.init_deconv_layer(256, 128, 3, 2), # Input channel 256, output channel 128, convolution kernel size 3, step size 2
[0182] self.init_deconv_layer(128, 64, 3, 2) # Input channel 128, output channel 64, convolution kernel size 3, step size 2 ]
[0184] self.output_layer = self.init_conv_layer(64, self.output_dim,3, 1) # Final output layer
[0185] def init_weight_matrix(self, in_dim, out_dim):
[0186] """
[0187] Initialize the weight matrix
[0188] :param in_dim: input dimension
[0189] :param out_dim: output dimension
[0190] :return: initialized weight matrix
[0191] """
[0192] return np.random.normal(scale=0.01, size=(in_dim, out_dim))
[0193] def init_conv_layer(self, in_channels, out_channels, kernel_size,stride):
[0194] """
[0195] Initialize the convolutional layer
[0196] :param in_channels: number of input channels
[0197] :param out_channels: number of output channels
[0198] :param kernel_size: convolution kernel size
[0199] :param stride: stride
[0200] :return: Initialized convolution layer parameters
[0201] """
[0202] return {
[0203] 'weight': np.random.normal(scale=0.01, size=(out_channels, in_channels, kernel_size, kernel_size)),
[0204] 'bias': np.zeros(out_channels),
[0205] 'stride': stride,
[0206] 'kernel_size': kernel_size
[0207] }
[0208] def init_deconv_layer(self, in_channels, out_channels, kernel_size, stride):
[0209] """
[0210] Initialize the deconvolution layer
[0211] :param in_channels: number of input channels
[0212] :param out_channels: number of output channels
[0213] :param kernel_size: deconvolution kernel size
[0214] :param stride: stride
[0215] :return: Initialized deconvolution layer parameters
[0216] """
[0217] return {
[0218] 'weight': np.random.normal(scale=0.01, size=(in_channels,out_channels, kernel_size, kernel_size)),
[0219] 'bias': np.zeros(out_channels),
[0220] 'stride': stride,
[0221] 'kernel_size': kernel_size
[0222] }
[0223] def forward(self, SFV, user_prefs):
[0224] """
[0225] Forward Propagation
[0226] :param SFV: time series feature vector
[0227] :param user_prefs: User preferences
[0228] :return: The resulting crop parameter image
[0229] """
[0230] # Embed user preference information into the time series feature vector
[0231] user_embedding = np.dot(user_prefs, self.embedding_layer)
[0232] x = SFV + user_embedding
[0233] # Process the feature vector through a series of convolutional and deconvolutional layers
[0234] for conv in self.conv_layers:
[0235] x = self.conv2d(x, conv)
[0236] x = self.batch_norm(x)
[0237] x = self.relu(x)
[0238] for deconv in self.deconv_layers:
[0239] x = self.deconv2d(x, deconv)
[0240] x = self.batch_norm(x)
[0241] x = self.relu(x)
[0242] # Final output layer
[0243] x = self.conv2d(x, self.output_layer)
[0244] output_image = self.tanh(x)
[0245] return output_image
[0246] def conv2d(self, x, layer):
[0247] """
[0248] 2D Convolution Operation
[0249] :param x: input feature
[0250] :param layer: convolutional layer parameters
[0251] :return: convolution result
[0252] """
[0253] weight, bias, stride, kernel_size = layer['weight'], layer['bias'], layer['stride'], layer['kernel_size']
[0254] # This is a simplified convolution operation, which should actually be implemented using a deep learning framework
[0255] return np.convolve(x, weight, mode='same') + bias
[0256] def deconv2d(self, x, layer):
[0257] """
[0258] 2D Deconvolution Operation
[0259] :param x: input features
[0260] :param layer: Deconvolution layer parameters
[0261] :return: deconvolution result
[0262] """
[0263] weight, bias, stride, kernel_size = layer['weight'], layer['bias'], layer['stride'], layer['kernel_size']
[0264] # This is a simplified deconvolution operation, which should actually be implemented using a deep learning framework
[0265] return np.convolve(x, weight, mode='same') + bias
[0266] def batch_norm(self, x):
[0267] """
[0268] Batch Normalization Operation
[0269] :param x: input features
[0270] :return: normalized result
[0271] """
[0272] mean = np.mean(x, axis=0)
[0273] var = np.var(x, axis=0)
[0274] return (x - mean) / np.sqrt(var + 1e-5)
[0275] # Implementation of the discriminator
[0276] class Discriminator:
[0277] def __init__(self, input_dim):
[0278] """
[0279] Initialize the discriminator
[0280] :param input_dim: the dimension of the input image
[0281] """
[0282] self.input_dim = input_dim
[0283] self.initialize_layers()
[0284] def initialize_layers(self):
[0285] """
[0286] Initialize the layers of the discriminator, including convolutional layers and fully connected layers
[0287] """
[0288] self.conv_layers = [
[0289] self.init_conv_layer(64, 128, 3, 1), # Input channel 64, output channel 128, convolution kernel size 3, step size 1
[0290] self.init_conv_layer(128, 256, 3, 1) # Input channel 128, output channel 256, convolution kernel size 3, step size 1 ]
[0292] self.fc_layer = self.init_fc_layer(256 * 8 * 8, 1) # Assume that the input image size is 64x64 and the output of the last convolutional layer is 8x8
[0293] def init_conv_layer(self, in_channels, out_channels, kernel_size,stride):
[0294] """
[0295] Initialize the convolutional layer
[0296] :param in_channels: number of input channels
[0297] :param out_channels: number of output channels
[0298] :param kernel_size: convolution kernel size
[0299] :param stride: stride
[0300] :return: Initialized convolution layer parameters
[0301] """
[0302] return {
[0303] 'weight': np.random.normal(scale=0.01, size=(out_channels, in_channels, kernel_size, kernel_size)),
[0304] 'bias': np.zeros(out_channels),
[0305] 'stride': stride,
[0306] 'kernel_size': kernel_size
[0307] }
[0308] def init_fc_layer(self, in_dim, out_dim):
[0309] """
[0310] Initialize the fully connected layer
[0311] :param in_dim: input dimension
[0312] :param out_dim: output dimension
[0313] :return: Initialized fully connected layer parameters
[0314] """
[0315] return {
[0316] 'weight': np.random.normal(scale=0.01, size=(in_dim, out_dim)),
[0317] 'bias': np.zeros(out_dim)
[0318] }
[0319] def forward(self, image):
[0320] """
[0321] Forward Propagation
[0322] :param image: input image
[0323] :return: The probability of whether the image is real or generated
[0324] """
[0325] x = image
[0326] for conv in self.conv_layers:
[0327] x = self.conv2d(x, conv)
[0328] x = self.batch_norm(x)
[0329] x = self.relu(x)
[0330] x = x.flatten() # Expand the output of the convolutional layer
[0331] x = self.fc(x, self.fc_layer)
[0332] output = self.sigmoid(x)
[0333] return output
[0334] def conv2d(self, x, layer):
[0335] """
[0336] 2D Convolution Operation
[0337] :param x: input features
[0338] :param layer: convolutional layer parameters
[0339] :return: convolution result
[0340] """
[0341] weight, bias, stride, kernel_size = layer['weight'], layer['bias'], layer['stride'], layer['kernel_size']
[0342] # This is a simplified convolution operation, which should actually be implemented using a deep learning framework
[0343] return np.convolve(x, weight, mode='same') + bias
[0344] def fc(self, x, layer):
[0345] """
[0346] Fully connected operation
[0347] :param x: input feature
[0348] :param layer: fully connected layer parameters
[0349] :return: Full connection result
[0350] """
[0351] weight, bias = layer['weight'], layer['bias']
[0352] return np.dot(x, weight) + bias
[0353] def batch_norm(self, x):
[0354] """
[0355] Batch Normalization Operation
[0356] :param x: input feature
[0357] :return: normalized result
[0358] """
[0359] mean = np.mean(x, axis=0)
[0360] var = np.var(x, axis=0)
[0361] return (x - mean) / np.sqrt(var + 1e-5)
[0362] The scanned document trimming system uses a trained hybrid neural network model to determine the trimming parameters. The hybrid neural network model includes an input layer, a multi-head self-attention layer, a convolutional long short-term memory network layer, a conditional generative adversarial network layer, and an output layer. The following is a detailed description of the training steps of the model.
[0363] First, the model training process starts with data preparation. The input data includes the identified document type, the detected document edge information, and the user's preferences. Document types may include invoices, ID cards, contracts, etc. The edge information is usually the boundary coordinates obtained by the edge detection algorithm, and the user preferences include cropping margins, cropping area shapes, cropping accuracy, etc. After receiving this data, the input layer normalizes and encodes it to generate an initial feature vector. This step ensures that the input data is in the same scale and format, suitable for processing by subsequent neural network layers.
[0364] Next, the initial feature vector is passed to the multi-head self-attention layer. The multi-head self-attention layer uses the attention mechanism to process the initial feature vector to capture the correlation between document types, edge information, and user preferences. Specifically, each attention head processes a different subset of information in the feature vector, calculates the query, key, and value vectors, and generates an attention score matrix through the attention mechanism. These score matrices are then applied to the value vector to generate an enhanced feature vector. This step improves the richness and accuracy of the feature representation.
[0365] The enhanced feature vector is then input to the convolutional long short-term memory network layer. This layer processes the enhanced feature vector through multiple convolutional long short-term memory units to capture the temporal and spatial information in the features. Each long short-term memory unit includes an input gate, a forget gate, an output gate, and a cell state, and these gating mechanisms control the flow and update of information in the time series. Finally, the convolutional long short-term memory network layer outputs a temporal feature vector containing the temporal and spatial information of the document.
[0366] Then, the temporal feature vector is input into the conditional generative adversarial network layer. The conditional generative adversarial network layer consists of two parts: the generator and the discriminator. The generator receives the temporal feature vector and the user preference settings, and embeds the user preference information into the feature vector through the conditional embedding module. Next, the generator processes the feature vector through a series of convolutional and deconvolutional layers to generate a cropped parameter image with high resolution and detailed information. Each convolutional and deconvolutional layer is equipped with batch normalization and nonlinear activation functions to ensure the stability and diversity of the generator output. At the same time, the discriminator receives the generated cropped parameter image and the real cropped parameter image, extracts the local features of the image through multiple convolutional layers, and then generates a global feature representation through a fully connected layer, and finally outputs the probability of whether the image is real or generated. Through the adversarial training of the generator and the discriminator, the generator is continuously optimized to make the images it generates more and more realistic.
[0367] Finally, the optimized cropping parameter vector is passed to the output layer. The output layer decodes the optimized cropping parameter vector to generate the final cropping parameters. The decoding process includes linear transformation and biasing of the feature vector to output specific cropping parameters, such as cropping margin, cropping area shape and size, etc.
[0368] Throughout the training process, the model measures the difference between the generated results and the real results by defining a loss function. Common loss functions include mean square error, cross entropy loss, etc. Through the back-propagation algorithm, the gradient of the loss relative to the model parameters is calculated, and the model parameters are updated using optimization algorithms (such as gradient descent, Adam optimizer, etc.) to minimize the loss function value. The training process lasts for multiple iterations, each of which includes four steps: forward propagation, loss calculation, back-propagation, and parameter update. The model improves the accuracy and robustness of the generated clipping parameters through continuous iteration and optimization, and finally verifies the performance of the model on the test data to ensure its effectiveness in practical applications.
[0369] Through these detailed training steps, the training of the hybrid neural network model can be achieved.
[0370] The output module 105 communicates with the multi-level precision trimming module and is used to output the trimmed document.
[0371] The output module 105 is an important component of the trimming system. Its main function is to receive the processed document image from the multi-level precision trimming module 104 and generate the final output document according to the user's preference settings. The design and implementation of this module ensures that the trimmed document can be saved and transmitted in the format and quality required by the user.
[0372] First, the output module 105 receives the cropped document images transmitted by the multi-level precision trimming module 104. These images are trimmed to remove the redundant background area and retain only the valid part of the document. In order to meet the needs of different users, the output module needs to process multiple output formats, such as PDF, JPEG, PNG, etc. Each format has its own unique advantages and application scenarios. For example, the PDF format is suitable for document archiving and sharing, while the JPEG and PNG formats are more suitable for image display and web page publishing.
[0373] In the process of generating the output document, the output module 105 first determines the output format according to the user's preference settings. If the user selects the PDF format, the module will embed the cropped image into the PDF file and can choose to add multiple pages to generate a multi-page PDF. If the user selects the image format, the module will appropriately compress and optimize the quality of the image to ensure the best balance between file size and image quality.
[0374] In addition, the output module also needs to handle OCR recognition. If the user chooses to support OCR recognition, the module will call the OCR engine to perform text recognition on the cropped image before generating the final output document. The recognized text can be embedded into the PDF file, so that the PDF file contains not only images but also searchable and copyable text content. If the user chooses the image format, the OCR recognized text can be attached to the metadata of the image file to facilitate subsequent text extraction and processing.
[0375] In order to ensure the high quality of the output document, the output module 105 also includes a series of image processing functions, such as color correction, brightness adjustment and noise filtering of the image, etc. These processing steps help to improve the visual effect and readability of the final document, especially when processing documents with poor scanning quality, these functions are particularly important.
[0376] After completing all processing steps, the output module 105 will save the generated document to a specified storage location. The user can select a default save path through system settings, such as a local hard disk, a network drive, or a cloud storage service. The output module can also provide an automatic naming function to generate a file name according to the user's naming rules to facilitate the organization and management of documents.
[0377] By implementing the above steps, the output module 105 can efficiently and flexibly generate the cropped document required by the user, and support multiple output formats and OCR recognition functions to meet the needs of different application scenarios.
[0378] Furthermore, the output module includes a data transmission interface for transmitting the cropped document to an external storage device or cloud storage.
[0379] The data transmission interface may include various forms, such as a USB interface, an Ethernet interface, a Wi-Fi module or a Bluetooth module, etc. The user can select a suitable interface type according to needs.
[0380] When the trimming system completes the document trimming operation, the trimmed document will be received by the output module and prepared for transmission. First, the output module will perform necessary processing on the trimmed document, including file format conversion, compression or encryption, to ensure the integrity and security of the data during transmission. Then, the output module sends the processed trimmed document to an external storage device or cloud storage through the data transmission interface.
[0381] The external storage device can be a USB flash drive, an external hard disk, a network storage device (NAS), etc., which is connected to the trimming system through a USB interface or an Ethernet interface. The trimming system identifies the external storage device, establishes a data connection, and transfers the trimmed document to the specified storage path. During the transmission process, the output module monitors the status of data transmission in real time to ensure that the document can be smoothly and completely transferred to the external storage device.
[0382] If the user chooses to transfer the cropped document to cloud storage, the output module will connect to the Internet via the built-in Wi-Fi module or Ethernet interface. The cloud storage account information preset in the system configuration will be used for authentication and authorization to ensure that only authorized users can access and store documents. The output module will upload the cropped document to the specified cloud storage service. During the upload process, the output module will also monitor the data to ensure the stability of the transmission process and the integrity of the data.
[0383] In addition, the design of the output module takes into account a variety of usage scenarios. Users can select the target location (local storage or cloud storage) and transmission method of the output document through the system settings interface. In the implementation of the data transmission interface, the system uses common transmission protocols such as FTP, HTTP, HTTPS, etc. to ensure the compatibility and security of the transmission.
[0384] The design of the output module ensures that the cropped documents can be efficiently and securely transmitted to the user-specified storage location, meeting the storage needs of different users and ensuring the integrity and security of the data during transmission.
[0385] In the above-mentioned embodiment, a system for trimming the scanned document is provided. Correspondingly, the present application also provides a method for trimming the scanned document. Figure 2 , which is a flow chart of an embodiment of a scanned document trimming method of the present application. Since this embodiment, i.e., the second embodiment, is basically similar to the first embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the first embodiment. The method embodiment described below is only illustrative.
[0386] A second embodiment of the present application provides a method for trimming a scanned document, comprising:
[0387] Step S201: obtaining an initial image of a document to be scanned;
[0388] Step S202: identifying and detecting the document edge in the initial image;
[0389] Step S203: Identify the document type in the initial image;
[0390] Step S204: determining cropping parameters based on the identified document type, the detected document edge, and the user's preference settings, wherein the cropping parameters include a cropping margin, a cropping region shape, a cropping region size, and a cropping precision level, and the user's preference settings include an output format of the cropped document and whether the cropped document supports an OCR recognition function;
[0391] Step S205: cropping the document area in the initial image according to the determined cropping parameters to remove the non-document area;
[0392] Step S206: Output the cropped document.
[0393] Although the present application is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present application. Any technical personnel in this field may make possible changes and modifications without departing from the spirit and scope of the present application. Therefore, the scope of protection of the present application shall be based on the scope defined by the claims of the present application.
Claims
1. A scanning document trimming system, characterized in that: include: An image capture module, used for acquiring an initial image of a document to be scanned; an edge detection module, in communication with the image capture module, for identifying and detecting document edges in the initial image; a document type recognition module, communicating with the edge detection module, for identifying the document type in the initial image; a multi-level precision trimming module, communicating with the document type recognition module and the edge detection module, and used to determine trimming parameters based on the recognized document type, the detected document edge, and the user's preference settings; trimming the document area in the initial image according to the determined trimming parameters to remove the non-document area; wherein the trimming parameters include a trimming margin, a trimming area shape, a trimming area size, and a trimming precision level; and the user's preference settings include an output format of the trimmed document and whether the trimmed document supports an OCR recognition function; An output module, communicating with the multi-level precision trimming module, for outputting the trimmed document; The multi-level precision trimming module determines the trimming parameters using a trained hybrid neural network model based on the identified document type, the detected document edge, and the user's preference settings; wherein the hybrid neural network model includes an input layer, a multi-head self-attention layer, a convolutional long short-term memory network layer, a conditional generative adversarial network layer, and an output layer; The input layer is used to receive the identified document type, the detected document edge and the user's preference setting, and perform data standardization and encoding on the received data to generate an initial feature vector; the multi-head self-attention layer processes the initial feature vector through the attention mechanism to obtain an enhanced feature vector; the convolutional long short-term memory network layer processes the enhanced feature vector through the convolutional long short-term memory unit to obtain a time series feature vector; the conditional generative adversarial network processes the time series feature vector through the generative adversarial mechanism to obtain an optimized cropping parameter vector; the output layer decodes the optimized cropping parameter vector and outputs the cropping parameters; The multi-head self-attention layer includes multiple parallel attention heads, each of which is used to process different subsets of information in the initial feature vector and capture the correlation between the information through the attention mechanism; the workflow of the multi-head self-attention layer specifically includes: Receive initial feature vector , calculate the query vector according to the following formula 1-3 , key vector Sum value vector : in, It is Initial eigenvectors; is the query weight matrix; is the key weight matrix; is the weight matrix of values; For each attention head , calculate the attention score matrix according to the following formula 4 : in, It is The query vector of the attention head; It is The key vector of the attention heads; is the dimension of the key vector; is the activation function used for normalization; is a matrix used for masking to filter invalid or irrelevant attention scores; According to the following formula 5, the output vector is calculated : in, It is The value vector of the attention heads; is the bias vector used to adjust the output of the attention head; According to the following formula 6, the outputs of all attention heads are concatenated together and the final enhanced feature vector EFV is generated through linear transformation: in, is the output weight matrix; is the number of attention heads; represents the concatenation of the outputs of all attention heads; is the bias vector of the final output; The convolutional long short-term memory network layer includes a plurality of convolutional long short-term memory units, and each convolutional long short-term memory unit is processed through the following steps to obtain a time series feature vector: For each enhanced feature vector , according to the following formula 7, calculate the weighted enhanced feature vector in, is the weight matrix of edge detection result; EB is the edge detection result; represents element-wise product; According to the following formula 8-11, the weighted enhanced feature vector Input to the convolutional long short-term memory unit, calculate the input gate, forget gate, output gate and cell state: in, is the hidden state of the previous time step; and They are input gate, forget gate, output gate and cell state. and is the input weight matrix; and is the weight matrix of the hidden state; and is the bias vector; is the Sigmoid activation function; is the cell state at the previous time step; According to the following formula 12, calculate the output hidden state in, is the output hidden state of the current time step; According to the following formula 13, the output hidden state of all time steps Connect them to form a time series feature vector SFV: in, They are from the first time step to the The output hidden state of the time step; Wherein, the conditional generative adversarial network layer includes a generator and a discriminator; The generator includes a plurality of convolutional layers, deconvolutional layers and conditional embedding modules; the generator first receives a temporal feature vector and a user's preference settings, and embeds the user's preference information into the temporal feature vector through the conditional embedding module; then, the temporal feature vector is processed through a series of convolutional layers and deconvolutional layers to generate a cropped parameter image with high resolution and detail information; each convolutional layer and deconvolutional layer is equipped with batch normalization and nonlinear activation functions to ensure that the output of the generator has good stability and diversity; The discriminator includes multiple convolutional layers and fully connected layers, which are used to distinguish the cropping parameter images generated by the generator from the real cropping parameters; the discriminator first receives the generated cropping parameter images and the real cropping parameter images, and extracts local features of the images through multiple convolutional layers; then, through the fully connected layers, the extracted features are further processed to output the probability of whether the image is real or generated; wherein each convolutional layer of the discriminator is equipped with batch normalization and nonlinear activation functions to improve the discrimination ability and convergence speed of the model.
2. The scanning document trimming system according to claim 1, characterized in that: The image capture module includes a high-resolution image sensor and an autofocus system to ensure that the acquired initial image has clear edges and high-quality image details.
3. The scanning document trimming system according to claim 1, characterized in that: The edge detection module uses an edge detection technique based on the Canny algorithm to accurately identify and detect the document edge in the initial image.
4. The scanning document trimming system according to claim 1, characterized in that: The document type recognition module includes a pre-trained convolutional neural network model for classifying the initial image to identify the document type in the image.
5. The scanning document trimming system according to claim 1, characterized in that: The output module includes a data transmission interface for transmitting the cropped document to an external storage device or cloud storage.
6. A method for trimming a scanned document, characterized in that: include: Acquire an initial image of the document to be scanned; identifying and detecting document edges in the initial image; identifying a document type in the initial image; Determining cropping parameters based on the identified document type, the detected document edge, and user preferences, wherein the cropping parameters include a cropping margin, a cropping region shape, a cropping region size, and a cropping precision level, and the user preferences include an output format of the cropped document and whether the cropped document supports an OCR recognition function; Cropping the document area in the initial image according to the determined cropping parameters to remove the non-document area; Output the cropped document; The step of determining the cropping parameters based on the identified document type, the detected document edge, and the user's preference setting includes: Determining cropping parameters using a trained hybrid neural network model based on the identified document type, the detected document edges, and the user's preference settings; wherein the hybrid neural network model includes an input layer, a multi-head self-attention layer, a convolutional long short-term memory network layer, a conditional generative adversarial network layer, and an output layer; The input layer is used to receive the identified document type, the detected document edge and the user's preference setting, and perform data standardization and encoding on the received data to generate an initial feature vector; the multi-head self-attention layer processes the initial feature vector through the attention mechanism to obtain an enhanced feature vector; the convolutional long short-term memory network layer processes the enhanced feature vector through the convolutional long short-term memory unit to obtain a time series feature vector; the conditional generative adversarial network processes the time series feature vector through the generative adversarial mechanism to obtain an optimized cropping parameter vector; the output layer decodes the optimized cropping parameter vector and outputs the cropping parameters; The multi-head self-attention layer includes multiple parallel attention heads, each of which is used to process different subsets of information in the initial feature vector and capture the correlation between the information through the attention mechanism; the workflow of the multi-head self-attention layer specifically includes: Receive initial feature vector , calculate the query vector according to the following formula 1-3 , key vector Sum value vector : in, It is Initial eigenvectors; is the query weight matrix; is the key weight matrix; is the weight matrix of values; For each attention head , calculate the attention score matrix according to the following formula 4 : in, It is The query vector of the attention head; It is The key vector of the attention heads; is the dimension of the key vector; is the activation function used for normalization; is a matrix used for masking to filter invalid or irrelevant attention scores; According to the following formula 5, the output vector is calculated : in, It is The value vector of the attention heads; is the bias vector used to adjust the output of the attention head; According to the following formula 6, the outputs of all attention heads are concatenated together and the final enhanced feature vector EFV is generated through linear transformation: in, is the output weight matrix; is the number of attention heads; represents the concatenation of the outputs of all attention heads; is the bias vector of the final output; The convolutional long short-term memory network layer includes a plurality of convolutional long short-term memory units, and each convolutional long short-term memory unit is processed through the following steps to obtain a time series feature vector: For each enhanced feature vector , according to the following formula 7, calculate the weighted enhanced feature vector in, is the weight matrix of edge detection result; EB is the edge detection result; represents element-wise product; According to the following formula 8-11, the weighted enhanced feature vector Input to the convolutional long short-term memory unit, calculate the input gate, forget gate, output gate and cell state: in, is the hidden state of the previous time step; and They are input gate, forget gate, output gate and cell state. and is the input weight matrix; and is the weight matrix of the hidden state; and is the bias vector; is the Sigmoid activation function; is the cell state at the previous time step; According to the following formula 12, calculate the output hidden state in, is the output hidden state of the current time step; According to the following formula 13, the output hidden state of all time steps Connect them to form a time series feature vector SFV: in, They are from the first time step to the The output hidden state of the time step; Wherein, the conditional generative adversarial network layer includes a generator and a discriminator; The generator includes a plurality of convolutional layers, deconvolutional layers and conditional embedding modules; the generator first receives a temporal feature vector and a user's preference settings, and embeds the user's preference information into the temporal feature vector through the conditional embedding module; then, the temporal feature vector is processed through a series of convolutional layers and deconvolutional layers to generate a cropped parameter image with high resolution and detail information; each convolutional layer and deconvolutional layer is equipped with batch normalization and nonlinear activation functions to ensure that the output of the generator has good stability and diversity; The discriminator includes multiple convolutional layers and fully connected layers, which are used to distinguish the cropping parameter images generated by the generator from the real cropping parameters; the discriminator first receives the generated cropping parameter images and the real cropping parameter images, and extracts local features of the images through multiple convolutional layers; then, through the fully connected layers, the extracted features are further processed to output the probability of whether the image is real or generated; wherein each convolutional layer of the discriminator is equipped with batch normalization and nonlinear activation functions to improve the discrimination ability and convergence speed of the model.
Citation Information
Patent Citations
Bar code detection and identification method based on visual image
CN107403124A
Document scanning apparatus and method
JP2019125828A