PDF document image character comparison method and device, equipment and storage medium

By using icon region extraction and semantic feature point matching, the problem of recognition accuracy and efficiency in PDF document image character comparison in existing technologies has been solved, achieving efficient and accurate document character comparison in complex layout scenarios.

CN123182250APending Publication Date: 2026-11-27SUNWODA ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611317118.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-27
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies for PDF document image character comparison suffer from problems such as insufficient support for multilingual mixed typesetting, low recognition accuracy, high false recognition rate due to dynamic typesetting, low efficiency of manual comparison, and large computational load, which cannot meet the strict requirements of document version management in the manufacturing industry.

Method used

This paper employs a method of icon region extraction, semantic hierarchical mask construction, and semantic feature point matching. By extracting character box coordinate information through an object detection model, constructing a semantic hierarchical mask and extracting semantic feature points, performing semantic consistency matching, filtering out valid matching point pairs, filtering character boxes and locating differing character boxes, and realizing document character comparison.

Benefits of technology

It improves the accuracy and robustness of PDF document image character comparison in complex layout scenarios, effectively identifies the location of character differences between documents, and improves comparison efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123182250A_ABST
    Figure CN123182250A_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of intelligent analysis of documents, and particularly relates to a PDF document image character comparison method and device, equipment and a storage medium, comprising converting at least two PDF documents to be compared into corresponding document images respectively; extracting an icon area from the document image to obtain an icon image, and extracting character box coordinate information from the icon image respectively; constructing a semantic hierarchical mask according to the character box coordinate information, and extracting semantic feature points in layers through the semantic hierarchical mask to construct a PDF feature descriptor; performing semantic consistency matching according to the PDF feature descriptor, and screening effective matching point pairs from a matching data set; filtering difference character boxes in the icon image by using the effective matching point pairs, and positioning the difference character boxes to obtain a document character comparison result. The present application compares characters through semantic feature point matching and other technologies, and improves the accuracy and robustness of printed character comparison in PDF document images in complex layout and other scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of document intelligent analysis technology, and in particular to a method, apparatus, device, and storage medium for comparing characters in PDF document images. Background Technology

[0002] In the product lifecycle management of manufacturing enterprises, Portable Document Format (PDF) files are widely used as a standard format for cross-platform document exchange for iterative archiving and version management of various product printed specifications. Since specifications usually contain a mixed layout of various elements such as text, images, and vector graphics, the version consistency comparison of image content (mainly including brand logos, safety certification marks, and printed characters) is directly related to product compliance review and quality traceability.

[0003] However, existing technologies have many shortcomings in practical applications. First, most existing technologies use Optical Character Recognition (OCR). The recognition-assisted comparison method has insufficient support for multilingual mixed typesetting and limited accuracy in recognizing non-Latin characters (such as Chinese, Japanese, Korean, and various symbols). Furthermore, dynamic typesetting often makes it difficult to accurately distinguish the boundaries between safety regulations, trademarks, and ordinary text, leading to frequent misidentifications. The overall accuracy is insufficient to meet the stringent requirements of production sites. Secondly, traditional manual inspection and comparison methods not only require significant manpower and time investment but also struggle to adapt to the frequent typesetting changes during document iteration in the manufacturing industry. When page layout, font size, or icon position is slightly adjusted, manual comparison requires re-verification item by item, resulting in extremely low efficiency and a high rate of missed detections, severely restricting the speed of document iteration. In addition, existing image comparison technologies mostly use pixel-by-pixel movement and real-time adjustment of matching tolerance to estimate the offset of each region of the image. While this method can work in simple scenarios, the computational load increases dramatically when dealing with high-resolution icon images containing complex edges and fine characters, resulting in low processing efficiency and failing to meet the stringent requirements of document version management in the manufacturing industry. Summary of the Invention

[0004] To address the above technical problems, this invention provides a method, apparatus, device, and storage medium for comparing characters in PDF document images.

[0005] In a first aspect, the present invention provides a method for comparing characters in an image of a PDF document, the method comprising the following steps: Convert at least two PDF documents to be compared into image format to obtain document images corresponding to each PDF document; The icon regions of each document image are extracted to obtain the corresponding icon images, and the character box coordinate information is extracted from each of the icon images. A semantic hierarchy mask is constructed based on the character box coordinate information, and semantic feature points are extracted layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor; Based on the PDF feature descriptor, semantic consistency matching is performed on the semantic feature points of each icon image to obtain a matching dataset, and valid matching point pairs are selected from the matching dataset. By filtering the character boxes in the icon image using the effective matching point pairs, different character boxes are obtained, and the different character boxes are located by different coordinates to obtain the document character comparison result.

[0006] In a further implementation, the step of extracting the icon region from each document image to obtain the corresponding icon image includes: The pre-built first object detection model is used to perform a global scan of each document image to obtain the bounding rectangles corresponding to each icon area; Based on the bounding rectangle, the corresponding icon candidate region image is cropped from each document image, and each icon candidate region image is preprocessed to obtain the preprocessed icon candidate region image. The pre-built second target detection model is used to detect the preprocessed icon candidate region image to obtain the detection box coordinates of the icon foreground entity region, and the icon foreground entity region mask is obtained based on the detection box coordinates. The corresponding icon image is cropped from the preprocessed icon candidate region image using the icon foreground entity region mask.

[0007] In a further implementation, the semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask; correspondingly, the step of constructing the semantic hierarchy mask based on the character box coordinate information includes: Using the pixel matrix of the icon image as a base, an all-zero mask matrix is ​​initialized as the initial state of the character mask, and the vertex pixel coordinates of each character box are read from the character box coordinate information; Based on the vertex pixel coordinates, assign the first value to all pixels within the area covered by each character box, and assign the second value to the remaining area to generate a character mask; Based on the boundary of each character box, shrink inward by a first preset number of pixels and expand outward by a second preset number of pixels. Assign the first value to the pixels in the outline ring area formed after shrinking and expanding, and assign the second value to the pixels in the remaining area to generate a character edge mask. Obtain the outer contour of the icon image, take all pixels within the outer contour as initial pixels and assign them a first value, remove the pixels with the first value from the initial pixels one by one in the character mask, assign the first value to the pixels in the remaining non-character area after removal, and assign the second value to the remaining pure character area to generate the icon mask. The character mask, the character edge mask, and the icon mask are integrated into a semantic-level mask, wherein the first value and the second value are the binarized values ​​of the foreground region and the background region, respectively.

[0008] In a further implementation, the semantic feature points include at least character center feature points, character contour feature points, and icon structure feature points; correspondingly, the step of extracting semantic feature points hierarchically through the semantic hierarchy mask to construct the PDF feature descriptor includes: The geometric center of each character frame is calculated based on the character frame coordinate information, and several sampling points are uniformly sampled within the character frame according to a preset grid division method, with the geometric center as the reference. Calculate the mean gray-level gradient in the neighborhood of each sampling point, and retain the sampling points whose mean gray-level gradient is greater than a first preset threshold and are located in the foreground area indicated by the character mask as character center feature points; Calculate the corner response value of each pixel within the area defined by the character edge mask, and determine the pixels whose corner response value is greater than the second preset threshold and are located within the foreground area indicated by the character edge mask as candidate corners. Perform non-maximum suppression on the candidate corners, and use the candidate corners retained after suppression as character contour feature points. Within the non-character semantic region defined by the icon mask, key points of the icon outline are extracted as icon structural feature points, and the character center feature points, the character outline feature points, and the icon structural feature points are integrated to form semantic feature points; The semantic category of each semantic feature point and its normalized position relative to its corresponding character frame are encoded to obtain the PDF feature descriptor; the PDF feature descriptor includes semantic category encoding and position relative encoding.

[0009] In a further implementation, the step of performing semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain a matching dataset includes: Extract the semantic category code corresponding to each semantic feature point from the PDF feature descriptor, and determine the semantic feature points with the same semantic category code as matchable feature point pairs; The relative positional deviation of each matchable feature point pair is calculated based on the relative positional encoding, and the offset of each matchable feature point pair is determined based on the relative positional deviation. The matching confidence of each matchable feature point pair is determined based on the local texture encoding and context encoding of each matchable feature point pair. A matching dataset is generated based on the offset and matching confidence of each matchable feature point pair.

