Character ghosting simulation method and device, electronic equipment and storage medium
By building a corpus containing font information and text characteristics, dynamically adjusting the drawing position and color depth, and carefully simulating the stroke afterimage during instrument character switching, the problem of the existing technology being unable to recognize the stroke afterimage generated during instrument character switching is solved. , achieving more accurate and real-time data recognition.
Patent Information
- Application Number
- CN202411352951.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-02-07
AI Technical Summary
The prior art cannot recognize the afterimage of strokes generated during instrument character switching, resulting in failure of OCR recognition, affecting the accuracy and real-timeness of the data.
By obtaining the real image of the instrument, a corpus is constructed, including background image, text font information and text characteristics of the instrument, dynamically adjust the corpus drawing position and color depth, carefully simulate background afterimage and stroke afterimage, and generate afterimage simulation images.
It significantly enhances the realism and dynamic sense of the image, improves the visual presentation quality, makes the simulated image closer to the actual scene, effectively solves the problem of OCR recognition failure, and improves the accuracy and real-timeness of the data.
Smart Images

Figure CN119399774A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing and text recognition, and in particular to a method, device, electronic device and storage medium for simulating character afterimages. Background Art
[0002] With the rapid development of optical character recognition (OCR) technology, its application in digital image processing and text information extraction is becoming more and more extensive. OCR technology plays an important role in text recognition of digital instruments, especially in the fields of industrial automation and power system monitoring, which require real-time and accurate reading of instrument data. However, in practical applications, due to problems such as stroke afterimages generated during instrument character switching and abnormal ambient light, OCR recognition often fails, affecting the accuracy and real-time performance of data.
[0003] In the existing technology, images generated based on generative models are limited by training data, have poor diversity, and are difficult to cover all practical application scenarios. The generation effect of the model is difficult to accurately control, and the generated images often have large differences from the real scenes, affecting the generalization ability of the recognition model.
[0004] In addition, the existing text image generation scheme can only generate text with completely correct strokes, and cannot simulate the stroke afterimage phenomenon caused by the switching process of instrument characters, resulting in the poor effect of the trained model in practical applications.
[0005] Therefore, there is an urgent need for a character afterimage simulation method that can accurately simulate the afterimage of digital pen strokes between instrument character switching and generate text image data containing the afterimage. Summary of the invention
[0006] The embodiments of the present invention provide a method for simulating character afterimages to solve the problem that the prior art cannot recognize the stroke afterimages generated during instrument character switching, resulting in OCR recognition failure and affecting the accuracy and real-time performance of data. The technical solution is as follows:
[0007] According to one aspect of the present invention, a method for simulating character afterimages comprises: obtaining a real image of an instrument, obtaining a background image, font information of text and text characteristics of the instrument according to the real image and constructing a corpus; determining a corpus and a background image according to the corpus, determining a drawing position and a color depth of the corpus according to a width and a height of the background image and drawing the corpus on the background image; calculating an afterimage position and a color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and the color depth; calculating a position and a color depth of a stroke afterimage of the corpus, and drawing the stroke afterimage of the corpus on the background image according to the position and the color depth of the stroke afterimage, to obtain an afterimage simulation image.
[0008] In one of the embodiments, obtaining a background image, font information of text and text characteristics of the instrument based on the real image and constructing a corpus is achieved by the following steps: acquiring a blank background image of the real image to obtain a background image, obtaining text content of the instrument in different modes, performing statistical analysis on the text content to obtain a character set and character frequency; analyzing the text characteristics of the instrument in different modes based on the character set and character frequency, performing font recognition on the text content to obtain font information; and constructing a corpus that conforms to each mode of the instrument based on the background image, text characteristics and font information of the text content.
[0009] In one of the embodiments, determining the drawing position and color depth of the corpus according to the width and height of the background image and drawing the corpus on the background image is achieved by the following steps: obtaining the width and height of the background image, randomly adding characters to the corpus to obtain corpus text, and obtaining the font size of the corpus text according to the width and height of the background image; determining the starting position and character spacing according to the width of the background image, and calculating the drawing position of the corpus text using an image processing algorithm; and drawing the corpus text on the background image according to the font size, starting position, character spacing and drawing position.
[0010] In one of the embodiments, obtaining the font size of the corpus text according to the width and height of the background image is achieved by the following steps: obtaining the font size of the corpus text by ensuring that the ratio of the width and height of the corpus text to the background image is between 2 / 3 and 3 / 4.
[0011] In one of the embodiments, calculating the afterimage position and color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and color depth is achieved by the following steps: defining a brightness formula and a contrast formula; the brightness formula is used to convert RGB values into brightness values; the contrast formula is used to distinguish the corpus from the background afterimage; intercepting the drawing area of the character according to the drawing position and character width of the character in the corpus text, and obtaining the background brightness of the character according to the drawing area and the brightness formula; setting a contrast value for the character, combining the contrast value, the background brightness and the brightness of the character to calculate the color depth of the character, and drawing the background afterimage of the character on the background image according to the color depth.
[0012] In one of the embodiments, the position and color depth of the stroke afterimage of the corpus are calculated, and the stroke afterimage of the corpus is drawn on the background image according to the position and color depth of the stroke afterimage, so as to obtain the afterimage simulation image by the following steps: selecting a digital character in the corpus text and obtaining the drawing position of the digital character, defining a contrast interval of the stroke afterimage, and obtaining the contrast value of the digital character according to the contrast interval; calculating the color depth of the digital character according to the contrast value and the background brightness of the digital character, and determining the drawing position of the stroke afterimage according to the position of the digital character; and drawing the stroke afterimage of the digital character on the background image according to the color depth at the drawing position of the stroke afterimage to obtain the afterimage simulation image.
[0013] In one embodiment, the brightness formula is: Y=0.299R+0.587G+0.114B;
[0014] The contrast formula is:
[0015] Among them, Y represents the brightness value, Y c Indicates the brightness of the character, Y bg Represents the background brightness, L c The contrast threshold was set to 0.2.
[0016] According to one aspect of the present invention, a device for simulating character afterimages comprises: a corpus construction module, used to obtain a real image of an instrument, obtain a background image, font information of text and text characteristics of the instrument according to the real image and construct a corpus; a corpus drawing module, used to determine a corpus and a background image according to the corpus, determine a drawing position and color depth of the corpus according to the width and height of the background image and draw the corpus on the background image; a background afterimage drawing module, used to calculate an afterimage position and color depth of the corpus in the background image, and draw the background afterimage of the corpus on the background image according to the afterimage position and color depth; a stroke afterimage drawing module, used to calculate the position and color depth of the stroke afterimages of the corpus, and draw the stroke afterimages of the corpus on the background image according to the position and color depth of the stroke afterimages to obtain an afterimage simulation image.
[0017] According to one aspect of the present invention, an electronic device includes at least one processor and at least one memory, wherein the memory stores computer-readable instructions; the computer-readable instructions are executed by one or more of the processors, so that the electronic device implements the character afterimage simulation method as described above.
[0018] According to one aspect of the present invention, a storage medium stores computer-readable instructions thereon, and the computer-readable instructions are executed by one or more processors to implement the character afterimage simulation method as described above.
[0019] The beneficial effects brought by the technical solution provided by the present invention are:
[0020] In the above technical scheme, the present invention first obtains a real image of the instrument, obtains the background image, font information of the text and the text characteristics of the instrument according to the real image and constructs a corpus, determines the corpus and the background image according to the corpus, determines the drawing position and color depth of the corpus according to the width and height of the background image and draws the corpus on the background image, calculates the afterimage position and color depth of the corpus in the background image, draws the background afterimage of the corpus on the background image according to the afterimage position and color depth, calculates the position and color depth of the stroke afterimage of the corpus, draws the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage, obtains the afterimage Simulated images, by accurately analyzing the real images of instruments and building a corpus containing font information and text characteristics, achieve accurate simulation of the instrument display effect. By dynamically adjusting the corpus drawing position and color depth, and carefully simulating the afterimage effect, including background afterimage and stroke afterimage, the realism and dynamics of the image are significantly enhanced. It not only improves the visual presentation quality, but also makes the simulated image closer to the actual scene, providing strong support for the evaluation and optimization of the instrument display effect, thereby effectively solving the problem that the existing technology cannot recognize the stroke afterimage generated during the switching of instrument characters, resulting in OCR recognition failure, affecting the accuracy and real-time performance of the data. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in describing the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without creative work.
[0022] Figure 1 is a flow chart of a character afterimage simulation method according to an exemplary embodiment;
[0023] Figure 2 It is a flowchart of a method for simulating character afterimage in an application scenario;
[0024] Figure 3 yes Figure 2 Schematic diagram of the process of drawing characters in the corresponding application scenario;
[0025] Figure 4 yes Figure 2A schematic diagram of the process of drawing background afterimages of characters in the corresponding application scenario;
[0026] Figure 5 yes Figure 2 A schematic diagram of the process of drawing the residual strokes of characters in the corresponding application scenario;
[0027] Figure 6 yes Figure 2 Schematic diagram of the result of the character afterimage simulation method in the corresponding application scenario;
[0028] Figure 7 is a block diagram of a device for simulating character afterimage according to an exemplary embodiment;
[0029] Figure 8 is a hardware structure diagram of an electronic device according to an exemplary embodiment;
[0030] Fig. 9 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0031] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be interpreted as limiting the present invention.
[0032] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present disclosure refers to the presence of the features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0033] The present invention provides a method for simulating character afterimages, which can significantly enhance the realism and dynamic sense of an image by dynamically adjusting the drawing position and color depth of a corpus, and carefully simulating afterimage effects, including background afterimages and stroke afterimages, and solve the problem that the prior art cannot recognize the stroke afterimages generated during the switching of instrument characters, resulting in OCR recognition failure and affecting the accuracy and real-time performance of data. The method for simulating character afterimages is suitable for a character afterimage simulation device, which can be an electronic device. The method for simulating character afterimages in the embodiments of the present invention can be applied to a variety of scenarios, such as character afterimage simulation, etc.
[0034] See also Figure 1 An embodiment of the present invention provides a method for simulating character afterimage, which is applicable to electronic devices.
[0035] In the following method embodiments, for ease of description, the execution subject of each step of the method is taken as an electronic device as an example for illustration, but this does not constitute a specific limitation.
[0036] like Figure 1 As shown, the method may include the following steps:
[0037] Step 110, obtaining a real image of the instrument, obtaining a background image, font information of the text and text characteristics of the instrument according to the real image and constructing a corpus.
[0038] In one possible implementation, a blank background image is collected from a real image to obtain a background image, and the text content of the instrument in different modes is obtained. The text content is statistically analyzed to obtain the character set and character frequency. The text characteristics of the instrument in different modes are analyzed based on the character set and character frequency. The text content is font recognized to obtain font information. A corpus that conforms to each mode of the instrument is constructed based on the background image, text characteristics, and font information of the text content.
[0039] Step 130, determining the corpus and the background image according to the corpus, determining the drawing position and color depth of the corpus according to the width and height of the background image, and drawing the corpus on the background image.
[0040] In one possible implementation, the width and height of the background image are obtained, characters are randomly added to the corpus to obtain the corpus text, the font size of the corpus text is obtained according to the width and height of the background image, the starting position and character spacing are determined according to the width of the background image, the drawing position of the corpus text is calculated using an image processing algorithm, and the corpus text is drawn on the background image according to the font size, starting position, character spacing and drawing position.
[0041] In a possible implementation, the font size of the corpus text is obtained by ensuring that the ratio of the width and height of the corpus text to the background image is between 2 / 3 and 3 / 4.
[0042] Step 150, calculating the afterimage position and color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and color depth.
[0043] In one possible implementation, a brightness formula and a contrast formula are defined, the drawing area of the character is intercepted according to the drawing position and character width of the character in the corpus text, the background brightness of the character is obtained according to the drawing area and the brightness formula, a contrast value is set for the character, the color depth of the character is calculated by combining the contrast value, the background brightness and the brightness of the character, and the background afterimage of the character is drawn on the background image according to the color depth.
[0044] The brightness formula is used to convert RGB values into brightness values, and the contrast formula is used to distinguish the corpus from the background afterimage.
[0045] Step 170, calculating the position and color depth of the stroke afterimages of the corpus, and drawing the stroke afterimages of the corpus on the background image according to the position and color depth of the stroke afterimages to obtain a simulated afterimage image.
[0046] In one possible implementation, a digital character is selected in a corpus text and the drawing position of the digital character is obtained, a contrast interval of the stroke afterimage is defined, a contrast value of the digital character is obtained according to the contrast interval, the color depth of the digital character is calculated according to the contrast value and the background brightness of the digital character, the drawing position of the stroke afterimage is determined according to the position of the digital character, and the stroke afterimage of the digital character is drawn on the background image at the drawing position of the stroke afterimage according to the color depth to obtain an afterimage simulation image.
[0047] In one possible implementation, the brightness formula is: Y=0.299R+0.587G+0.114B;
[0048] The contrast ratio formula is:
[0049] Among them, Y represents the brightness value, Y c Indicates the brightness of the character, Y bg Represents the background brightness, L c The contrast threshold was set to 0.2.
[0050] Through the above process, the present invention first obtains a real image of the instrument, obtains the background image, font information of the text and the text characteristics of the instrument according to the real image and constructs a corpus, determines the corpus and the background image according to the corpus, determines the drawing position and color depth of the corpus according to the width and height of the background image and draws the corpus on the background image, calculates the afterimage position and color depth of the corpus in the background image, draws the background afterimage of the corpus on the background image according to the afterimage position and color depth, calculates the position and color depth of the stroke afterimage of the corpus, draws the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage, and obtains the afterimage. Simulated images, by accurately analyzing the real images of instruments and building a corpus containing font information and text characteristics, achieve accurate simulation of the instrument display effect. By dynamically adjusting the corpus drawing position and color depth, and carefully simulating the afterimage effect, including background afterimage and stroke afterimage, the realism and dynamics of the image are significantly enhanced. It not only improves the visual presentation quality, but also makes the simulated image closer to the actual scene, providing strong support for the evaluation and optimization of the instrument display effect, thereby effectively solving the problem that the existing technology cannot recognize the stroke afterimage generated during the switching of instrument characters, resulting in OCR recognition failure, affecting the accuracy and real-time performance of the data.
[0051] In one application scenario, Figure 2 A flowchart of a character afterimage simulation method is shown.
[0052] like Figure 2As shown in the figure, the whole process from image acquisition to the final generation of an image with afterimage effect is described. First, complete cycle images of the device under different working conditions are obtained, and the regularity and character set of the text in the acquired image are analyzed to better understand the structure and characteristics of the text. The text in the image is identified by font recognition technology, and its font type is determined. Specifically, the font corresponding to the instrument display text is identified through third-party online websites such as whatfont is. In order to draw the text on a clean and interference-free background in the future, a blank background image is collected. Based on the text regularity, character set and font recognition results, the text characteristics of each mode in the instrument display cycle are sorted out, and a corpus containing these characteristics is generated, which includes not only random generation of text, but also generation of text according to specific text characteristics. A corpus is randomly selected from the corpus or according to specific needs as the basis for subsequent processing. According to the identified font or design requirements, a suitable font is selected for text drawing. One is selected from a blank background image or other background resources as the background for text drawing. The selected original corpus and background are combined to prepare for text drawing, and detailed parameter configuration is performed on the characters, including size, positioning and color. Specifically, the character positioning module is used to determine the font size according to the font, and the drawing position and color depth of each character in the corpus in the image are calculated one by one. In order to simulate the text display effect in the real scene, the background afterimage of the text is drawn, which is completed by calculating the position and color depth of the afterimage. After configuring the parameters and background, the original corpus is drawn onto the background image to further simulate the writing effect of the text and draw the afterimage of the strokes. It is also necessary to calculate the position and color depth of the afterimage until the specified number of text images are generated.
[0053] Specifically, a third-party online service such as Whatfont is or local font recognition software is used to upload instrument images in real scenes to identify the fonts used for instrument display texts. According to the display cycle of the instrument (such as the change cycle of time, temperature, speed, etc.), the characteristics of the text in different display modes (such as format, length, content change rules) are sorted out and understood. Based on these characteristics, a series of texts are randomly generated or generated according to specific rules to build a corpus. These texts will be used in the subsequent image generation process. A text and a background image (usually the background of the instrument panel) in the corpus are randomly selected. According to the recognized font and text content, the drawing position (including size, position coordinates) and color depth (considering factors such as lighting effects) of each character in the image are determined to simulate the visual traces (afterimages) left by the text on the background. The position of the afterimage (offset relative to the original text position), shape (may be blurred due to time decay) and color depth (lighter or different tones than the original text) are calculated to complete the drawing of the afterimage characters on the image, increase the dynamic and historical sense of the image, and for numbers or specific characters, further refine to the stroke level, calculate and draw the afterimage effect of the stroke. This can simulate the dynamic visual effect left by the stroke when it changes or moves quickly. Repeat the above steps, each time you may select different text and / or adjust the drawing parameters (such as position, color, afterimage effect strength, etc.) to generate a specified number of text images, which can be used to train machine learning models, simulate dynamic instrument displays, or as visual effects, etc.
[0054] like Figure 3 As shown, the process of drawing characters in the corpus on the background image is described. First, the original corpus is expanded or converted in some form to generate the expanded corpus. Specifically, a background image is prepared or selected for the subsequent display of text information, a font is specified for drawing or displaying text information on the background image, and the text meets the specific visual effect or format requirements. The width and height of the background image are recorded or determined. According to the image width and height and the preset display effect requirements, the appropriate size of the text (corpus) is calculated to ensure that the text can be displayed on the background image as expected. The text size calculated in the previous step is displayed or recorded, and the proportional relationship between the text size and the image size is further determined to ensure the harmony between the text and the background. The specific proportional requirements between the text size and the image size are emphasized, which is an important basis for locating the text position. Specifically, according to the ratio of the text size or position to the image size, it is determined whether the text is located in the predetermined display interval (between 2 / 3 and 3 / 4 of the background image width). After all conditions are met, the position of the text characters on the background image is finally determined.
[0055] Specifically, firstly, according to the training requirements, appropriate fonts, corpus (i.e., the text content to be displayed) and background images are selected, the width (i mg_w) and height (i mg_h) of the background image are obtained, several characters are randomly selected from the predefined character set, and these characters are inserted into the selected corpus to form a new corpus text (called corpus text 2). This step is to increase the diversity of the text and the richness of the training set. By gradually increasing the font size and calculating the text width (text_w) and height (text_h) of corpus text 2 at each size, a suitable font size (font_s) is found. The selection standard is that the ratio of the text size to the background image size is between 2 / 3 and 3 / 4, which ensures that the text is neither too small to be difficult to recognize nor too large to exceed the image boundary.
[0056] Furthermore, within the width of the background image (i.e., [0, i mg_w-text_w]), a position is randomly selected as the starting position (c_offset_0) of the first character of corpus text 2, and the interval (m) between characters is set. This interval can be adjusted as needed to improve the visual effect of the text or simulate the text layout in a real scene. For each character c_i in corpus text 2, the Pillow library (an image processing library in Python) is used to calculate the width (c_w_i) of the character at the current font size, and the drawing position (c_offset_i) of the current character is calculated according to the end position of the previous character (i.e., c_offset_{i-1}+c_w_{i-1}+m), and the current character is drawn at the specified position (c_offset_i) of the background image. The above process is repeated until all characters in corpus text 2 are calculated and drawn.
[0057] Through the above process, by dynamically adjusting the font size and text position, it is ensured that the generated text image not only meets the requirements of the training model, but also simulates the text display effect in the real scene. The generated image can be used to train the text recognition model to improve the model's recognition ability for texts of different fonts, sizes and positions.
[0058] like Figure 4As shown, the process of drawing the background afterimage of the characters in the corpus on the background image is described. First, the character information in the original corpus is extracted and converted into the meter font to simulate the text effect on the meter display screen. The original corpus is enhanced using the extended corpus 2, that is, the text content is expanded, formatted or optimized to improve the clarity and readability of the text. The position, size, brightness and other parameters of the characters are finely adjusted to ensure that the characters can be presented in the best way on the background image, which is both clear and beautiful. While adjusting the character parameters, the background image is prepared. This image will serve as the base for drawing the characters. The selection of the background image is based on specific application scenarios or visual effect requirements. The optimized characters are drawn on the background image to form a background afterimage, which perfectly integrates the characters with the background image to create the desired visual effect.
[0059] Specifically, first, define a formula for converting RGB color values (the values of the three components of red, green, and blue) into a brightness value Y. The brightness value is a single numerical value used to indicate the lightness or darkness of a color. Common RGB to brightness conversion formulas include the weighted sum formula, such as Y=0.299R+0.587G+0.114B. Next, define a contrast formula for calculating the contrast between characters and backgrounds. Contrast is a function of the difference (or ratio) between character brightness and background brightness, and is used to measure the visibility of characters against the background. When the contrast is closer to 1 or -1, the greater the difference between the text and the background, and the more obvious the text; conversely, when the contrast is close to 0, the text is close to the background and difficult to distinguish.
[0060] Specifically, the contrast formula is:
[0061] Among them, Y represents the brightness value, Y c Indicates the brightness of the character, Y bg Represents the background brightness, L c The contrast threshold is (0.2) which is set through a large number of statistics to distinguish the original corpus from the background afterimage. The contrast below 0.2 is considered to be the background afterimage.
[0062] Furthermore, a character c_i is selected from the corpus text 2, and its drawing position c_offset_i is obtained. This position is the starting coordinate of the character on the background image. According to the drawing position of the character and the possible character width (or the position of the next character), the drawing area c_area_i of the character c_i is intercepted. This area is used for the subsequent calculation of the background brightness. The brightness formula is used to convert the average RGB value c_rgb_i of the intercepted area c_area_i into a brightness value c_L_bg_i. This brightness value represents the average brightness of the background where the character is located. Depending on whether the character c_i is the original corpus or the background afterimage, the range of its contrast is determined. If it is the original corpus, the contrast should be between (0.2,1]; if it is the background afterimage, the contrast should be between (0,0.2].
[0063] Further, a contrast value is randomly selected within the determined contrast range, and then the color depth c_L_c_i of the character c_i is calculated by combining the background brightness c_L_bg_i and the original brightness of the character (which may need to be preset or calculated based on the font style). This color depth will be used to draw the character, and the character c_i is drawn using the calculated color depth c_L_c_i at the c_offset_i position of the background image. This includes converting the RGB value of the character to a value appropriate for the background contrast. Repeat the above steps until all characters in corpus text 2 (including the original corpus and the background afterimage) are calculated and drawn.
[0064] Through the above process, the clarity and readability of the text on the background image are ensured, while the effect of background afterimage is simulated, which increases the complexity and authenticity of the image and helps to train a more robust text recognition model.
[0065] like Figure 5As shown, the process of drawing the character afterimages of the characters in the corpus on the background image is described. First, the original data or text set is obtained, which contains the text information that needs to be processed by the stroke afterimage. The original text data selected from the stroke afterimage corpus is expanded or converted based on the original corpus to generate an extended corpus for further processing, including text format adjustment, content enhancement, etc., and a specific font (such as an electric meter font) is selected or defined for the subsequent text drawing to ensure the visual consistency and specific style of the text. The background afterimage corpus is obtained according to the extended corpus, which contains text or image information related to the background image, which is used to create or simulate the background afterimage effect. A blank background image is prepared or selected for the subsequent text and afterimage drawing. The drawing position and size of each character in the text are set, which also includes the adjustment of the character brightness to ensure the visibility and readability of the character on the background image. Specifically, all characters c_i are obtained from "corpus text 2". Drawing position c_offset_i, in particular, screening is performed for digital characters, because the requirement is to design the afterimage of numbers. For a selected digital character c_i without background afterimage, first obtain its drawing position c_offset_i, obtain the character brightness, background brightness and contrast of the character, define the contrast range of the stroke afterimage character, and randomly select a contrast value from the range as the contrast of the afterimage character. According to the selected contrast value, calculate the color depth of the afterimage character, randomly generate a number c'_i (which may be the same number as c_i or a different number, depending on the needs of the afterimage design) as the afterimage content, and draw the afterimage character c'_i at the character drawing position c_offset_i with the calculated color depth. Repeat the above process until the design and drawing of all digital characters that need to add afterimages are completed.
[0066] Specifically, first select a non-background residual digital character c_i from corpus text 2, and obtain its drawing position c_offset_i, obtain the character brightness, background brightness and contrast of the character, and this information will be used to calculate the contrast of the residual image in the future, and define a contrast interval suitable for stroke residual images (such as [0,0.2], indicating that the contrast of the residual image is low). Randomly select a contrast value of a residual image character from this interval. Using the selected residual image contrast and background brightness (or character brightness, depending on the required residual image effect), calculate the color depth of the residual image character, such as reducing the brightness or saturation of the character to simulate the visual effect of the residual image.
[0067] The position of the afterimage usually does not completely overlap with the original character, but will have a certain offset or blur effect. Therefore, the specific position of the afterimage needs to be determined according to the effect design of the afterimage. Based on the original character position, it is slightly offset in a certain direction (such as horizontally or vertically), or a blur effect is applied to simulate the afterimage.
[0068] Specifically, at the determined afterimage position, the afterimage character is drawn using the calculated color depth, using the same number as the original character, but applying a different color depth and possible blur effect. The above steps are repeated until all the digital characters in corpus text 2 have completed the design and drawing of afterimages.
[0069] Among them, it is necessary to use the blurring, transparency adjustment and other functions in the image processing library (such as Pillow) to achieve a more realistic afterimage effect. In addition, the specific design of the afterimage (such as position, size, shape, color, etc.) can be adjusted according to specific needs and training objectives.
[0070] like Figure 6 As shown, the finally generated instrument image is displayed, wherein the red box is the simulated stroke afterimage, and the yellow box is the simulated background afterimage. It can be seen that the embodiment of the present invention can simulate the background character afterimage and character stroke afterimage in the instrument text image with high quality, and can well meet the needs of instrument text recognition such as the need for customized recognition models for specific fonts or even specific scenarios. Compared with the general text image generation solution, it can better simulate the afterimage phenomenon that is widely present in the actual instrument text recognition scenario, and train a model with higher robustness and stronger generalization.
[0071] Through the above process, the embodiment of the present invention greatly enhances the realism and dynamic sense of the generated image by accurately simulating the text display effect in the real scene, including font, size, position and afterimage effect, which helps to improve the user experience, and the generated image with afterimage effect can be used to train machine learning models, especially text recognition models, by increasing the complexity and diversity of the training set, significantly improving the recognition ability and robustness of the model for complex text environments. In addition, it also has a high degree of flexibility and scalability, and can adjust the parameters and effects of characters and afterimages according to different application scenarios and needs to meet diverse visual design needs. Finally, through the automated and batched image generation process, the work efficiency is greatly improved, the labor cost is reduced, and strong support is provided for the creation and application of large-scale visual content. The embodiment of the present invention shows significant advantages in enhancing the model training effect, meeting diverse design needs, and improving work efficiency.
[0072] The following is an embodiment of the device of the present invention, which can be used to execute the character afterimage simulation method involved in the present invention. For details not disclosed in the embodiment of the device of the present invention, please refer to the method embodiment of the character afterimage simulation method involved in the present invention.
[0073] See also Figure 7 , an embodiment of the present invention provides a character afterimage simulation device 800.
[0074] The character afterimage simulation device 800 includes but is not limited to: a corpus construction module 810 , a corpus drawing module 830 , a background afterimage drawing module 850 and a stroke afterimage drawing module 870 .
[0075] The corpus construction module 810 is used to obtain a real image of the instrument, obtain the background image, the font information of the text and the text characteristics of the instrument according to the real image, and construct a corpus.
[0076] The corpus drawing module 830 is used to determine the corpus and the background image according to the corpus, determine the drawing position and color depth of the corpus according to the width and height of the background image, and draw the corpus on the background image.
[0077] The background afterimage drawing module 850 is used to calculate the afterimage position and color depth of the corpus in the background image, and draw the background afterimage of the corpus on the background image according to the afterimage position and color depth.
[0078] The stroke afterimage drawing module 870 is used to calculate the position and color depth of the stroke afterimage of the corpus, and draw the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage to obtain a simulated afterimage image.
[0079] It should be noted that the character afterimage simulation provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the character afterimage simulation device will be divided into different functional modules to complete all or part of the functions described above.
[0080] In addition, the character afterimage simulation device and the character afterimage simulation method provided in the above embodiments belong to the same concept, and the specific manner in which each module performs the operation has been described in detail in the method embodiment and will not be repeated here.
[0081] Figure 8 The present invention schematically illustrates the structure of an electronic device according to an exemplary embodiment.
[0082] It should be noted that the electronic device is only an example adapted to the present invention and cannot be considered to provide any limitation on the scope of use of the present invention. The electronic device cannot be interpreted as requiring dependence on or having Figure 8 One or more components of exemplary electronic device 2000 are shown.
[0083] The hardware structure of the electronic device 2000 may vary greatly due to differences in configuration or performance, such as Figure 8As shown, the electronic device 2000 includes: a power supply 210, an interface 230, at least one memory 250, and at least one central processing unit (CPU) 270.
[0084] Specifically, the power supply 210 is used to provide operating voltage for each hardware device on the electronic device 2000 .
[0085] The interface 230 includes at least one wired or wireless network interface 231 for interacting with external devices. Of course, in other examples adapted by the present invention, the interface 230 may further include at least one serial-to-parallel conversion interface 233, at least one input-output interface 235, and at least one USB interface 237, etc. Figure 8 As shown, this is not intended to be a specific limitation.
[0086] The memory 250 is a carrier for storing resources, which may be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 251, an application 253 and data 255, etc. The storage method may be temporary storage or permanent storage.
[0087] Among them, the operating system 251 is used to manage and control various hardware devices and application programs 253 on the electronic device 2000 to enable the central processing unit 270 to calculate and process the massive data 255 in the memory 250. It can be Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0088] The application program 253 is a computer-readable instruction that performs at least one specific task based on the operating system 251, and may include at least one module ( Figure 8 (not shown), each module may respectively include computer-readable instructions for the electronic device 2000. For example, the character afterimage simulation device may be regarded as an application 253 deployed in the electronic device 2000.
[0089] The data 255 may be signal information, etc., stored in the memory 250 .
[0090] The central processor 270 may include one or more processors, and is configured to communicate with the memory 250 through at least one communication bus to read the computer-readable instructions stored in the memory 250, thereby realizing the operation and processing of the mass data 255 in the memory 250. For example, the character afterimage simulation method is completed by the central processor 270 reading a series of computer-readable instructions stored in the memory 250.
[0091] In addition, the present invention can also be implemented by hardware circuits or hardware circuits combined with software. Therefore, the implementation of the present invention is not limited to any specific hardware circuits, software, or a combination of the two.
[0092] See also Fig. 9 In an embodiment of the present invention, an electronic device 4000 is provided. The electronic device 4000 may include: a desktop computer, a laptop computer, a server, etc. with sensor recognition capability.
[0093] exist Fig. 9 In the embodiment, the electronic device 4000 includes at least one processor 4001 and at least one memory 4003.
[0094] The data interaction between the processor 4001 and the memory 4003 can be realized through at least one communication bus 4002. The communication bus 4002 may include a path for transmitting data between the processor 4001 and the memory 4003. The communication bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus 4002 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0095] Optionally, the electronic device 4000 may further include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception, etc. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present invention.
[0096] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of the present invention. Processor 4001 may also be a combination that implements a computing function, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0097] The memory 4003 can be a ROM (Read On Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrical Erasable Programmable Read On Memory), a CD-ROM (Compact Disk Read On Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program instructions or codes in the form of instructions or data structures and can be accessed by the electronic device 4000, but is not limited to this.
[0098] Computer-readable instructions are stored in the memory 4003 , and the processor 4001 can read the computer-readable instructions stored in the memory 4003 through the communication bus 4002 .
[0099] The computer-readable instructions are executed by one or more processors 4001 to implement the character afterimage simulation method in the above-mentioned embodiments.
[0100] In addition, an embodiment of the present invention provides a storage medium on which computer-readable instructions are stored. The computer-readable instructions are executed by one or more processors to implement the character afterimage simulation method as described above.
[0101] A computer program product is provided in an embodiment of the present invention. The computer program product includes computer-readable instructions. The computer-readable instructions are stored in a storage medium. One or more processors of an electronic device read the computer-readable instructions from the storage medium, load and execute the computer-readable instructions, so that the electronic device implements the character afterimage simulation method as described above.
[0102] Compared with the related art, the present invention has the following beneficial effects:
[0103] 1. The present invention first obtains a real image of the instrument, obtains the background image, the font information of the text and the text characteristics of the instrument according to the real image and constructs a corpus, determines the corpus and the background image according to the corpus, determines the drawing position and color depth of the corpus according to the width and height of the background image and draws the corpus on the background image, calculates the afterimage position and color depth of the corpus in the background image, draws the background afterimage of the corpus on the background image according to the afterimage position and color depth, calculates the position and color depth of the stroke afterimage of the corpus, draws the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage, and obtains the afterimage simulation image For example, by accurately analyzing the real images of instruments and building a corpus containing font information and text characteristics, we can achieve accurate simulation of the instrument display effect. By dynamically adjusting the corpus drawing position and color depth, and carefully simulating the afterimage effect, including background afterimage and stroke afterimage, the realism and dynamics of the image are significantly enhanced. It not only improves the visual presentation quality, but also makes the simulated image closer to the actual scene, providing strong support for the evaluation and optimization of instrument display effects, thereby effectively solving the problem that the existing technology cannot recognize the stroke afterimages generated during the switching of instrument characters, resulting in OCR recognition failure, affecting the accuracy and real-time performance of the data.
[0104] 2. The present invention can simulate the actual scene more realistically: by designing the background afterimage module and the stroke afterimage module, the afterimage phenomenon widely existing in the actual instrument text recognition scene can be simulated in the generated text image. This simulation makes the generated image closer to the real scene and improves the robustness and generalization ability of the model.
[0105] 3. The present invention can improve the model training effect: using the text image containing the afterimage phenomenon for model training can enable the model to learn the interference when the numbers have switching afterimages during the instrument content switching process, thereby improving the recognition accuracy of the model in practical applications.
[0106] 4. The present invention can adapt to complex and changeable meter environments: The characteristics of meter text recognition are that the text fonts are standardized but changeable, and the environment in which the meter is located is complex. This solution can better adapt to these complex and changeable scenarios by training the corresponding meter model through synthetic data, and improve the practicality and reliability of the model.
[0107] 5. The present invention can reduce the cost of data annotation and review: Since manual annotation and review of text data are extremely time-consuming and labor-intensive, and model training requires a large amount of diverse data, this solution can reduce the cost of data annotation and review to a certain extent by simulating the generation of a large amount of text data containing afterimage phenomena.
[0108] 6. The present invention can enhance the generalization ability of the model: by simulating environmental factors such as different lighting and tilt, as well as text data under different language systems and fonts, the scheme can further improve the generalization ability of the OCR model, enabling it to better adapt to text recognition tasks in various complex scenarios.
[0109] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0110] The above descriptions are only some embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A character afterimage simulation method, characterized in that: The method comprises: Acquire a real image of the instrument, obtain a background image, font information of the text and text characteristics of the instrument according to the real image and construct a corpus; Determine the corpus and the background image according to the corpus, determine the drawing position and color depth of the corpus according to the width and height of the background image, and draw the corpus on the background image; Calculating the afterimage position and color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and color depth; The position and color depth of the stroke afterimage of the corpus are calculated, and the stroke afterimage of the corpus is drawn on the background image according to the position and color depth of the stroke afterimage to obtain a simulated afterimage image.
2. The character afterimage simulation method according to claim 1, characterized in that: The step of obtaining a background image, font information of text and text characteristics of the instrument according to the real image and constructing a corpus includes: Capturing a blank background image of the real image to obtain a background image, obtaining text content of the instrument in different modes, and performing statistical analysis on the text content to obtain a character set and character frequency; Analyze the text characteristics of the instrument in different modes according to the character set and character frequency, and perform font recognition on the text content to obtain font information; A corpus conforming to each mode of the instrument is constructed according to the background image, text characteristics and font information of the text content.
3. The character afterimage simulation method according to claim 1, characterized in that: The step of determining the drawing position and color depth of the corpus according to the width and height of the background image and drawing the corpus on the background image comprises: Obtaining the width and height of the background image, randomly adding characters to the corpus to obtain a corpus text, and obtaining the font size of the corpus text according to the width and height of the background image; Determine the starting position and character spacing according to the width of the background image, and calculate the drawing position of the corpus text using an image processing algorithm; The corpus text is drawn on the background image according to the font size, the starting position, the character spacing and the drawing position.
4. The character afterimage simulation method according to claim 3, characterized in that: The obtaining of the font size of the corpus text according to the width and height of the background image includes: The font size of the corpus text is obtained by ensuring that the ratio of the width and height of the corpus text to the background image is between 2 / 3 and 3 / 4.
5. The character afterimage simulation method according to claim 3, characterized in that: The calculating the afterimage position and color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and color depth, comprises: Define a brightness formula and a contrast formula; the brightness formula is used to convert the RGB value into a brightness value; the contrast formula is used to distinguish the corpus from the background afterimage; intercepting a drawing area of the character according to a drawing position and a character width of the character in the corpus text, and obtaining a background brightness of the character according to the drawing area and the brightness formula; A contrast value is set for the character, a color depth of the character is calculated by combining the contrast value, background brightness and the brightness of the character, and a background afterimage of the character is drawn on the background image according to the color depth.
6. The character afterimage simulation method according to claim 5, characterized in that: The calculating the position and color depth of the stroke afterimage of the corpus, and drawing the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage to obtain a simulated afterimage image, comprises: Selecting a numeric character in the corpus text and obtaining a drawing position of the numeric character, defining a contrast interval of a stroke afterimage, and obtaining a contrast value of the numeric character according to the contrast interval; Calculate the color depth of the digital character according to the contrast value and the background brightness of the digital character, and determine the drawing position of the stroke afterimage according to the position of the digital character; The stroke afterimage of the digital character is drawn on the background image at the drawing position of the stroke afterimage according to the color depth to obtain an afterimage simulation image.
7. The character afterimage simulation method according to claim 5, characterized in that: The brightness formula is: Y = 0.299R + 0.587G + 0.114B; The contrast formula is: Among them, Y represents the brightness value, Y c Indicates the brightness of the character, Y bg Represents the background brightness, L c The contrast threshold was set to 0.
2.
8. A character afterimage simulation device, characterized in that: The device comprises: A corpus construction module is used to obtain a real image of the instrument, obtain a background image, font information of the text and text characteristics of the instrument according to the real image, and construct a corpus; A corpus drawing module, used for determining corpus and a background image according to the corpus, determining a drawing position and a color depth of the corpus according to a width and a height of the background image, and drawing the corpus on the background image; A background afterimage drawing module, used for calculating the afterimage position and color depth of the corpus in the background image, and drawing the background afterimage of the corpus on the background image according to the afterimage position and color depth; The stroke afterimage drawing module is used to calculate the position and color depth of the stroke afterimage of the corpus, and draw the stroke afterimage of the corpus on the background image according to the position and color depth of the stroke afterimage to obtain a simulated afterimage image.
9. An electronic device, characterized in that: include: at least one processor and at least one memory, wherein: The memory has computer-readable instructions stored thereon; The computer-readable instructions are executed by one or more of the processors, so that the electronic device implements the character afterimage simulation method according to any one of claims 1 to 7.
10. A storage medium having computer-readable instructions stored thereon, characterized in that: The computer-readable instructions are executed by one or more processors to implement the character afterimage simulation method according to any one of claims 1 to 7.