Method and device for detecting character position and width, electronic equipment and storage medium
By extracting signals from character images using wavelet transform technology and preprocessing with time-spectrum data, the problem of low accuracy in character position and width detection is solved, achieving high-precision character region and width measurement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MATRIXTIME ROBOTICS (SHANGHAI) CO LTD
- Filing Date
- 2022-12-19
- Publication Date
- 2026-07-07
AI Technical Summary
Existing technologies struggle to accurately detect both character position and width simultaneously in industrial inspection, exhibiting issues such as high computational complexity, low robustness, and limited accuracy.
Wavelet transform technology is used to extract character signals from the image of the character to be detected. By preprocessing the time-frequency data, the character region and width are determined. The accurate positioning and measurement of the character region and width are achieved by using time-domain energy signals and frequency cumulative energy signals.
It achieves high-precision detection of character position and width, has strong robustness and error correction capabilities, and is widely applicable to various data conditions.
Smart Images

Figure CN116343217B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically, to a method, apparatus, electronic device, and storage medium for detecting character position and width. Background Technology
[0002] The industrial manufacturing sector has developed rapidly in recent decades, and the demand and application of industrial image positioning and measurement have grown explosively. Different machine vision technologies are increasingly being used in all aspects of industrial production.
[0003] In the field of industrial machine vision, character identification images frequently appear in almost all industrial production scenarios, such as automotive parts, new products, and circuit boards. Locating the characters and measuring their width in such image data is a crucial step in subsequent work such as defect detection and product recognition. Traditional manual inspection methods suffer from high costs, low efficiency, and insufficient accuracy.
[0004] With the rapid development of image processing technology, a series of techniques and methods for character image localization and width measurement have emerged. In the past, such methods had problems such as large computational load, low robustness, and limited accuracy, making it difficult to solve the current problems of character localization and width detection. Summary of the Invention
[0005] One objective of this invention is to provide a method, apparatus, electronic device, and storage medium for detecting character position and width, thereby simultaneously solving the current problem of detecting character position and width with high accuracy. Embodiments of this invention can be implemented as follows:
[0006] In a first aspect, the present invention provides a method for detecting character position and width, the method comprising:
[0007] Extract the character signal corresponding to the character to be detected from the image of the character to be detected;
[0008] The character signal is subjected to wavelet transform to obtain the time-spectrum data corresponding to the character signal, and the time-spectrum data is preprocessed; the time-spectrum data is used to maintain the wavelet convolution result value of the character signal at different positions corresponding to each frequency;
[0009] Based on the preprocessed time-spectrum data, the time-domain energy signal of the character signal is determined in the time domain dimension, and the region corresponding to the time-domain energy value greater than a preset threshold is determined as the character region of the character to be detected from the time-domain energy signal.
[0010] Based on the preprocessed time-spectrum data, the frequency cumulative energy signal of the character signal is determined in the frequency domain dimension, and the character width of the character to be detected is determined based on the frequency corresponding to the maximum frequency cumulative energy value in the frequency cumulative energy signal and the width of the character image to be detected.
[0011] Secondly, the present invention provides an apparatus for detecting the position and width of characters, comprising:
[0012] The extraction module is used to: extract the character signal corresponding to the character to be detected from the character image to be detected;
[0013] The transformation module is used to: perform wavelet transform on the character signal to obtain the time-spectrum data corresponding to the character signal, and preprocess the time-spectrum data; the time-spectrum data is used to maintain the wavelet convolution result value of the character signal at different positions corresponding to each frequency;
[0014] The positioning module is used to: determine the time-domain energy signal of the character signal in the time-domain dimension based on the preprocessed time-spectrum data, and determine the region corresponding to the time-domain energy value greater than a preset threshold from the time-domain energy signal as the character region of the character to be detected;
[0015] The detection module is used to: determine the frequency cumulative energy signal of the character signal in the frequency domain dimension based on the preprocessed time-spectrum data, and determine the character width of the character to be detected based on the frequency corresponding to the maximum frequency cumulative energy value in the frequency cumulative energy signal and the width of the character image to be detected.
[0016] Thirdly, the present invention provides an electronic device including a processor and a memory, the memory storing a computer program executable by the processor, the processor being able to execute the computer program to implement the method described in the first aspect.
[0017] Fourthly, the present invention provides a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method described in the first aspect.
[0018] This invention provides a method, apparatus, electronic device, and storage medium for detecting character position and width. First, the character signal of the character to be detected is obtained from the image of the character to be detected. Then, wavelet transform is performed on the character signal to obtain time-spectrum data. Next, the corresponding time-domain energy signal of the character signal is determined from the time-domain dimension of the preprocessed time-spectrum data. The region corresponding to the time-domain energy value greater than a preset threshold in the time-domain energy signal is determined as the character region of the character to be detected, thereby accurately locating the character region. Then, the corresponding frequency cumulative energy signal of the character signal is obtained in the frequency domain dimension. Based on the frequency corresponding to the maximum frequency cumulative energy value and the width of the image of the character to be detected, the character width of the character to be detected can be detected. The method provided by this invention not only solves the problems of difficulty and low accuracy in industrial detection of character position and width, but also has fewer data restrictions, a wider range of applications, strong robustness and error correction capabilities, and can calculate the character region and width even for defective data. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A schematic flowchart illustrating the method for detecting character position and width provided in an embodiment of the present invention;
[0021] Figure 2 This is an example image of the character to be detected provided in an embodiment of the present invention;
[0022] Figure 3 A schematic flowchart of step S101 provided in an embodiment of the present invention;
[0023] Figure 4 This is an example image of a binarized image provided in an embodiment of the present invention;
[0024] Figure 5 This is an example diagram of the character signal of the character to be detected provided in an embodiment of the present invention;
[0025] Figure 6 The time-spectral diagram of the character to be detected provided in the embodiments of the present invention;
[0026] Figure 7 A schematic flowchart of step S103 provided in an embodiment of the present invention;
[0027] Figure 8An example diagram of the time-domain energy signal provided in an embodiment of the present invention;
[0028] Figure 9 The effective character region signal provided in the embodiments of the present invention;
[0029] Figure 10 A schematic flowchart of step S104 provided in an embodiment of the present invention;
[0030] Figure 11 An example diagram of the frequency accumulation energy signal provided in an embodiment of the present invention;
[0031] Figure 12 A schematic diagram illustrating the determination of frequency in an embodiment of the present invention;
[0032] Figure 13 A functional block diagram of the device for detecting character position and width provided in an embodiment of the present invention;
[0033] Figure 14 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0035] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0036] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0037] In the description of this invention, it should be noted that if terms such as "upper," "lower," "inner," or "outer" are used to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of this invention is usually placed, they are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention.
[0038] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0039] It should be noted that, where there is no conflict, the features in the embodiments of the present invention can be combined with each other.
[0040] The industrial manufacturing sector has developed rapidly in recent decades, and the demand and application of industrial image positioning and measurement have grown explosively. Different machine vision technologies are increasingly being used in all aspects of industrial production.
[0041] In the field of industrial machine vision, character identification images frequently appear in almost all industrial production scenarios, such as automotive parts, new products, and circuit boards. Locating the character identifications and measuring their width in such image data is one of the key steps in subsequent work such as defect detection and product recognition.
[0042] Traditional manual inspection methods suffer from high costs, low efficiency, and insufficient accuracy. With the rapid development of image processing technology, a series of techniques and methods for character image localization and width measurement have emerged. However, previous methods have not solved both problems simultaneously and suffer from high computational load, low robustness, and limited accuracy, making it difficult to solve current character localization and width detection problems.
[0043] To address the aforementioned issues, this invention provides a method for detecting the position and width of characters in industrial applications based on wavelet transform. For industrial image data with character identifiers, wavelet transform is used to determine the position and calculate the character width. This method does not require pre-setting the character position or the number of character segment groups.
[0044] Please see Figure 1 , Figure 1 This is a schematic flowchart illustrating a method for detecting character position and width provided in an embodiment of the present invention. The subject executing this method can be an electronic device, which may be, but is not limited to, personal computers, smart terminals, tablet computers, etc., and is not limited here.
[0045] like Figure 1 As shown, the method for detecting character position and width provided in this embodiment of the invention may include the following steps:
[0046] S101. Extract the character signal corresponding to the character to be detected from the character image to be detected.
[0047] S102. Perform wavelet transform on the character signal to obtain the time-spectrum data corresponding to the character signal, and preprocess the time-spectrum data; the time-spectrum data is used to maintain the wavelet convolution result value of the character signal at different positions corresponding to each frequency;
[0048] S103. Based on the preprocessed time-spectrum data, determine the time-domain energy signal of the character signal in the time-domain dimension, and determine the region corresponding to the time-domain energy value that is greater than the preset threshold as the character region of the character to be detected from the time-domain energy signal.
[0049] S104. Based on the preprocessed time-spectrum data, determine the frequency cumulative energy signal of the character signal in the frequency domain dimension, and determine the character width of the character to be detected based on the frequency corresponding to the maximum frequency cumulative energy value in the frequency cumulative energy signal and the width of the character image to be detected.
[0050] In the above-mentioned character positioning and width detection method, the character signal of the character to be detected is first obtained from the image of the character to be detected. Then, wavelet transform is performed on the character signal to obtain time-frequency spectrum data. Then, the time-domain energy signal corresponding to the character signal is determined from the time-domain dimension of the preprocessed time-frequency spectrum data. The region corresponding to the time-domain energy value greater than the preset threshold in the time-domain energy signal is determined as the character region of the character to be detected, thereby accurately locating the character region. Then, the frequency cumulative energy signal corresponding to the character signal is obtained in the frequency domain dimension. Based on the frequency corresponding to the maximum frequency cumulative energy value and the width of the character image to be detected, the character width of the character to be detected can be detected. The above-mentioned method provided by the embodiments of the present invention can not only solve the problems of difficulty and low accuracy in industrial detection of character position and width, but also has fewer data restrictions, a wider range of applications, strong robustness and error correction ability, and can also calculate character region and width for defective data.
[0051] The following will explain each of the above steps in detail with reference to the accompanying drawings.
[0052] In step S101, the character signal corresponding to the character to be detected is extracted from the character image to be detected.
[0053] In this embodiment of the invention, the character image to be detected provided by this embodiment can be as follows: Figure 2 As shown, Figure 2 This is an example image of a character to be detected provided in an embodiment of the present invention, wherein "6004 / P6YB4" and "BH" are both characters to be detected. Embodiments of the present invention can locate and detect the width of these characters. The methods for obtaining the image of the character to be detected may include, but are not limited to, the following implementation methods:
[0054] As one implementation method: the electronic device obtains the image of the character to be detected from local storage; or, the electronic device receives the image of the character to be detected transmitted by other electronic devices in real time, wherein the sub-image to be detected contains a row of characters to be detected;
[0055] As another implementation method: the electronic device acquires an industrial character image, which contains at least one line of characters to be detected, and crops the area where the characters to be detected are located to obtain the image of the characters to be detected.
[0056] In this embodiment of the invention, the following implementation method is provided for step S101 above. Please refer to [link / reference]. Figure 3 , Figure 3 This is a schematic flowchart of step S101 provided in an embodiment of the present invention. Step S101 may include:
[0057] S101-1. Adjust the arrangement mode of the characters to be detected in the image to be horizontal.
[0058] In this embodiment of the invention, in real-world scenarios, the characters to be detected in the image may appear at different angles or be arranged in a disorderly manner due to factors such as the shooting angle, the position and angle of the characters on the workpiece. These factors all affect the accuracy of the position and width of the detected characters. Therefore, the arrangement mode of the characters to be detected in the image can be adjusted to a horizontal arrangement to eliminate the interference of the above-mentioned adverse factors.
[0059] As an optional implementation method, the above adjustment method may include, but is not limited to, SVD matrix decomposition, optimization of rotational inertia, etc.
[0060] S101-2. Increase the image brightness of the area where the character to be detected is located.
[0061] In this embodiment of the invention, to further improve accuracy, the image of the character to be detected can be preprocessed to make the signal intensity of the character region high and the brightness of the background region image as low as possible. The following is a method for increasing image brightness in this embodiment of the invention, that is, the above step S102-2 can be performed as follows:
[0062] a1: Removes the texture region from the character image to be detected and converts the character image to grayscale.
[0063] In this embodiment of the invention, the method for removing texture regions can be, but is not limited to, bilateral filtering. Assuming the size of the character image to be detected is M×N×3, then after converting the image to grayscale, it can be represented as: I gray (M×N) represents the gray area, where M is the image height and N is the image width.
[0064] a2: In a grayscale image, adjust the pixel values whose grayscale is less than the image dark area threshold to the image dark area threshold, and adjust the pixel values whose grayscale is less than the image bright area threshold to the image bright area threshold.
[0065] In this embodiment, since the image capture process is affected by factors such as lighting and angle, dark areas exist in the image, which is not conducive to subsequent character positioning and width detection. Therefore, this embodiment of the invention can first determine the image dark area threshold based on the image brightness of the first percentile in the grayscale image, and determine the image brightness of the grayscale image other than the image brightness of the first percentile as the image bright area threshold. The first percentile and the second percentile can be set according to actual needs, and are not limited here.
[0066] Furthermore, based on the image brightness threshold and the image darkness threshold, the above grayscale image can be processed. For example, assuming an image darkness threshold c is defined... low Image brightness at the 10th percentile: c low =percentile(I,10), defines the image brightness threshold c. high Image brightness at the 90th percentile: c high =percentile(I,90), where I represents the grayscale image. The primary function of the percentile function is to return the Kth percentile value of the values in a region. Therefore, the image with grayscale values below c... low The pixel is set to c low Image grayscale is higher than c high The pixel is set to c high Step a2 above can be expressed as:
[0067]
[0068] in, The gray level in the i-th row and j-th column of the grayscale image is represented by... The grayscale value in the i-th row and j-th column of the grayscale image is represented by the adjusted grayscale value.
[0069] The above methods can remove noise from both dark and bright areas, further providing data assurance for subsequent accurate positioning and detection.
[0070] a3: Normalize all pixels based on the image dark area threshold and the image bright area threshold.
[0071] In this embodiment of the invention, after processing the grayscale image in step a2, all pixels can be normalized using the following formula:
[0072]
[0073] in, The pixel grayscale value after normalization is represented in the i-th row and j-th column.
[0074] In an optional implementation, if the character brightness is low after processing through steps a1 to a3, the entire image can be inverted, i.e., Ii,j =255-I i,j After ensuring that the character area has high brightness and increasing the image brightness of the area where the character to be detected is located, step S103-3 can be executed to obtain the binarized image.
[0075] S101-3. Based on the determined image threshold, the image of the character to be detected is processed to obtain a binarized image.
[0076] In this embodiment of the invention, the image threshold can be determined using, but is not limited to, the Otsu method. Then, based on the determined image threshold, the pixel values corresponding to pixels with pixel values greater than or equal to the image threshold are set to a first value, and the pixel values corresponding to pixels with pixel values less than the image threshold are set to a second value. The first and second values can be determined according to the actual situation, and this application does not limit this. For example, the pixel values of the character area can be set to 0, and the pixels of the background area can be set to 1. The resulting binarized image can be found in [reference needed]. Figure 4 , Figure 4 This is an example image of a binarized image provided in an embodiment of the present invention.
[0077] S101-4. In the binarized image, calculate the cumulative gray value of each column of pixels, and form a character signal based on each cumulative gray value.
[0078] In this embodiment of the invention, assuming the size of the binarized image is M×N, the grayscale values of each column of pixels are accumulated to obtain N accumulated grayscale values. These accumulated grayscale values are combined to form a character signal, denoted as S, where S is of the form [s1, s2, ... s2]. N The signal length is N, such as Figure 5 As shown, Figure 5 This is an example image of the character signal of the character to be detected provided in an embodiment of the present invention, where the horizontal axis represents the number of image columns and the vertical axis represents the accumulated grayscale value. Figure 5 From the image, we can roughly see that the character width is about 19; the character regions are [250, 440] and [934, 973], that is, the sub-image to be detected is between columns 250 and 440 in the image, and between columns 934 and 973.
[0079] This embodiment of the invention will analyze the obtained character signal from the perspectives of time domain and frequency domain, and finally achieve the purpose of detecting the character position and width. First, see step S102.
[0080] In step S102, wavelet transform is performed on the character signal to obtain the time-spectrum data corresponding to the character signal, and the time-spectrum data is preprocessed; the time-spectrum data is used to maintain the wavelet convolution result value of the character signal at different positions corresponding to each frequency.
[0081] In this embodiment of the invention, a one-dimensional wavelet transform is performed on the character signal S to obtain the signal time-spectrum data matrix at different positions and frequencies. Then, a frequency threshold can be defined to filter out regions with excessively low frequencies, eliminate interference, and improve accuracy.
[0082] This invention provides an implementation method for step S102, wherein step S102 may include the following steps:
[0083] b1: Perform wavelet transform on the character signal based on a preset wavelet basis to obtain time-spectrum data.
[0084] In this embodiment of the invention, wavelet transform is performed on the character signal, as follows:
[0085]
[0086] Among them, X a,b The wavelet transform result matrix represents the time-frequency data matrix. 'a' represents the scale (which can also be understood as frequency in the frequency domain), 'b' represents the translation (which can also be understood as position in the time domain), Ψ is the wavelet basis, and a high-performance basis can be selected according to the actual situation. S n X is the nth accumulated gray value in the character signal S. a,b A Y×N matrix can be represented in the following form:
[0087]
[0088] Where Y is the scale search range selected based on the actual situation, and X... a1,b1 The wavelet convolution result of the character signal S at scale a1 and translation b1 is represented by the value. Other values in the time-spectrum data matrix are similar and will not be described in detail here.
[0089] In the aforementioned time-frequency data matrix, the horizontal direction represents the time domain, and the vertical direction represents the frequency domain. The graphical representation of this video data matrix can be found in [reference needed]. Figure 6 , Figure 6 The above is a time-frequency spectrum of the character to be detected provided in an embodiment of the present invention, wherein the horizontal and vertical axes are in the time domain and the vertical axis is in the frequency domain.
[0090] It should be noted that the above representation of the time-spectrum data matrix is merely an example and not a limitation on the time-spectrum data matrix. In practical scenarios, the horizontal direction can also be taken as the frequency domain direction and the vertical direction as the time domain direction. The corresponding time-spectrum graphs will have the horizontal axis as the frequency domain and the vertical axis as the time domain. This application will use the above-mentioned horizontal and vertical axes as the time domain and the vertical axis as the frequency domain for subsequent scheme descriptions.
[0091] b2: Adjust the wavelet convolution result value corresponding to the frequency in the time spectrum data that is less than or equal to the preset frequency threshold to zero.
[0092] After obtaining the time-spectrum data, a frequency threshold can be defined, and the wavelet convolution result value corresponding to frequencies less than or equal to the frequency threshold can be set to 0, i.e., for the aforementioned X... a,b Perform the following processing:
[0093]
[0094] This allows for filtering out regions with excessively low frequencies, eliminating interference, and improving efficiency. Then, character regions can be located in the time domain and characters can be detected in the frequency domain, i.e., steps S103 to S104 are executed.
[0095] For "character positioning", in step S103, based on the preprocessed time-spectrum data, the time-domain energy signal of the character signal is determined in the time-domain dimension, and the region corresponding to the time-domain energy value that is greater than the preset threshold is determined as the character region of the character to be detected.
[0096] In this embodiment of the invention, from the above-mentioned time-spectrum data matrix and Figure 6 It can be seen that, in the time domain, the total number of columns in the time-frequency data matrix is consistent with the image width N (which is also the length of the character signal S). That is, the column positions in the time-frequency data matrix correspond one-to-one with the column positions in the image. Based on this, when detecting a character region, as long as the column positions where the character signal exists are determined, the character region can be determined. Therefore, for step S103 above, this embodiment of the invention provides the following... Figure 7 The implementation method shown, Figure 7 A schematic flowchart of step S103 provided in an embodiment of the present invention:
[0097] S103-1: From the preprocessed time-spectrum data, along the time domain direction, the maximum wavelet convolution result value at each frequency is determined as the time-domain energy value, and based on all time-domain energy values, the time-domain energy signal is obtained.
[0098] Continuing with the above X a,b For example, taking the maximum value of each column along the time domain direction, i.e., along the horizontal direction, as the time domain energy value, the final time domain energy signal is denoted as S. ti :
[0099]
[0100] The time-domain energy signal is denoted as S. ti The length of N represents the signal energy corresponding to each column of the character image to be detected. The time-domain energy signal is in the form of... Figure 8 As shown, Figure 8 This is an example diagram of the time-domain energy signal provided in an embodiment of the present invention. The horizontal and vertical axes represent the positions (corresponding to the column positions in the image), and the vertical axis represents the time-domain energy value.
[0101] S103-2, Determine the position in the time domain direction corresponding to the time domain energy value that is greater than a preset threshold from the time domain energy signal.
[0102] S103-3, the interval formed by this position is taken as the character area.
[0103] In this embodiment of the invention, a threshold value of th can be defined. ti According to S ti The relationship with a threshold determines the character region. Regions with energy values greater than the threshold are considered character regions; otherwise, they are non-character regions. The result is used to locate the character region. Specifically: if S... ti Greater than th ti Then S can be determined ti The corresponding image column, thus obtaining each image greater than th ti S ti The corresponding image columns, and the interval formed by these image columns, constitutes the character region.
[0104] For example, continue with Figure 8 For example, it can be seen that the time-domain energy values are significantly larger in the ranges of 200 to 500 and 900 to 1000. In this embodiment of the invention, the time-domain energy value is set to... ti The value is 2000, which determines the valid character region signal. Figure 9 As shown, Figure 9 The effective character region signal provided in the embodiments of the present invention is from Figure 9 The character ranges [244,446] and [927,975] can be obtained. The error between these ranges and the actual character ranges [250,440] and [934,973] is within an acceptable range, reflecting the accuracy of the positioning method provided by the embodiments of the present invention.
[0105] For “width detection”, in step S104, based on the preprocessed time-spectrum data, the time-domain energy signal of the character signal is determined in the time-domain dimension, and the region corresponding to the time-domain energy value that is greater than the preset threshold is determined as the character region of the character to be detected.
[0106] In this embodiment of the invention, based on Figure 6 It can be seen that there is a character frequency corresponding to the area containing characters. Therefore, in this embodiment of the invention, the frequency of the character signal occurrence can be determined first, and then the signal period can be calculated as the character width W based on the image size and signal frequency. Therefore, for the above step S104, this embodiment of the invention provides an implementation method, see [link to implementation]. Figure 10 , Figure 10 A schematic flowchart of step S104 provided in an embodiment of the present invention:
[0107] S104-1: From the preprocessed time-spectrum data, along the frequency domain direction, the wavelet convolution result values corresponding to each position are summed to obtain the frequency cumulative energy value, and the frequency cumulative energy signal is obtained based on the total frequency cumulative energy value.
[0108] Continuing with the above X a,b For example, along the frequency domain direction, that is, along the vertical direction, the accumulated value of the wavelet convolution result of each row is taken as the frequency accumulated energy value, and the final frequency accumulated energy signal is denoted as S. fre :
[0109]
[0110] The frequency cumulative energy signal is denoted as S. fre The length Y represents the cumulative frequency energy value corresponding to each line of the character image to be detected. The cumulative frequency energy signal is in the form of... Figure 11 As shown, Figure 11 This is an example diagram of the frequency cumulative energy signal provided in an embodiment of the present invention. The horizontal and vertical axes represent frequencies, and the vertical axis represents the frequency cumulative energy signal.
[0111] S104-2, determine the maximum frequency cumulative energy value and the frequency corresponding to the maximum frequency cumulative energy value from the frequency cumulative energy signal.
[0112] S104-3, The ratio of the width to the frequency of the character image to be detected is determined as the character width.
[0113] In this embodiment of the invention, the frequency corresponding to the position with the maximum frequency energy from the frequency accumulated energy signal is taken as the frequency f of the character signal. str :
[0114] f str =argmax(S fre )
[0115] Then, based on the image size N and the signal frequency f... str The signal period is calculated as the character width W.
[0116] W = N / f str
[0117] For easier understanding, please continue reading. Figure 11 It can be seen that the maximum frequency accumulated energy value appears at a frequency index of approximately 271, which is obtained through argmax(S fre The frequency-accumulated energy signal is processed, i.e., Figure 12 As shown, Figure 12This is a schematic diagram illustrating the determination of frequency in an embodiment of the present invention, showing the frequency f corresponding to a frequency index of approximately 271. str ≈62.6, therefore, the character width W = N / f str =1222 / 62.6≈19.5, which is within an acceptable range compared to the actual character width of 19, reflecting the accuracy of the width detection method provided by the embodiment of the present invention.
[0118] Based on the same inventive concept, embodiments of the present invention also provide a device for detecting character position and width; please refer to [link to related documentation]. Figure 13 , Figure 13 The present invention provides a functional block diagram of a device for detecting character position and width. The device 300 for detecting character position and width provided in the present invention may include: an extraction module 310, a transformation module 320, a positioning module 330, and a detection module 340.
[0119] The extraction module 310 is used to: extract the character signal corresponding to the character to be detected from the character image to be detected;
[0120] The transformation module 320 is used to: perform wavelet transform on the character signal to obtain the time-spectrum data corresponding to the character signal, and preprocess the time-spectrum data; the time-spectrum data is used to maintain the wavelet convolution result value of the character signal at different positions corresponding to each frequency;
[0121] The positioning module 330 is used to: determine the time-domain energy signal of the character signal in the time-domain dimension based on the preprocessed time-spectrum data, and determine the region corresponding to the time-domain energy value greater than a preset threshold from the time-domain energy signal as the character region of the character to be detected;
[0122] The detection module 340 is used to: determine the frequency cumulative energy signal of the character signal in the frequency domain dimension based on the preprocessed time-spectrum data, and determine the character width of the character to be detected based on the frequency corresponding to the maximum frequency cumulative energy value in the frequency cumulative energy signal and the width of the character image to be detected.
[0123] In an alternative implementation, the extraction module 310, transformation module 320, positioning module 330, and detection module 340 can be executed collaboratively. Figure 1 Each step in the process is used to achieve the corresponding technical effect.
[0124] In an optional implementation, the extraction module 310 is configured to: adjust the arrangement mode of the characters to be detected in the image to be horizontal; increase the image brightness of the area where the characters to be detected are located; and process the image to be detected based on a determined image threshold to obtain the binarized image. In the binarized image, the cumulative grayscale value of each column of pixels is calculated, and the character signal is formed based on each cumulative grayscale value.
[0125] In an optional implementation, the extraction module 310 is configured to: remove texture regions from the character image to be detected and convert the character image to be detected into a grayscale image; in the grayscale image, adjust pixel values with grayscale values less than the image dark area threshold to the image dark area threshold, and adjust pixel values with grayscale values less than the image bright area threshold to the image bright area threshold; and normalize all the pixels based on the image dark area threshold and the image bright area threshold.
[0126] In an optional implementation, the transformation module 320 is used to perform wavelet transform on the character signal based on a preset wavelet basis to obtain the time-spectrum data; and to adjust the wavelet convolution result value corresponding to the frequency in the time-spectrum data that is less than or equal to a preset frequency threshold to zero.
[0127] In an optional implementation, the positioning module 330 is configured to: determine the maximum wavelet convolution result value at each frequency from the preprocessed time-spectrum data along the time-domain direction as the time-domain energy value, and obtain the time-domain energy signal based on all the time-domain energy values; determine the position corresponding to the time-domain energy value greater than the preset threshold in the time-domain direction from the time-domain energy signal; and use the interval formed by the positions as the character region.
[0128] In an optional implementation, the detection module 340 is configured to: from the preprocessed time-spectrum data, along the frequency domain direction, sum the wavelet convolution result values corresponding to each position as a frequency cumulative energy value, and obtain the frequency cumulative energy signal based on all the frequency cumulative energy values; determine the maximum frequency cumulative energy value and the frequency corresponding to the maximum frequency cumulative energy value from the frequency cumulative energy signal; and determine the ratio of the width of the character image to be detected to the frequency as the character width.
[0129] The device 300 for detecting character position and width in this embodiment of the invention can be stored in the operating system (OS) of the electronic device 400 in the form of software or firmware.
[0130] Please see Figure 14 , Figure 14 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. The electronic device is used to implement the method for detecting character position and width in the above embodiments. See also... Figure 14 As shown, the electronic device 400 includes a memory 401, a processor 402, a communication interface 403, and a bus 404. The memory 401, processor 402, and communication interface 403 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines.
[0131] Optionally, bus 404 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 14 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0132] In this embodiment of the invention, the processor 402 may be a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in this embodiment of the invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in this embodiment of the invention can be directly manifested as execution by the hardware processor, or execution by a combination of hardware and software modules within the processor. The software modules may reside in the memory 401, and the processor 402 reads the program instructions from the memory 401 and, in conjunction with its hardware, completes the steps of the aforementioned methods.
[0133] In this embodiment of the invention, the memory 401 can be a non-volatile memory, such as a hard disk drive (HDD) or a solid-state drive (SSD), or it can be volatile memory, such as RAM. The memory can also be any other medium capable of carrying or storing desired program code in the form of instructions or data structures, and accessible by a computer, but is not limited thereto. The memory in this embodiment of the invention can also be a circuit or any other device capable of implementing storage functions, used to store instructions and / or data.
[0134] The memory 401 can be used to store software programs and modules, such as the instructions / modules of the device 300 for detecting character position and width provided in this embodiment of the invention. These can be stored in the memory 401 in the form of software or firmware, or embedded in the operating system (OS) of the electronic device 400. The processor 402 executes various functional applications and data processing by executing the software programs and modules stored in the memory 401. The communication interface 403 can be used for signaling or data communication with other node devices.
[0135] Based on the above embodiments, this application also provides a storage medium storing a computer program. When the computer program is executed by a computer, it causes the computer to perform the method for detecting character position and width provided in the above embodiments.
[0136] Based on the above embodiments, this application also provides a computer program that, when run on a computer, causes the computer to execute the method for detecting character position and width provided in the above embodiments.
[0137] Based on the above embodiments, this application also provides a chip for reading a computer program stored in a memory and executing the method for detecting character position and width provided in the above embodiments.
[0138] This application also provides a computer program product, including instructions that, when run on a computer, cause the computer to execute the method for detecting character position and width provided in the above embodiments.
[0139] This application describes embodiments of methods, apparatus (systems), and computer program products according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by instructions. These instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0140] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0141] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0142] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for detecting character position and width, characterized in that, The method includes: Extracting the character signal corresponding to the character to be detected from the character image to be detected includes: calculating the cumulative gray value of each column of pixels in the binarized image corresponding to the image to be detected, and forming the character signal based on each cumulative gray value; The character signal is subjected to wavelet transform to obtain the corresponding time-spectrum data. The time-spectrum data is then preprocessed, including adjusting the wavelet convolution result values corresponding to frequencies less than or equal to a preset frequency threshold in the time-spectrum data to zero. The time-spectrum data is used to maintain the wavelet convolution result values of the character signal at different positions corresponding to each frequency. The total number of columns in the time-spectrum data is consistent with the length of the character signal, and the total number of rows is the scale search range of the wavelet transform. Based on the preprocessed time-spectrum data, in the time domain dimension, for each position, the maximum value of the wavelet convolution result value at all frequencies at that position is determined as the time-domain energy value of that position, thereby obtaining the time-domain energy signal of the character signal, and from the time-domain energy signal, the region corresponding to the time-domain energy value greater than a preset threshold is determined as the character region of the character to be detected; From the preprocessed time-spectrum data, along the frequency domain direction, the wavelet convolution result values corresponding to each position are summed to obtain the frequency cumulative energy value, and the frequency cumulative energy signal is obtained based on all the frequency cumulative energy values; the maximum frequency cumulative energy value and the frequency corresponding to the maximum frequency cumulative energy value are determined from the frequency cumulative energy signal; the ratio of the width of the character image to be detected to the frequency is determined as the character width.
2. The method for detecting character position and width according to claim 1, characterized in that, Extracting the character signal corresponding to the character to be detected from the image of the character to be detected also includes: Adjust the arrangement of the characters to be detected within the image to a horizontal arrangement; Increase the image brightness of the area where the character to be detected is located; Based on a determined image threshold, the image of the character to be detected is processed to obtain the binarized image.
3. The method for detecting character position and width according to claim 2, characterized in that, Increasing the image brightness of the region containing the character to be detected includes: Remove the texture regions from the character image to be detected, and convert the character image to be detected into a grayscale image; In the grayscale image, pixel values with grayscale values less than the image dark area threshold are adjusted to the image dark area threshold, and pixel values with grayscale values less than the image bright area threshold are adjusted to the image bright area threshold. Based on the image dark area threshold and the image bright area threshold, all the pixels are normalized.
4. The method for detecting character position and width according to claim 3, characterized in that, The method further includes: The image brightness at the first percentile of the grayscale image is determined as the image dark area threshold, and the image brightness other than the second percentile of the grayscale image is determined as the image bright area threshold.
5. The method for detecting character position and width according to claim 1, characterized in that, Perform wavelet transform on the character signal to obtain the time-spectrum data corresponding to the character signal, and preprocess the time-spectrum data, including: The character signal is subjected to wavelet transform based on a preset wavelet basis to obtain the time-spectrum data.
6. The method for detecting character position and width according to claim 1, characterized in that, Based on the preprocessed time-spectrum data, in the time domain dimension, for each position, the maximum value among the wavelet convolution results at all frequencies is determined as the time-domain energy value of that position, thereby obtaining the time-domain energy signal of the character signal. From the time-domain energy signal, the region corresponding to the time-domain energy value greater than a preset threshold is determined as the character region of the character to be detected, including: From the time-domain energy signal, determine the position corresponding to the time-domain energy value that is greater than the preset threshold in the time-domain direction; The interval formed by the positions is taken as the character region.
7. A device for detecting the position and width of a character, characterized in that, include: The extraction module is used to: extract the character signal corresponding to the character to be detected from the character image to be detected, including: extracting the character signal corresponding to the character to be detected from the character image to be detected, including: calculating the cumulative gray value of each column of pixels in the binarized image corresponding to the image to be detected, and forming the character signal based on each cumulative gray value; The transformation module is used to: perform wavelet transform on the character signal to obtain time-spectrum data corresponding to the character signal, and preprocess the time-spectrum data, including adjusting the wavelet convolution result values corresponding to frequencies in the time-spectrum data that are less than or equal to a preset frequency threshold to zero; the time-spectrum data is used to maintain the wavelet convolution result values of the character signal at different positions corresponding to each frequency; wherein, the total number of columns in the time-spectrum data is consistent with the length of the character signal, and the total number of rows is the scale search range of the wavelet transform; The positioning module is used to: based on the preprocessed time-spectrum data, in the time domain dimension, for each position, determine the maximum value among the wavelet convolution results of the position at all frequencies as the time-domain energy value of the position, thereby obtaining the time-domain energy signal of the character signal, and determine the region corresponding to the time-domain energy value greater than a preset threshold from the time-domain energy signal as the character region of the character to be detected; The detection module is configured to: from the preprocessed time-spectrum data, along the frequency domain direction, sum the wavelet convolution results corresponding to each position as a cumulative frequency energy value, and obtain the cumulative frequency energy signal based on all the cumulative frequency energy values; determine the maximum cumulative frequency energy value and the frequency corresponding to the maximum cumulative frequency energy value from the cumulative frequency energy signal; and determine the character width as the ratio of the width of the character image to be detected to the frequency.
8. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a computer program executable by the processor, the processor being able to execute the computer program to implement the method of any one of claims 1 to 6.
9. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 6.