[0010] In a further implementation, the step of filtering valid matching point pairs from the matching dataset includes: Based on the matching dataset, matchable feature point pairs with matching confidence lower than a preset confidence threshold or offset exceeding a preset offset threshold are removed to obtain initial screening of matching point pairs. Select matching pairs whose semantic category is character center feature point or character contour feature point from the initial screening matching point pairs, and use them as matching pairs to be compared; Calculate the size ratio of the character box corresponding to the matching pair to be compared, and remove the matching pairs whose size ratio deviation exceeds the preset ratio range to obtain the valid matching point pairs.

[0011] In a further implementation, the step of filtering the character boxes in the icon image using the effective matching point pairs to obtain the difference character boxes, and performing cross-position coordinate positioning on the difference character boxes to obtain the document character comparison result includes: Based on the valid matching point pairs, the character boxes in each icon image are filtered out, and the character boxes in which valid matching points fall are removed, while the character boxes in which no valid matching points fall are marked as difference character boxes. Adjacent difference character boxes are merged based on the intersection-union ratio and pixel spacing to generate a fused difference character box, and the coordinate position, semantic level, and difference type of the fused difference character box are obtained. In the PDF document to be compared, the coordinates, semantic level, and difference type of the merged difference character boxes are marked synchronously to obtain the document character comparison results.

[0012] Secondly, the present invention provides a PDF document image character comparison device, the device comprising: The format conversion module is used to convert at least two PDF documents to be compared into image formats, so as to obtain the document images corresponding to each PDF document; The character extraction module is used to extract the icon region from each document image to obtain the corresponding icon image, and to extract the character box coordinate information from each of the icon images. The semantic analysis module is used to construct a semantic hierarchical mask based on the character box coordinate information, and to extract semantic feature points layer by layer through the semantic hierarchical mask to construct PDF feature descriptors; The feature matching module is used to perform semantic consistency matching on the semantic feature points of each icon image according to the PDF feature descriptor, obtain a matching dataset, and filter out valid matching point pairs from the matching dataset; The character comparison module is used to filter the character boxes in the icon image using the effective matching point pairs, obtain the difference character boxes, and perform different position coordinate positioning on the difference character boxes to obtain the document character comparison result.

[0013] Thirdly, the present invention also provides an electronic device, the electronic device including a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the PDF document image character comparison method described above.

[0014] Fourthly, the present invention also provides a computer-readable storage medium storing a computer-executable program or instructions, wherein when the computer-executable program or instructions are executed by a computer, the steps of the PDF document image character comparison method described above are implemented.

[0015] This invention provides a method, apparatus, device, and storage medium for comparing PDF document images. The method involves converting at least two PDF documents to be compared into image formats to obtain document images corresponding to each PDF document; extracting icon regions from each document image to obtain corresponding icon images, and extracting character box coordinate information from each icon image; constructing a semantic hierarchy mask based on the character box coordinate information, and extracting semantic feature points layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor; the semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask; the semantic feature points include at least character center feature points, character contour feature points, and icon structure feature points; performing semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain a matching dataset, and filtering valid matching point pairs from the matching dataset; using the valid matching point pairs to filter character boxes in the icon images to obtain differing character boxes, and performing out-of-position coordinate positioning on the differing character boxes to obtain the document character comparison result. Compared with existing technologies, this method uses techniques such as semantic feature point matching to perform character comparison, which improves the accuracy and robustness of printed character comparison in PDF document images under complex layout scenarios and effectively identifies the location of character differences between documents. Attached Figure Description

[0016] Figure 1 This is a schematic diagram of the PDF document image character comparison method provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the PDF document image character comparison process provided in an embodiment of the present invention; Figure 3 This is a block diagram of the PDF document image character comparison device provided in an embodiment of the present invention; Figure 4 This is a schematic diagram of the electronic device structure provided in an embodiment of the present invention.

[0017] Explanation of reference numerals in the attached figures: 101, Format conversion module; 102, Character extraction module; 103, Semantic analysis module; 104, Feature matching module; 105, Character comparison module; 401, Processor; 402, Memory. Detailed Implementation

[0018] The embodiments of the present invention are described in detail below with reference to the accompanying drawings. The embodiments are given for illustrative purposes only and should not be construed as limiting the present invention. The accompanying drawings are for reference and illustration only and do not constitute a limitation on the scope of patent protection of the present invention, because many changes can be made to the present invention without departing from the spirit and scope of the present invention.

[0019] In the manufacturing process of electronic products, product specification sheets (such as instruction manual covers, safety certification pages, or brand logo pages) are usually archived in PDF format. It is necessary to compare changes in icons and printed characters between different versions. Figure 1 This is a schematic flowchart of a PDF document image character comparison method provided in an embodiment of the present invention. The present invention provides a PDF document image character comparison method, such as... Figure 1 As shown, the PDF document image character comparison method includes the following steps: S1. Convert at least two PDF documents to be compared into image format to obtain document images corresponding to each PDF document.

[0020] In a specific embodiment, this embodiment performs high-resolution rasterization conversion on each page of each PDF document based on the page data of at least two PDF documents to be compared, obtaining a corresponding high-resolution document image. The conversion resolution is no less than 300 dots per inch, and the image format is either Portable Network Graphics (PNG) or Joint Photographic Experts (JPA). (Group, JPEG) ensures that icon edges and character strokes remain clearly identifiable in the converted image, avoiding missed detections or broken strokes in subsequent character detection stages due to insufficient resolution. During the conversion process, for cases where vector and bitmap layouts may exist in PDF documents, this embodiment prioritizes rasterization using a vector rendering engine to maintain the edge sharpness of vector elements. For pages with embedded bitmaps, this embodiment can directly extract the original bitmap data and uniformly scale it to the target resolution, avoiding image quality loss introduced by secondary compression. Through the above operations, this embodiment enables the converted page image to be accurately identified by the model in the subsequent object detection stage, and to clearly distinguish the stroke structure of small characters in the text detection stage, thereby ensuring the accuracy of the comparison results.

[0021] S2. Extract the icon region from each document image to obtain the corresponding icon image, and extract the character box coordinate information from each icon image.

[0022] In some implementations, the step of extracting icon regions from each document image to obtain the corresponding icon image includes: The pre-built first object detection model is used to perform a global scan of each document image to obtain the bounding rectangles corresponding to each icon area; Based on the bounding rectangle, the corresponding icon candidate region image is cropped from each document image, and each icon candidate region image is preprocessed to obtain the preprocessed icon candidate region image. The pre-built second target detection model is used to detect the preprocessed icon candidate region image to obtain the detection box coordinates of the icon foreground entity region, and the icon foreground entity region mask is obtained based on the detection box coordinates. The corresponding icon image is cropped from the preprocessed icon candidate region image using the icon foreground entity region mask.

[0023] In a specific embodiment, this embodiment pre-uses a YOLOv11n-based object detection model as both the first and second object detection models. Then, each document image is sequentially input into the pre-trained first object detection model. This first object detection model has learned a large number of icon samples of different layouts and sizes during the training phase, possessing a large receptive field and fast inference speed. The first object detection model performs a global scan of each document image and outputs the bounding rectangle of each detected icon region. The first object detection model prioritizes high recall, allowing... The first bounding rectangle contains redundant background areas, but ensures that all icon areas are detected to avoid omissions. Then, in this embodiment, the corresponding icon candidate area images are cropped from each document image based on the bounding rectangle. In this embodiment, to compensate for the slight deviation of the first object detection model in edge localization during cropping, the bounding rectangle is extended outward by several pixels (e.g., 5 to 10 pixels) around each side to retain complete icon boundary information. After obtaining the icon candidate area images, this embodiment performs a preprocessing operation. Specifically, the preprocessing operation fills the colored interference lines on the icon candidate area images with the background color according to the color chromaticity value distribution in the Hue Saturation Value (HSV) color space, resulting in the preprocessed icon candidate area images. This preprocessing operation effectively filters out non-content interference elements such as colored annotation lines and border lines around the icons, preventing these interference elements from being misjudged as icon foreground in the subsequent fine segmentation stage, thereby improving the purity of icon foreground extraction.

[0024] Next, in this embodiment, the preprocessed icon candidate region image is input into a pre-trained second object detection model for detection. The model outputs the detection box coordinates for the icon's foreground entity region. Based on these coordinates, pixels within the detection box are assigned foreground values, and pixels outside the detection box are assigned background values, generating a binary mask. This binary mask is used as the icon's foreground entity region mask. Compared to the first object detection model, this second object detection model uses finely labeled icon foreground contour data during training, enabling it to learn subtle features of the icon edges. Therefore, it can compensate for the insufficient edge accuracy of the first-level coarse detection model, achieving accurate separation of the icon entity region from the background and interference lines. This allows for pixel-by-pixel determination of the foreground and background, precise removal of background areas and residual interference lines, and the acquisition of the icon's foreground entity region mask. Specifically, this icon foreground entity region... In this embodiment, the pixel values ​​of the foreground region in the domain mask are set to 1, and the pixel values ​​of the background region are set to 0. The preprocessed icon candidate region image is then subjected to a pixel-by-pixel masking operation based on the icon foreground entity region mask. The original pixels corresponding to the regions with a value of 1 in the icon foreground entity region mask are retained, while the pixels with a value of 0 are set to the background color. This generates a clean icon image that removes the background and retains only the icon foreground entity region. The specific operation process is as follows: the icon foreground entity region mask and the preprocessed icon candidate region image are multiplied pixel by pixel. Pixels with a mask value of 1 are retained, and pixels with a mask value of 0 are removed. This results in an icon image that contains only the icon foreground entity. As a result, the output icon image has removed irrelevant backgrounds, border lines, and interfering color blocks from the page, effectively reducing the interference of background noise on feature point extraction and matching, and improving the accuracy of the comparison.

[0025] Since pixel-level comparison can quickly detect differences in PDF documents with minor version differences (such as those with only a single character or punctuation mark modified), this embodiment first preprocesses, resizes, and performs initial pixel-level screening on the extracted icon images to quickly identify any differences and eliminate non-content-related interference. Specifically, this embodiment performs grayscale conversion, denoising, and magnification preprocessing on the extracted icon images based on their pixel data to obtain preprocessed icon images. The grayscale conversion uses a weighted average method, converting the red, green, and blue channel pixel values ​​of the color image into single-channel grayscale values ​​according to preset weights to eliminate the impact of color channel differences on subsequent comparisons. The denoising process uses median filtering. The algorithm in this embodiment takes a neighborhood window centered on each pixel and replaces the center pixel value with the median value of the pixels within the neighborhood window, thereby effectively filtering out salt-and-pepper noise and scanning noise. The magnification process uses a bilinear interpolation algorithm to scale the two icon images proportionally according to their size ratio, so that the physical size (i.e., pixel width and height) of the two images is consistent, ensuring the correct correspondence of subsequent pixel-by-pixel operations. This scaling operation uses the larger size of the two images as a reference and performs bilinear interpolation to magnify the smaller image, avoiding pixel misalignment due to inconsistent sizes. Through the above preprocessing, this embodiment ensures that the two icon images to be compared are consistent in grayscale space, noise level, and spatial resolution, improving the robustness of subsequent matching.

[0026] In this embodiment, at least two pre-processed icon images to be compared are compared in size. If the two icon images are not the same size, the smaller icon image is used as the reference image. The four edges of the reference image are cropped by a preset number of pixels, for example, 5 to 10 pixels are cropped from each edge to obtain the first image to be compared, denoted as image A. In practical applications, the number of pixels to be cropped can be determined by rounding down half of the difference between the width and height of the two images to ensure that the size of the first image after cropping is not greater than the size of the other image, and the cropping area only involves the blank or low information area of ​​the image edge to avoid cropping the core content of the icon. This cropping process eliminates redundant pixels at the edges caused by inconsistent page cropping during PDF conversion, making the core content area of ​​the reference image more compact.

[0027] In this embodiment, image A is used as the template image, and another preprocessed icon image is used as the target image. Template matching search is performed on the target image using a normalized cross-correlation matching algorithm. The template image is slid pixel by pixel on the target image. At each position, the normalized cross-correlation coefficient of the corresponding pixel values ​​in the template image and the target image is calculated. This normalized cross-correlation coefficient reflects the similarity of the two regions in terms of brightness distribution patterns. The normalized cross-correlation coefficient ranges from -1 to +1, with a value closer to +1 indicating higher similarity. After traversing all possible sliding positions in the target image, the coordinates of the sliding position where the normalized cross-correlation coefficient reaches its maximum value are recorded. The dynamic position coordinates are the best matching position of the template image in the target image. Subsequently, in this embodiment, the corresponding area is cropped from the target image using the top left corner as the starting point and the width and height of the template image as the cropping size. This area is used as the second image to be compared, denoted as image B. Thus, this embodiment has found the precise corresponding area of ​​the same icon in two different document images through template matching, so that image A and image B are precisely aligned in spatial position and have the same pixel size. This effectively solves the problem of icon position offset caused by changes in document layout, avoids false differences caused by overall offset, and provides a pixel-level precise spatial correspondence for subsequent pixel-by-pixel comparison.

[0028] To achieve rapid pixel-level difference screening, this embodiment performs pixel-by-pixel differential comparison on images A and B. Specifically, it calculates the absolute value of the grayscale difference between corresponding pixels in images A and B, and constructs a difference image of the same size as the original images using the absolute values ​​of all pixel differences. The value of each pixel in the difference image represents the degree of grayscale difference between the two images at that location; a larger pixel value indicates a more significant difference at that location. Furthermore, this embodiment counts the total number of pixels in the difference image whose values ​​are greater than a preset difference threshold, obtaining the number of differing pixels. If the number of differing pixels is less than the preset difference pixel threshold, then... The difference pixel threshold is set according to the proportion of the total number of pixels in the image. For example, if the difference pixel ratio is less than 5% of the total number of pixels, the two images are considered to be basically the same. At this time, no further fine comparison is needed, and the results can be directly output in the post-processing stage. If the number of difference pixels is greater than or equal to the preset difference pixel threshold, it indicates that there is a substantial difference in content between the two icon images. Fine comparison needs to be carried out in the feature point matching stage. This embodiment adopts a phased strategy of first screening and then fine comparison. The comparison results are quickly output for images with no significant differences, which greatly improves the overall comparison efficiency and avoids performing time-consuming high-precision feature point matching for all images.

[0029] It should be noted that when the number of differing pixels is less than a preset difference pixel threshold, this embodiment performs post-processing operations, specifically morphological opening and closing operations on the differing image. Morphological opening involves first performing erosion and then dilation, eliminating isolated differing points caused by single-pixel noise, compression distortion edges, or scanning noise. Morphological closing involves first performing dilation and then erosion, filling tiny gaps within the differing region and connecting differing pixels belonging to the same content change into a complete region. Both morphological operations use a 3x3 rectangular kernel. Through this morphological filtering, false differences introduced by non-content-related factors such as compression algorithm differences and resolution rounding errors during PDF-to-image conversion are effectively eliminated. Next, this embodiment performs connected component analysis on the retained true differing pixels, using an eight-neighbor connectivity determination method. Pixels in the difference image whose pixel values ​​are greater than a preset difference threshold and whose eight neighboring pixels contain other difference pixels are grouped into the same connected component, resulting in several independent difference connected components. For each difference connected component, the coordinate data of its minimum bounding rectangle is calculated, that is, the minimum and maximum coordinate values ​​of the connected component in the horizontal direction and the minimum and maximum coordinate values ​​in the vertical direction, thus completing the coordinate localization of the difference location. The coordinate data of the minimum bounding rectangle of all difference connected components are summarized, and the preliminary comparison result is output. The preliminary comparison result includes the position coordinates, pixel area, and difference type label of each difference region. This embodiment uses connected component analysis to aggregate scattered difference pixels into difference regions with clear boundaries, realizing accurate positioning and quantitative statistics of differences. It avoids the problems of low efficiency and oversensitivity to small offsets in the existing technology of pixel-by-pixel moving matching. At the same time, it ensures that the difference results output in the initial screening stage have actual physical meaning, providing traceable difference positioning information for subsequent manual review.

[0030] When the number of differing pixels is greater than or equal to a preset difference pixel threshold, this embodiment performs a feature point matching stage. Specifically, the icon image is input into a pre-trained text detection model for character-level localization, generating character box coordinate information for all characters. This text detection model uses a Differentiable Binarization Network (DBNet) based on a differentiable binary architecture. This model has been trained and optimized for small-sized characters, compact layouts, and text embedded in icons, and has the ability to detect curved text and locally small-sized text, thereby outputting high-precision character-level coordinate boxes. The coordinate information of each character box is represented by the pixel coordinates of the four vertices of the character box, and the area inside the box is the area of ​​a single printed character. This ensures that even when characters are densely arranged, fonts are diverse, or there is tilted text, accurate character position information can still be obtained, providing basic data support for subsequent semantic feature extraction. It should be noted that the first object detection model, the second object detection model, and the text detection model are all trained using a pre-labeled PDF icon sample dataset. The training objective of the first object detection model is to maximize the icon area. Domain recall: The training objective of the second object detection model is to maximize foreground segmentation accuracy, and the training objective of the text detection model is to minimize character localization error. This not only overcomes the edge blurring and background residue problems caused by single-level detection in existing technologies, but also adopts a text detection model optimized for small-sized characters and compact layouts. This solves the problems of missed detection and inaccurate boundaries that are easy to occur when general optical character recognition methods locate embedded text in icons. It effectively overcomes the shortcomings of traditional optical character recognition technology in complex layouts, multilingual scenarios, and scenarios with embedded text in icons, as well as the difficulty in separating text and icon boundaries. This improves the accuracy of icon character matching from 70% to 80% of traditional methods to over 95%, especially reducing the false positive rate by 90% in complex layouts and multilingual scenarios.

[0031] S3. Construct a semantic hierarchy mask based on the character box coordinate information, and extract semantic feature points layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor.

[0032] In some implementations, the semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask; correspondingly, the step of constructing the semantic hierarchy mask based on the character box coordinate information includes: Using the pixel matrix of the icon image as a base, an all-zero mask matrix is ​​initialized as the initial state of the character mask, and the vertex pixel coordinates of each character box are read from the character box coordinate information; Based on the vertex pixel coordinates, assign the first value to all pixels within the area covered by each character box, and assign the second value to the remaining area to generate a character mask; Based on the boundary of each character box, shrink inward by a first preset number of pixels and expand outward by a second preset number of pixels. Assign the first value to the pixels in the outline ring area formed after shrinking and expanding, and assign the second value to the pixels in the remaining area to generate a character edge mask. Obtain the outer contour of the icon image, take all pixels within the outer contour as initial pixels and assign them a first value, remove the pixels with the first value from the initial pixels one by one in the character mask, assign the first value to the pixels in the remaining non-character area after removal, and assign the second value to the remaining pure character area to generate the icon mask. The character mask, the character edge mask, and the icon mask are integrated into a semantic-level mask, wherein the first value and the second value are the binarized values ​​of the foreground region and the background region, respectively.

[0033] In this specific embodiment, the pixel matrix of the icon image is used as the basis. A zero-value mask matrix with the same size as the icon image and all pixel values ​​are zero is initialized as the initial state of the character mask matrix. The pixel coordinates of the four vertices of each character box in the image coordinate system are read from the character box coordinate information. For axis-aligned rectangular character boxes (i.e., the border is parallel to the image coordinate axis), this embodiment uses a pixel traversal filling algorithm to traverse each pixel position within the rectangular area covered by the upper left to lower right corner of the character box, and sets the mask value of that pixel position as the first value. For character boxes with a tilt angle (i.e., the border is not parallel to the image coordinate axis and is arranged diagonally), this embodiment uses a polygonal mask filling algorithm to enclose the coordinates of the four vertices of the character box into a quadrilateral area, and traverses and fills all pixels inside the quadrilateral, setting the mask value as the first value. After filling all character boxes, this embodiment performs normalization processing on the current character mask matrix, uniformly reducing all non-zero values ​​in the character mask matrix to the first value and keeping all zero values ​​as zero, ensuring the character mask... The matrix is ​​in a binary format, meaning that pixel values ​​only have two states: foreground and background, resulting in a character mask. In this embodiment, the foreground value is a first value, and the background value is a second value. The first value can be set to 1, representing the foreground region of the character; the second value can be set to 0, representing the background region. This embodiment uses this conversion process to transform the character box coordinates output by the text detection model into a binary mask image that completely corresponds to the pixel space of the icon image, providing a pixel-level spatial mapping basis for the precise definition of the semantic region. In this character mask, all pixel regions covered by the character box are assigned the first value (foreground), indicating that the position belongs to the character region; all pixel regions not covered by the character box are assigned the second value (background), indicating that the position does not belong to the character region. This character mask identifies the precise pixel range of all characters in the icon image. It is used in subsequent feature point extraction to limit the search range of the character center feature point to the character region, ensuring that feature points fall primarily on the character entity and avoiding the generation of redundant feature points in blank backgrounds or irrelevant areas.

[0034] Next, based on the generated character mask, this embodiment extracts the edge region of each character box in the character mask. Specifically, for each character box, this embodiment shrinks its boundary inward by a first preset number of pixels (e.g., shrinks by 3 pixels) and expands the character box boundary outward by a second preset number of pixels (e.g., expands by 1 pixel). A contour ring-shaped region (i.e., character edge strip-shaped region) is formed between the two boundaries after shrinkage and expansion. The mask value of all pixels in the contour ring-shaped region is set to the first value, and the pixel values ​​of all other regions are set to the second value to generate a character edge mask. This character edge mask identifies the pixel range where the contour edge of each character is located.

[0035] Simultaneously, this embodiment obtains the maximum bounding contour of the icon foreground entity region output by the second object detection model and uses it as the bounding contour of the icon image. This bounding contour includes all foreground elements in the icon, which may include characters, symbols, patterns, and geometric structures. In this embodiment, all pixels inside the bounding contour are used as the initial pixel set, and all pixel values ​​in this initial pixel set are initially set to a first value as the overall icon region mask. Subsequently, all pixels in the generated character mask that have the first value (i.e., character region pixels) are removed pixel by pixel from the overall icon region mask. Specifically, on the matrix of the overall icon region mask, if a pixel position has the first value in the character mask, then the mask value of that pixel position is set to a second value; if the pixel position has the second value in the character mask, then the original first value remains unchanged. After the removal operation is completed, the remaining area with the first value is the icon region. The semantic regions of non-character elements in the icon can include icon structural elements such as lines, symbols, and geometric structures. In this embodiment, all values ​​less than zero in the mask matrix after removal are uniformly set to zero to ensure that the mask values ​​are in a binary state, and finally an icon mask is generated. This icon mask identifies the area where structural elements other than characters are located in the icon, so that subsequent feature extraction can capture the geometric structural information of non-text elements such as symbols and graphics in the icon, making up for the insensitivity of pure character feature points to changes in the overall structure of the icon. In this embodiment, the character mask, character edge mask, and icon mask are stored in a matrix stacked according to the same image size to form a semantic hierarchical mask containing three semantic hierarchical channels. In this semantic hierarchical mask, the character mask identifies the character entity area, the character edge mask identifies the character outline area, and the icon mask identifies the non-character structural area. Together, they constitute a hierarchical description of the complete semantic space of the icon image.

[0036] In some implementations, the semantic feature points include at least character center feature points, character outline feature points, and icon structure feature points; correspondingly, the step of extracting semantic feature points hierarchically through the semantic hierarchy mask to construct the PDF feature descriptor includes: The geometric center of each character frame is calculated based on the character frame coordinate information, and several sampling points are uniformly sampled within the character frame according to a preset grid division method, with the geometric center as the reference. Calculate the mean gray-level gradient in the neighborhood of each sampling point, and retain the sampling points whose mean gray-level gradient is greater than a first preset threshold and are located in the foreground area indicated by the character mask as character center feature points; Calculate the corner response value of each pixel within the area defined by the character edge mask, and determine the pixels whose corner response value is greater than the second preset threshold and are located within the foreground area indicated by the character edge mask as candidate corners. Perform non-maximum suppression on the candidate corners, and use the candidate corners retained after suppression as character contour feature points. Within the non-character semantic region defined by the icon mask, key points of the icon outline are extracted as icon structural feature points, and the character center feature points, the character outline feature points, and the icon structural feature points are integrated to form semantic feature points; The semantic category of each semantic feature point and its normalized position relative to its corresponding character frame are encoded to obtain the PDF feature descriptor; the PDF feature descriptor includes semantic category encoding and position relative encoding.

[0037] In a specific embodiment, this embodiment calculates the geometric center coordinates of each character frame based on the pixel coordinate data of the four vertices of each character frame in the character frame coordinate information. The geometric center coordinates include the center horizontal coordinate and the center vertical coordinate. In this embodiment, the midpoint of the horizontal left and right boundaries of the character frame is taken as the center horizontal coordinate, and the midpoint of the vertical upper and lower boundaries is taken as the center vertical coordinate. Using this geometric center as a reference, a number of sampling points are uniformly sampled within the character frame according to a 3x3 grid. The number of sampling points can be adjusted according to the actual size of the character frame. For example, for a larger character frame, the grid can be divided into 4x4 or even 5x5, and the number of sampling points can be increased to 16 or 25 respectively. For a smaller character frame, a 3x3 grid with a total of 9 sampling points is maintained. In actual implementation, the above grid division method is not limited to 3x3. Other division methods can also be adopted according to the actual size of the character frame and the complexity of the character. For example, as another embodiment, for character frames with small character sizes or simple stroke structures... In this embodiment, a 2x2 grid division method can be used, dividing the character frame evenly into four quadrants with the geometric center as the reference, and taking a sampling point at the center of each quadrant, for a total of four sampling points. For character frames with larger size or complex strokes, a 6x6 or 7x7 grid division method can be used, and the number of sampling points is increased accordingly to thirty-six or forty-nine to achieve more refined coverage of the character area. As another embodiment, for characters with special shapes or irregular layouts, this embodiment can dynamically determine the grid division method based on the aspect ratio of the character frame. When the aspect ratio of the character frame is close to 1:1, this embodiment can use a square grid division, such as a 4x4 grid division method; when the aspect ratio of the character frame is greater than 2, a rectangular grid division with more horizontal grids than vertical grids is used, such as a 5x3 grid division method; when the aspect ratio of the character frame is less than 0.5, a rectangular grid division with more vertical grids than horizontal grids is used, such as a 3x5 grid division method.

[0038] For each sampling point, this embodiment calculates the average gray-level gradient of all pixels in its local neighborhood. The specific method for calculating the average gray-level gradient is as follows: In this embodiment, the grayscale values ​​of all pixels within a three-by-three neighborhood window surrounding the sampling point are extracted. The absolute values ​​of the grayscale difference of each pixel in the horizontal and vertical directions within the neighborhood window are calculated. The average value of the absolute values ​​of the grayscale difference of all pixels is taken as the mean grayscale gradient of the sampling point. Sampling points whose mean grayscale gradient is greater than a first preset threshold and are located within the foreground area indicated by the character mask are retained as character center feature points, while other sampling points are discarded. It should be noted that when the mean grayscale gradient is greater than the first preset threshold, it indicates that the sampling point is located at the edge of the character stroke or in a textured area, rather than in a flat area or background area inside the character. This ensures that the character center feature point is generated only in a position inside the character with sufficient texture information, avoiding the generation of invalid feature points in smooth, featureless areas.

[0039] Next, in this embodiment, the corner response value of each pixel is calculated within the contour ring area defined by the character edge mask. The specific method for calculating the corner response value is as follows: For any pixel within the character edge mask, this embodiment calculates the grayscale gradient values ​​of that pixel in the horizontal and vertical directions. A 5x5 Gaussian weighted window is then taken centered on that pixel. Within the intersection of this Gaussian weighted window and the character edge mask, each pixel is assigned a Gaussian weight, resulting in weighted pixels. The pixel at the center of the Gaussian weighted window has the highest weight, gradually decreasing towards the edges. Then, this embodiment calculates the squared values ​​of the horizontal and vertical grayscale gradients of all weighted pixels, as well as the product of the horizontal and vertical grayscale gradients. These three statistical values ​​are then combined to form a structure tensor matrix. The matrix is ​​a 2x2 symmetric matrix. The top-left element is the sum of the squared horizontal gray-level gradients of all weighted pixels, and the bottom-right element is the sum of the squared vertical gray-level gradients of all weighted pixels. The two off-diagonal elements are the sum of the products of the horizontal and vertical gray-level gradients of all weighted pixels. In this embodiment, two eigenvalues ​​of the structure tensor matrix are calculated, and the smaller of the two eigenvalues ​​is taken as the corner response value of the current pixel. This smaller eigenvalue reflects the minimum gradient change intensity in the region where the pixel is located in the two orthogonal directions. When this value is large, it indicates that there is a significant gray-level change in the pixel in both orthogonal directions, that is, the pixel is located at a corner or strong edge intersection. The specific calculation formula of the structure tensor matrix is ​​as follows: In the formula, It is the structure tensor matrix; Let u be the pixel coordinates within the local neighborhood window, where u is the horizontal coordinate and v is the vertical coordinate. It is a local neighborhood window centered on the current pixel to be detected; This is a character edge mask. A value of 1 indicates that the pixel belongs to the character outline area, while a value of 0 indicates that it does not belong to the character outline area. This indicates that the summation operation is performed only within the intersection area of ​​the local neighborhood window W and the character edge mask; This is a Gaussian window weighting function, which is used to enhance the influence of the center pixel of the window and reduce the interference of edge pixels. The center pixel of the window has the largest weight, which gradually decreases towards the edge. The square of the horizontal grayscale gradient value; Image in pixel coordinates The first-order grayscale gradient value along the horizontal direction; Image in pixel coordinates The first-order grayscale gradient value along the vertical direction; The square of the grayscale gradient value in the vertical direction; It is the product of the horizontal gradient value and the vertical gradient value.

[0040] When the corner response value is greater than the second preset threshold and the pixel is located within the foreground area indicated by the character edge mask, the pixel is determined to be a candidate corner. To avoid corners being too dense or sparse within the same character frame, this embodiment also needs to perform non-maximum suppression processing on all candidate corners. Specifically, within the character edge mask area, a local window is taken with each candidate corner as the center. If the corner response value of the candidate corner is the maximum value within its local window, the candidate corner is retained; otherwise, it is discarded. After non-maximum suppression, it is ensured that each character frame retains three to eight evenly distributed corners. The retained candidate corners are marked as character contour feature points. These feature points are concentrated at the turning points, intersections, and endpoints of character strokes, and other prominent positions of the contour structure, which can accurately capture several features of the character. The shape features provide key features for fine comparison of character shapes. At the same time, this embodiment uses a corner detection algorithm to extract key points of the icon outline in the non-character semantic area defined by the icon mask, as icon structural feature points. Specifically, in the foreground area indicated by the icon mask, the same corner response value calculation method as described above is used to detect key points of icon structure such as line intersections, endpoints, and inflection points. The detected key points of icon structure are evenly distributed and filtered to avoid excessive aggregation in local areas, ensuring that the icon structural feature points can cover the overall geometric structure of the icon. These feature points are located in local positions with geometric structural significance, such as the edges and corners of graphic symbols in the icon and line intersections, which can effectively represent the overall shape and layout features of the icon, complementing the character feature points.

[0041] This embodiment constructs a PDF feature descriptor for each semantic feature point extracted above. The PDF feature descriptor includes at least semantic category encoding and positional relative encoding. Semantic category encoding is used to distinguish the semantic type of the feature point. This embodiment uses three different values ​​to represent three semantic feature point types: one value represents the character center feature point, the second value represents the character outline feature point, and the third value represents the icon structure feature point. This ensures that subsequent matching only allows matching between feature points with the same semantic category encoding, fundamentally avoiding incorrect pairing between feature points of different semantic types and maintaining semantic consistency. Positional relative encoding is used to eliminate the influence of image size scaling on feature matching. For character center and character outline feature points, this embodiment calculates the normalized coordinates of the feature point relative to its corresponding character frame. This is done by subtracting the minimum horizontal coordinate value of the character frame from the horizontal coordinate of the feature point and then dividing by the width of the character frame, and subtracting the minimum horizontal coordinate value from the vertical coordinate of the feature point. After removing the minimum vertical coordinate value of the character box and dividing it by the height of the character box, we obtain the horizontal and vertical normalized coordinates. For the feature points of the icon structure, we calculate the normalized coordinates of the feature point relative to the overall outer contour of the icon. Specifically, we subtract the minimum horizontal coordinate value of the icon's outer contour from the horizontal coordinate of the feature point and then divide it by the width of the icon's outer contour to obtain the horizontal normalized coordinates. At the same time, we subtract the minimum vertical coordinate value of the icon's outer contour from the vertical coordinate of the feature point and then divide it by the height of the icon's outer contour to obtain the vertical normalized coordinates. This relative encoding eliminates the influence of image size scaling or resolution differences on the absolute position of the feature points, making the position description of the feature points scale-invariant. This embodiment integrates the encoding information of the above two dimensions to form a PDF feature descriptor corresponding to each semantic feature point. This makes the feature descriptor not only contain local visual information but also integrate the semantic structural characteristics of the PDF document, improving the accuracy and robustness of feature matching.

[0042] In other implementations, the PDF feature descriptor further includes local texture coding and context coding. Local texture coding is used to capture the local visual features of feature points, ensuring the distinguishability of feature points. In this embodiment, a 3x3 neighborhood window is taken centered on the feature point, and the average gray value of all pixels within the window is calculated as the gray value mean. At the same time, the average of the squares of the differences between the gray values ​​of all pixels within the window and the gray value mean is calculated as the gray value variance, and the dominant direction of the gray value gradient of all pixels within the window is calculated as the gradient direction. The gray value mean, gray value variance, and gradient direction are combined to form the local texture coding. Context coding is used to strengthen the correlation between feature points and PDF document characteristics. Context coding includes character count, line density, and layout structure features. For the character count, this embodiment counts the number of characters within the region to which the feature point belongs, as determined by the text detection model. The total number of valid character frames after detection and filtering is calculated. If a feature point belongs to a feature point within a character frame, the statistical value is the total number of characters corresponding to a single character frame, where a single character frame corresponds to one character, and the statistical value is one. For line density, this embodiment uses the three-by-three neighborhood region to which the feature point belongs as the calculation range, counts the number of pixels in the region whose gray-level gradient value is greater than the preset line threshold, divides the number of pixels by the total number of pixels in the local region, and normalizes the result to the interval between zero and one to obtain the line density. For layout structure features, this embodiment calculates the horizontal coordinates of the character frame and its relative position on the page. Based on the horizontal coordinates of the character frame and its relative position on the page, the alignment type of the character frame or text line is determined. The alignment types are divided into four types: left alignment, right alignment, center alignment, and justified alignment. The alignment type is used as the layout structure feature.

[0043] S4. Perform semantic consistency matching on the semantic feature points of each icon image according to the PDF feature descriptor to obtain a matching dataset, and filter out valid matching point pairs from the matching dataset.

[0044] In some implementations, the step of performing semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain a matching dataset, and then filtering out valid matching point pairs from the matching dataset includes: Extract the semantic category code corresponding to each semantic feature point from the PDF feature descriptor, and determine the semantic feature points with the same semantic category code as matchable feature point pairs; The relative positional deviation of each matchable feature point pair is calculated based on the relative positional encoding, and the offset of each matchable feature point pair is determined based on the relative positional deviation. The matching confidence of each matchable feature point pair is determined based on the local texture encoding and context encoding of each matchable feature point pair. A matching dataset is generated based on the offset and matching confidence of each matchable feature point pair; Based on the matching dataset, matchable feature point pairs with matching confidence lower than a preset confidence threshold or offset exceeding a preset offset threshold are removed to obtain initial screening of matching point pairs. Select matching pairs whose semantic category is character center feature point or character contour feature point from the initial screening matching point pairs, and use them as matching pairs to be compared; Calculate the size ratio of the character box corresponding to the matching pair to be compared, and remove the matching pairs whose size ratio deviation exceeds the preset ratio range to obtain the valid matching point pairs.

[0045] In a specific embodiment, this embodiment first extracts the semantic category code corresponding to each semantic feature point from the PDF feature descriptor. The semantic category code value corresponds to three semantic types: character center feature point, character outline feature point, and icon structure feature point. When performing feature point matching, this embodiment only allows feature points with the same semantic category code to establish a matching relationship. Specifically, this embodiment sets character center feature points to match only with character center feature points, character outline feature points to match only with character outline feature points, and icon structure feature points to match only with icon structure feature points. For any two feature points with different semantic category codes, they are directly prohibited from establishing a matching relationship and are not included in the subsequent matching calculation process. This semantic consistency check serves as a hard constraint for matching, fundamentally preventing incorrect pairing between feature points of different semantic types, such as incorrectly matching a character center feature point to an icon structure feature point, ensuring the semantic rationality of the matching and reducing the mismatch rate.

[0046] For matchable feature point pairs that pass the semantic category consistency check, this embodiment calculates the absolute value of their coordinate difference in the horizontal direction and the absolute value of their coordinate difference in the vertical direction, respectively. The absolute values ​​of the coordinate differences in the two directions are then weighted and summed to obtain the offset of the matchable feature point pair. For each matchable feature point pair, this embodiment determines the matching confidence of each pair based on local texture encoding and context encoding. This matching confidence is used to characterize the similarity of the matchable feature point pairs at the local visual feature and document context levels. Specifically, this embodiment extracts the matchable feature point pairs... The gray-scale mean, variance, gradient direction, and line density of the neighborhood of each feature point pair are normalized for each continuous value dimension. The sum of squares of the differences in the corresponding dimensions is calculated using Euclidean distance and then squared to obtain the texture and context combined distance value. The reciprocal of the combined distance value is normalized to obtain the matching confidence. The offsets and matching confidence data of all matching feature point pairs are summarized to generate a matching dataset. This matching dataset contains successfully matched feature point pairs, unmatched feature points, and the offsets and matching confidence of each matching feature point pair.

[0047] Next, this embodiment sequentially filters each pair of matchable feature points in the matching dataset. Specifically, it checks whether the matching confidence of the current matchable feature point pair is lower than a preset confidence threshold, which is set according to the actual application scenario. Simultaneously, it checks whether the horizontal or vertical offset of the current matchable feature point pair exceeds a preset offset threshold, which is set according to the expected variation range of the image size and icon content. If a matching pair meets either of the above two conditions—that is, the matching confidence is lower than the preset confidence threshold or the offset exceeds the preset offset threshold—then the matchable feature point pair is directly removed from the matching dataset and not retained as a valid matching point pair. This embodiment only retains matching pairs with a matching confidence greater than or equal to the preset confidence threshold and an offset less than or equal to the preset offset threshold, obtaining the initial screening of matching point pairs. This dual-threshold initial screening quickly eliminates feature point pairs with poor matching quality or abnormal spatial positions through confidence and offset indices. Then, this embodiment further filters from the initial screening of matching point pairs to identify match points with semantic categories of character center feature points or character contour feature points. The system pairs characters as matching pairs to be verified. For each matching pair, this embodiment first determines the size data of the two character boxes corresponding to the matching pair. The difference in the horizontal coordinates of the left and right boundaries of the character boxes is taken as the width, and the difference in the vertical coordinates of the upper and lower boundaries is taken as the height, thus obtaining the width and height of the two character boxes. Next, this embodiment calculates the ratio of the widths and the ratio of the heights of the two character boxes to obtain the width ratio and height ratio of the two character boxes. The width ratio and height ratio of the two character boxes are compared with the preset ratio range. If either the width ratio or the height ratio exceeds the preset ratio range, it indicates that there is a difference in size between the two character boxes. The character corresponding to the matching pair may have undergone font changes, scaling, or replacement in different versions of the document, resulting in insufficient matching reliability. Therefore, the matching pair is discarded. This character box size ratio verification utilizes the prior knowledge that the same character in a PDF document should maintain approximately the same size in different versions, effectively eliminating incorrect matches caused by character scaling or font changes, and further improving the matching accuracy.

[0048] S5. Filter the character boxes in the icon image using the effective matching point pairs to obtain the difference character boxes, and perform different position coordinate positioning on the difference character boxes to obtain the document character comparison result.

[0049] In some implementations, the step of filtering character boxes in the icon image using the effective matching point pairs to obtain differing character boxes, and then performing cross-position coordinate positioning on the differing character boxes to obtain document character comparison results includes: Based on the valid matching point pairs, the character boxes in each icon image are filtered out, and the character boxes in which valid matching points fall are removed, while the character boxes in which no valid matching points fall are marked as difference character boxes. Adjacent difference character boxes are merged based on the intersection-union ratio and pixel spacing to generate a fused difference character box, and the coordinate position, semantic level, and difference type of the fused difference character box are obtained. In the PDF document to be compared, the coordinates, semantic level, and difference type of the merged difference character boxes are marked synchronously to obtain the document character comparison results.

[0050] In a specific embodiment, this embodiment traverses each character box in each icon image based on valid matching point pairs and character box coordinate information, detecting whether there is at least one valid matching point within the rectangular range of the current character box. If one or more valid matching points fall within the character box, it is determined that the character content corresponding to the character box is consistent in the two PDF documents, and the character box is removed from the difference candidate set. If no valid matching points are distributed within a certain character box, it is determined that the character content corresponding to the character box is different in the two PDF documents, and the character box is marked as a difference character box. Since the character boxes output by the text detection model are at the single character level, multiple adjacent difference character boxes may actually belong to the same word, the same line of text, or the same group of text within the icon. This embodiment needs to merge them into a semantically complete overall difference region. Specifically, this embodiment performs a box fusion operation on the marked difference character boxes, using Intersection over Union (IoU). The Intersection over Union (IOU) method, along with a dual-dimensional judgment approach using pixel vertical and horizontal spacing, merges scattered single-character detection boxes into word-level, text line-level, or whole-text group boxes within icons. Specifically, all difference character boxes are sorted from left to right and top to bottom according to their position in the image. Adjacent difference character boxes are then traversed sequentially. For any two adjacent difference character boxes, the Intersection over Union (IoU) ratio is calculated, which is the ratio of the area of ​​their intersection region to the area of ​​their union region. Simultaneously, the minimum pixel spacing in the vertical and horizontal directions of the two difference character boxes is calculated. If the IoU ratio is greater than a preset threshold, or the vertical spacing is less than a preset threshold and the horizontal spacing is less than a preset threshold, then the two difference character boxes are determined to belong to the same category. For the same semantic unit, they are merged into a group of difference character boxes. For all difference character box groups that are determined to be the same semantic unit, the minimum and maximum coordinate values ​​of all difference character boxes in the horizontal direction and the minimum and maximum coordinate values ​​in the vertical direction are taken to form the largest bounding rectangle of the difference character box group, which is used as the merged difference character box. The merged difference box no longer represents a single character, but represents the difference area of ​​a word-level, text line-level, or icon-level overall text group. In this embodiment, through this fusion operation, the originally scattered single-character difference boxes are aggregated into a whole area with semantic integrity, making the difference output result more in line with the actual needs of document reading and review, and avoiding the fragmentation problem caused by splitting the differences of multiple characters in the same word for output.

[0051] For each fused difference character box, this embodiment obtains the pixel coordinates of its four vertices and determines its semantic level based on its spatial assignment in the semantic level mask. If the difference character box is located in the foreground area indicated by the character mask, its semantic level is the character level; if it is located in the foreground area indicated by the character edge mask, its semantic level is the character outline level; and if it is located in the foreground area indicated by the icon mask, its semantic level is the icon structure level. Simultaneously, the difference type is determined based on the comprehensive performance of the difference area in pixel-level initial screening and feature point fine-tuning. Difference types include character missing, character replacement, character addition / deletion, stroke deformation, icon line missing, and icon structure change. Then, the coordinates, semantic level, and difference type data of the merged difference character boxes are simultaneously marked on the page image corresponding to the PDF document to be compared. For example, based on the pixel coordinates of the four vertices of the difference character boxes, difference marker boxes are drawn on the page image converted from the original PDF document, and difference type and semantic level labels are marked next to the difference marker boxes. The marked page image is integrated with the difference statistics to generate document character comparison results. The document character comparison results include the coordinates, semantic level, and difference type of each difference region, so that quality inspectors can quickly locate the version change content through the document character comparison results, meeting the needs of the manufacturing industry for document version consistency and traceability.

[0052] This invention provides a method for comparing PDF document images. The method involves converting at least two PDF documents to be compared into image formats to obtain document images corresponding to each PDF document; extracting icon regions from each document image to obtain corresponding icon images; extracting character box coordinate information from each icon image; constructing a semantic hierarchy mask based on the character box coordinate information; extracting semantic feature points layer by layer using the semantic hierarchy mask to construct a PDF feature descriptor; the semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask; the semantic feature points include at least character center feature points, character contour feature points, and icon structure feature points; performing semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain a matching dataset; filtering valid matching point pairs from the matching dataset; filtering character boxes in the icon images using valid matching point pairs to obtain differing character boxes; and locating the differing character boxes using their different coordinates to obtain the document character comparison result. Compared with existing technologies, this method uses techniques such as semantic feature point matching to perform character comparison, which improves the accuracy and robustness of printed character comparison in PDF document images under complex layout scenarios and effectively identifies the location of character differences between documents.

[0053] It should be noted that the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0054] In one embodiment, such as Figure 3 As shown, this embodiment of the invention provides a PDF document image character comparison device, the device comprising: The format conversion module 101 is used to convert at least two PDF documents to be compared into image formats respectively, so as to obtain document images corresponding to each PDF document; The character extraction module 102 is used to extract the icon region from each document image to obtain the corresponding icon image, and extract the character box coordinate information from each of the icon images respectively; The semantic analysis module 103 is used to construct a semantic hierarchy mask based on the character box coordinate information, and extract semantic feature points layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor; The feature matching module 104 is used to perform semantic consistency matching on the semantic feature points of each icon image according to the PDF feature descriptor, obtain a matching dataset, and filter out valid matching point pairs from the matching dataset. The character comparison module 105 is used to filter the character boxes in the icon image using the effective matching point pairs, obtain the difference character boxes, and perform different position coordinate positioning on the difference character boxes to obtain the document character comparison result.

[0055] For specific limitations regarding a PDF document image character comparison device, please refer to the above-described limitations regarding a PDF document image character comparison method, which will not be repeated here. Those skilled in the art will recognize that the various modules and steps described in conjunction with the embodiments disclosed in this application can be implemented in hardware, software, or a combination of both. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0056] This invention provides a PDF document image character comparison device. The device uses a format conversion module to convert at least two PDF documents to be compared into image formats, obtaining document images corresponding to each PDF document. A character extraction module extracts icon regions from each document image to obtain corresponding icon images, and extracts character box coordinate information from each icon image. A semantic analysis module constructs a semantic hierarchy mask based on the character box coordinate information, and extracts semantic feature points layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor. The semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask. The semantic feature points include at least character center feature points, character contour feature points, and icon structure feature points. A feature matching module performs semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain a matching dataset, and filters out valid matching point pairs from the matching dataset. A character comparison module uses the valid matching point pairs to filter character boxes in the icon images, obtaining differing character boxes, and performs out-of-position coordinate positioning on the differing character boxes to obtain the document character comparison result. Compared with existing technologies, this device improves the accuracy and robustness of printed character comparison in PDF document images under complex layout scenarios by using techniques such as semantic feature point matching, and effectively identifies the location of character differences between documents. Optionally, such as Figure 4 As shown, this application embodiment also provides an electronic device, including a processor 401 and a memory 402. The memory 402 stores a program or instructions that can run on the processor 401. When the program or instructions are executed by the processor 401, they implement the various steps of the above-described PDF document image character comparison method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.

[0057] It should be noted that the electronic devices in the embodiments of this application include mobile electronic devices and non-mobile electronic devices. The memory may include volatile memory or non-volatile memory, or both. The processor may be a central processing unit, a microprocessor, an application-specific integrated circuit, a programmable logic device, or a combination thereof. By way of example, but not limitation, the aforementioned programmable logic device may be a complex programmable logic device, a field-programmable gate array (FPGA), a general-purpose array logic (GPA), or any combination thereof. Furthermore, the memory may be a physically independent unit or integrated with the processor, as will be understood by those skilled in the art. Figure 4 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. Specific electronic devices may include more or fewer components than those shown in the figure, or combine certain components, or have the same component arrangement.

[0058] This application also provides a computer-readable storage medium storing a computer-executable program or instructions. When the computer-executable program or instructions are executed by a computer, they implement the various processes of the above-described PDF document image character comparison method embodiments and achieve the same technical effects. To avoid repetition, they will not be described again here.

[0059] The computer-readable storage medium may be a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0060] The above embodiments of this application focus on describing the differences between the various embodiments. As long as the different optimization features between the various embodiments are not contradictory, they can be combined to form a better embodiment. For the sake of brevity, they will not be described in detail here.

[0061] The embodiments described above are merely preferred embodiments of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various improvements and substitutions without departing from the technical principles of this invention, and these improvements and substitutions should also be considered within the scope of protection of this application. Therefore, the scope of protection of this patent application should be determined by the scope of the claims.

Claims

1. A method for comparing characters in PDF document images, characterized in that, Includes the following steps: Convert at least two PDF documents to be compared into image format to obtain document images corresponding to each PDF document; The icon regions of each document image are extracted to obtain the corresponding icon images, and the character box coordinate information is extracted from each of the icon images. A semantic hierarchy mask is constructed based on the character box coordinate information, and semantic feature points are extracted layer by layer through the semantic hierarchy mask to construct a PDF feature descriptor; Based on the PDF feature descriptor, semantic consistency matching is performed on the semantic feature points of each icon image to obtain a matching dataset, and valid matching point pairs are selected from the matching dataset. By filtering the character boxes in the icon image using the effective matching point pairs, different character boxes are obtained, and the different character boxes are located by different coordinates to obtain the document character comparison result.

2. The PDF document image character comparison method as described in claim 1, characterized in that, The step of extracting icon regions from each document image to obtain the corresponding icon image includes: The pre-built first object detection model is used to perform a global scan of each document image to obtain the bounding rectangles corresponding to each icon area; Based on the bounding rectangle, the corresponding icon candidate region image is cropped from each document image, and each icon candidate region image is preprocessed to obtain the preprocessed icon candidate region image. The pre-built second target detection model is used to detect the preprocessed icon candidate region image to obtain the detection box coordinates of the icon foreground entity region, and the icon foreground entity region mask is obtained based on the detection box coordinates. The corresponding icon image is cropped from the preprocessed icon candidate region image using the icon foreground entity region mask.

3. The PDF document image character comparison method as described in claim 1, characterized in that, The semantic hierarchy mask includes at least a character mask, a character edge mask, and an icon mask; Correspondingly, the step of constructing a semantic hierarchy mask based on the character box coordinate information includes: Using the pixel matrix of the icon image as a base, an all-zero mask matrix is ​​initialized as the initial state of the character mask, and the vertex pixel coordinates of each character box are read from the character box coordinate information; Based on the vertex pixel coordinates, assign the first value to all pixels within the area covered by each character box, and assign the second value to the remaining area to generate a character mask; Based on the boundary of each character box, shrink inward by a first preset number of pixels and expand outward by a second preset number of pixels. Assign the first value to the pixels in the outline ring area formed after shrinking and expanding, and assign the second value to the pixels in the remaining area to generate a character edge mask. Obtain the outer contour of the icon image, take all pixels within the outer contour as initial pixels and assign them a first value, remove the pixels with the first value from the initial pixels one by one in the character mask, assign the first value to the pixels in the remaining non-character area after removal, and assign the second value to the remaining pure character area to generate the icon mask. The character mask, the character edge mask, and the icon mask are integrated into a semantic-level mask, wherein the first value and the second value are the binarized values ​​of the foreground region and the background region, respectively.

4. The PDF document image character comparison method as described in claim 3, characterized in that, The semantic feature points include at least character center feature points, character contour feature points, and icon structure feature points; correspondingly, the step of extracting semantic feature points hierarchically through the semantic hierarchy mask to construct the PDF feature descriptor includes: The geometric center of each character frame is calculated based on the character frame coordinate information, and several sampling points are uniformly sampled within the character frame according to a preset grid division method, with the geometric center as the reference. Calculate the mean gray-level gradient in the neighborhood of each sampling point, and retain the sampling points whose mean gray-level gradient is greater than a first preset threshold and are located in the foreground area indicated by the character mask as character center feature points; Calculate the corner response value of each pixel within the area defined by the character edge mask, and determine the pixels whose corner response value is greater than the second preset threshold and are located within the foreground area indicated by the character edge mask as candidate corners. Perform non-maximum suppression on the candidate corners, and use the candidate corners retained after suppression as character contour feature points. Within the non-character semantic region defined by the icon mask, key points of the icon outline are extracted as icon structural feature points, and the character center feature points, the character outline feature points, and the icon structural feature points are integrated to form semantic feature points; The semantic category of each semantic feature point and its normalized position relative to its corresponding character frame are encoded to obtain the PDF feature descriptor; the PDF feature descriptor includes semantic category encoding and position relative encoding.

5. The PDF document image character comparison method as described in claim 4, characterized in that, The step of performing semantic consistency matching on the semantic feature points of each icon image based on the PDF feature descriptor to obtain the matching dataset includes: Extract the semantic category code corresponding to each semantic feature point from the PDF feature descriptor, and determine the semantic feature points with the same semantic category code as matchable feature point pairs; The relative positional deviation of each matchable feature point pair is calculated based on the relative positional encoding, and the offset of each matchable feature point pair is determined based on the relative positional deviation. The matching confidence of each matchable feature point pair is determined based on the local texture encoding and context encoding of each matchable feature point pair. A matching dataset is generated based on the offset and matching confidence of each matchable feature point pair.

6. The PDF document image character comparison method as described in claim 5, characterized in that, The step of filtering out valid matching point pairs from the matching dataset includes: Based on the matching dataset, matchable feature point pairs with matching confidence lower than a preset confidence threshold or offset exceeding a preset offset threshold are removed to obtain initial screening of matching point pairs. Select matching pairs whose semantic category is character center feature point or character contour feature point from the initial screening matching point pairs, and use them as matching pairs to be compared; Calculate the size ratio of the character box corresponding to the matching pair to be compared, and remove the matching pairs whose size ratio deviation exceeds the preset ratio range to obtain the valid matching point pairs.

7. The PDF document image character comparison method as described in claim 1, characterized in that, The steps of filtering character boxes in the icon image using the effective matching point pairs to obtain difference character boxes, and locating the difference character boxes using different coordinates to obtain document character comparison results include: Based on the valid matching point pairs, the character boxes in each icon image are filtered out, and the character boxes in which valid matching points fall are removed, while the character boxes in which no valid matching points fall are marked as difference character boxes. Adjacent difference character boxes are merged based on the intersection-union ratio and pixel spacing to generate a fused difference character box, and the coordinate position, semantic level, and difference type of the fused difference character box are obtained. In the PDF document to be compared, the coordinates, semantic level, and difference type of the merged difference character boxes are marked synchronously to obtain the document character comparison results.

8. A PDF document image character comparison device, characterized in that, The device includes: The format conversion module is used to convert at least two PDF documents to be compared into image formats, so as to obtain the document images corresponding to each PDF document; The character extraction module is used to extract the icon region from each document image to obtain the corresponding icon image, and to extract the character box coordinate information from each of the icon images. The semantic analysis module is used to construct a semantic hierarchical mask based on the character box coordinate information, and to extract semantic feature points layer by layer through the semantic hierarchical mask to construct PDF feature descriptors; The feature matching module is used to perform semantic consistency matching on the semantic feature points of each icon image according to the PDF feature descriptor, obtain a matching dataset, and filter out valid matching point pairs from the matching dataset; The character comparison module is used to filter the character boxes in the icon image using the effective matching point pairs, obtain the difference character boxes, and perform different position coordinate positioning on the difference character boxes to obtain the document character comparison result.

9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the PDF document image character comparison method as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program or instructions, which, when executed by a computer, implement the steps of the PDF document image character comparison method as described in any one of claims 1-7.