Method and device for detecting bill factors, terminal equipment and storage medium

文档序号:879858 发布日期:2021-03-19 浏览:13次 中文

阅读说明:本技术 一种检测票据要素的方法、装置、终端设备和存储介质 (Method and device for detecting bill factors, terminal equipment and storage medium ) 是由 张姣姣 于 2019-09-17 设计创作,主要内容包括:本申请涉及图像处理技术领域,提出一种检测票据要素的方法、装置、终端设备和存储介质。该方法在获取待测票据的原始灰度图像之后,会在该图像中选取一块区域,将该区域内各个像素点的灰度值设置为一个特定的灰度值,这个操作相当于往灰度值图像中额外添加一个具有要素的目标区域。当票据无要素或者要素和图像背景的对比度很低的时候,往票据的灰度值图像中添加额外的目标区域,能够在一定程度上增加灰度图像中目标和背景之间的对比度,获得更准确的最大类间方差,从而改善采用大津算法执行二值化处理的效果,使得后续可以获得更准确的票据要素检测结果。在二值化处理之后,会将添加的目标区域还原为背景区域,从而避免对后续的检测要素产生影响。(The application relates to the technical field of image processing, and provides a method and a device for detecting bill elements, terminal equipment and a storage medium. After the method obtains an original gray image of a bill to be tested, a region is selected from the image, the gray value of each pixel point in the region is set to be a specific gray value, and the operation is equivalent to adding an additional target region with elements in the gray value image. When the bill has no elements or the contrast between the elements and the image background is low, an additional target area is added into the gray value image of the bill, the contrast between the target and the background in the gray value image can be increased to a certain extent, and more accurate maximum inter-class variance is obtained, so that the effect of performing binarization processing by adopting an Otsu algorithm is improved, and more accurate bill element detection results can be obtained subsequently. After the binarization processing, the added target area is reduced to a background area, so that the influence on subsequent detection elements is avoided.)

1. A method of detecting a document feature, comprising:

acquiring an original gray image of a bill to be detected;

selecting a first region from the original gray image, and setting the gray value of each pixel point in the first region as a first gray value to obtain a first gray image, wherein the area of the first region is a preset proportion of the area of the original gray image, and the first gray value is larger than the average gray value of each pixel point of the original gray image or smaller than the average gray value of each pixel point of the original gray image;

performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image, wherein the second gray value is 0 if the first gray value is larger than the average gray value of each pixel point of the original gray image, and the second gray value is 255 if the first gray value is smaller than the average gray value of each pixel point of the original gray image;

and judging whether the bill to be detected has elements or not according to the second binary image.

2. The method of inspecting bill elements according to claim 1, further comprising, after obtaining the second binarized image:

selecting a second region from the original gray image, and setting the gray value of each pixel point in the second region as the first gray value to obtain a second gray image, wherein the second region and the first region are not intersected;

performing binarization processing on the second gray level image by using an Otsu algorithm to obtain a third binarization image;

setting the gray value of each pixel point in the second area in the third binary image as the second gray value to obtain a fourth binary image;

if the second gray value is 0, adjusting the gray value of each pixel point in the second binary image to be the minimum value of the gray values of the pixel points at the corresponding positions in the second binary image and the fourth binary image;

and if the second gray value is 255, adjusting the gray value of each pixel point in the second binary image to be the maximum value of the gray values of the pixel points at the corresponding positions in the second binary image and the fourth binary image.

3. The method of detecting a document element according to claim 1, wherein said extracting a first area in said original gray-scale image comprises:

selecting a preset number of pixel columns at the left boundary or the right boundary of the original gray image as the first area;

or

And selecting a preset number of pixel rows from the upper boundary or the lower boundary of the original gray image as the first area.

4. The method of detecting a document element according to claim 1, wherein the first gray scale value is determined by:

adding the gray value of the pixel point with the maximum gray value in the original gray image to a preset gray value to obtain a first gray value;

or

And subtracting the gray value of the pixel point with the minimum gray value in the original gray image from a preset gray value to obtain the first gray value.

5. The method of detecting a document element according to claim 1, wherein the first gray scale value is determined by:

sorting the gray values of all pixel points of the original gray image from large to small;

adding a gray value before the sequence in a preset proportion with a preset gray value to obtain a first gray value;

or

Sequencing the gray values of all pixel points of the original gray image from small to large;

subtracting a preset gray value from the gray value which is sequenced before the preset proportion to obtain the first gray value.

6. The method for detecting bill elements according to claim 1, wherein said judging whether the bill to be tested has elements or not based on the second binarized image comprises:

respectively counting the number of pixel points of the second gray value of each pixel row in the second binary image;

determining a target pixel row of which the number of the pixel points of the second gray value is greater than a preset number threshold;

if the number of the target pixel rows exceeds a preset row number threshold value, determining that the bill to be tested has elements;

and if the number of the target pixel rows does not exceed the row number threshold, determining that the bill to be tested has no elements.

7. The method for detecting bill elements according to any one of claims 1 to 6, further comprising, after acquiring an original gray image of a bill to be detected:

performing black cap operation processing of an image on the original gray image;

detecting whether the original gray-scale image after the black cap operation processing has a transverse line;

and if the original gray-scale image has the horizontal line, performing horizontal line removing processing on the original gray-scale image after the black cap operation processing.

8. An apparatus for detecting a document feature, comprising:

the gray level image acquisition module is used for acquiring an original gray level image of the bill to be detected;

the area selection module is used for selecting a first area from the original gray image and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image, wherein the area of the first area is a preset proportion of the area of the original gray image, and the first gray value is larger than the average gray value of each pixel point of the original gray image or smaller than the average gray value of each pixel point of the original gray image;

the binarization processing module is used for performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

a region gray value setting module, configured to set a gray value of each pixel point in the first region in the first binarized image to a second gray value, so as to obtain a second binarized image, where the second gray value is 0 if the first gray value is greater than an average gray value of each pixel point of the original gray image, and the second gray value is 255 if the first gray value is less than the average gray value of each pixel point of the original gray image;

and the element detection module is used for judging whether the bill to be detected has elements according to the second binary image.

9. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the steps of the method of detecting ticket elements according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method of detecting ticket elements according to any one of claims 1 to 7.

Technical Field

The present application relates to the field of image processing technologies, and in particular, to a method and an apparatus for detecting a ticket element, a terminal device, and a storage medium.

Background

When a bill is required to be subjected to subsequent OCR recognition, whether the factors such as the account name, the account number, the capital and small capital amount and the like exist or not needs to be detected, and the position of the factor is acquired when the factor is detected to exist, so that preparation is made for subsequent factor recognition or counterfeit identification.

At present, the detection of the bill elements usually adopts an image binarization mode to distinguish the bill elements from the image background, and then judges whether the bill elements exist or not.

One commonly used image binarization method is OTSU, which is an algorithm in Otsu, and is essentially to obtain the maximum inter-class variance between a target and a background to dynamically obtain a binarization threshold. When the bill has elements and the contrast between the elements and the image background is high, the OTSU can be adopted to obtain an accurate bill element detection result. However, when the document has no element or the contrast between the element and the image background is low, the gray value of the maximum inter-class variance position is not the expected binarization threshold, which generates very disordered binarization results, thereby causing errors in detecting whether the document element exists or not.

Disclosure of Invention

In view of the above, the embodiments of the present application provide a method, an apparatus, a terminal device and a storage medium for detecting a document element, which can obtain an accurate document element detection result even when the document has no element or the contrast between the element and the image background is low.

A first aspect of an embodiment of the present application provides a method for detecting a ticket element, including:

acquiring an original gray image of a bill to be detected;

selecting a first region from the original gray image, and setting the gray value of each pixel point in the first region as a first gray value to obtain a first gray image, wherein the area of the first region is a preset proportion of the area of the original gray image, and the first gray value is larger than the average gray value of each pixel point of the original gray image or smaller than the average gray value of each pixel point of the original gray image;

performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image, wherein the second gray value is 0 if the first gray value is larger than the average gray value of each pixel point of the original gray image, and the second gray value is 255 if the first gray value is smaller than the average gray value of each pixel point of the original gray image;

and judging whether the bill to be detected has elements or not according to the second binary image.

After the original gray image of the bill to be tested is obtained, an area is selected from the image, the gray value of each pixel point in the area is set to be a specific gray value, and the operation is equivalent to adding an additional target area with elements in the gray value image. When the bill has no elements or the contrast between the elements and the image background is low, an additional target area is added into the gray value image of the bill, the contrast between the target and the background in the gray value image can be increased to a certain extent, and more accurate maximum inter-class variance is obtained, so that the effect of performing binarization processing by adopting an Otsu algorithm is improved, and more accurate bill element detection results can be obtained subsequently. In addition, after the binarization processing, the gray value of each pixel point in the area in the binarized image is set to be 0 or 255, which is equivalent to restoring the added target area to the background area, so that the influence of the added target area on subsequent detection elements is avoided.

Further, after obtaining the second binarized image, the method may further include:

selecting a second region from the original gray image, and setting the gray value of each pixel point in the second region as the first gray value to obtain a second gray image, wherein the second region and the first region are not intersected;

performing binarization processing on the second gray level image by using an Otsu algorithm to obtain a third binarization image;

setting the gray value of each pixel point in the second area in the third binary image as the second gray value to obtain a fourth binary image;

if the second gray value is 0, adjusting the gray value of each pixel point in the second binary image to be the minimum value of the gray values of the pixel points at the corresponding positions in the second binary image and the fourth binary image;

and if the second gray value is 255, adjusting the gray value of each pixel point in the second binary image to be the maximum value of the gray values of the pixel points at the corresponding positions in the second binary image and the fourth binary image.

In order to solve the problem that the binarization result of the elements is missing when the added area is covered with the position of the element, which causes the added area to be restored to the background area subsequently, another area which is not intersected with the area selected for the first time can be selected again in the original gray-scale image, and the other area is subjected to the same operation processing as the area selected for the first time, so that another binarization image is obtained. And finally, solving the minimum value or the maximum value of the gray levels of the corresponding pixel positions of the two obtained binary images to obtain the final binary image.

Further, the selecting a first region in the original grayscale image may include:

selecting a preset number of pixel columns at the left boundary or the right boundary of the original gray image as the first area;

or

And selecting a preset number of pixel rows from the upper boundary or the lower boundary of the original gray image as the first area.

In selecting the first area, in order to avoid covering the area with elements as much as possible, the edge area of the original grayscale image is preferred, for example, a preset number of pixel columns may be selected as the first area at the left or right boundary of the original grayscale image, or a preset number of pixel rows may be selected as the first area at the upper or lower boundary of the original grayscale image.

Further, the first gray value may be determined by:

adding the gray value of the pixel point with the maximum gray value in the original gray image to a preset gray value to obtain a first gray value;

or

And subtracting the gray value of the pixel point with the minimum gray value in the original gray image from a preset gray value to obtain the first gray value.

The gray value of the region to be added to the original gray image should be greatly different from the gray value of the background region of the image. Therefore, the gray value of the pixel with the maximum gray value in the original gray image may be added to a preset gray value (for example, 50), or the gray value of the pixel with the minimum gray value in the original gray image may be subtracted from a preset gray value to obtain the first gray value, where the two methods respectively correspond to the case of the white paper and the case of the black paper and the white paper.

Further, the first gray value may be determined by:

sorting the gray values of all pixel points of the original gray image from large to small;

adding a gray value before the sequence in a preset proportion with a preset gray value to obtain a first gray value;

or

Sequencing the gray values of all pixel points of the original gray image from small to large;

subtracting a preset gray value from the gray value which is sequenced before the preset proportion to obtain the first gray value.

Sometimes, there are some noise points with extremely high or extremely low gray scale values on the gray scale image, and the first gray scale value is determined according to the gray scale values of these noise points, sometimes the ideal effect cannot be obtained. Therefore, the gray values of the pixels in the gray image can be sequenced, and a gray value before the preset proportion is selected to determine the first gray value. For example, if 10000 pixels are assumed, the gray value of the pixel with the gray value of the first 4%, that is, the gray value of the pixel with the gray value of the 400 th bit, may be selected, and the selected gray value is added to a preset gray value (for example, 50), or the selected gray value is subtracted from a preset gray value, so as to obtain the first gray value, where the two manners correspond to the cases of the black character and the black character on the white paper, respectively.

Specifically, the determining whether the to-be-detected bill has elements according to the second binarized image may include:

respectively counting the number of pixel points of the second gray value of each pixel row in the second binary image;

determining a target pixel row of which the number of the pixel points of the second gray value is greater than a preset number threshold;

if the number of the target pixel rows exceeds a preset row number threshold value, determining that the bill to be tested has elements;

and if the number of the target pixel rows does not exceed the row number threshold, determining that the bill to be tested has no elements.

After the binary image is obtained, a mode of counting the number of rows with specific pixel points in the binary image can be adopted when judging whether the bill to be detected has elements. For example, for a binarized image with white background and black characters, the number of black points in each line in the binarized image is counted, pixel lines with the number of black points exceeding a certain threshold value are found out, and if the number of the pixel lines exceeds a preset line number threshold value, the bill image is indicated to have characters or patterns, so that the bill to be detected is determined to have elements; if the number of the pixel lines is not the preset line number threshold value, the bill image is indicated to have no characters or patterns, so that the bill to be detected is determined to have no elements.

Specifically, after the original gray image of the to-be-detected bill is acquired, the method may further include:

performing black cap operation processing of an image on the original gray image;

detecting whether the original gray-scale image after the black cap operation processing has a transverse line;

and if the original gray-scale image has the horizontal line, performing horizontal line removing processing on the original gray-scale image after the black cap operation processing.

After the original grayscale image is acquired, some pre-processing may also be performed on the original grayscale image to optimize the quality of the image before the binarization process is performed on the image. For example, black cap operation processing of the image can be performed, so that the background brightness of the gray level image is more uniform, and the influence of color difference gradual change of the image background on subsequent binaryzation by adopting an Otsu algorithm is avoided. In addition, there is a bill in which an area for filling elements has a horizontal line, and in order to eliminate an adverse effect of the horizontal line on the binarization process, a horizontal line removal process may be performed on the original tone image.

A second aspect of an embodiment of the present application provides an apparatus for detecting a form element, including:

the gray level image acquisition module is used for acquiring an original gray level image of the bill to be detected;

the area selection module is used for selecting a first area from the original gray image and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image, wherein the area of the first area is a preset proportion of the area of the original gray image, and the first gray value is larger than the average gray value of each pixel point of the original gray image or smaller than the average gray value of each pixel point of the original gray image;

the binarization processing module is used for performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

a region gray value setting module, configured to set a gray value of each pixel point in the first region in the first binarized image to a second gray value, so as to obtain a second binarized image, where the second gray value is 0 if the first gray value is greater than an average gray value of each pixel point of the original gray image, and the second gray value is 255 if the first gray value is less than the average gray value of each pixel point of the original gray image;

and the element detection module is used for judging whether the bill to be detected has elements according to the second binary image.

A third aspect of an embodiment of the present application provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method for detecting a ticket element as provided in the first aspect of an embodiment of the present application when executing the computer program.

A fourth aspect of embodiments of the present application provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method of detecting a form element as provided in the first aspect of embodiments of the present application.

A fifth aspect of the embodiments of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the steps of the method for detecting ticket elements according to the first aspect of the embodiments of the present application.

It is understood that the beneficial effects of the second aspect to the fifth aspect can be referred to the related description of the first aspect, and are not described herein again.

Drawings

In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.

Fig. 1 is a flowchart of a first embodiment of a method for detecting a form element according to an embodiment of the present application;

fig. 2 is a flowchart of a second embodiment of a method for detecting a form element according to an embodiment of the present application;

fig. 3 is a flowchart of a third embodiment of a method for detecting a form element according to an embodiment of the present application;

fig. 4 is a flowchart of a fourth embodiment of a method for detecting a form element according to an embodiment of the present application;

FIG. 5.1 is an original gray image of a bill to be tested;

FIG. 5.2 is an image obtained by performing binarization operation on the image of FIG. 5.1 by using the Otsu algorithm;

FIG. 5.3 is an image obtained after performing a preprocessing operation such as a black cap algorithm on FIG. 5.1;

FIG. 5.4 is an image obtained by setting the gray scale values of the pixels in the 0 th to 4 th rows of pixels in FIG. 5.3 to a specific value;

FIG. 5.5 is an image obtained by performing binarization on FIG. 5.4 using Otsu's algorithm;

fig. 5.6 is an image obtained by setting the gray value of each pixel point of the 0 th-4 th row pixels in fig. 5.5 to 0 and then performing black-and-white inversion processing;

FIG. 6 is a block diagram of an embodiment of an apparatus for detecting a form element according to an embodiment of the present disclosure;

fig. 7 is a schematic diagram of a terminal device according to an embodiment of the present application.

Detailed Description

In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail. Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.

The embodiment of the application provides a method, a device, a terminal device and a storage medium for detecting bill elements, and when the bill has no elements or the contrast between the elements and the image background is low, an accurate bill element detection result can be obtained. It should be understood that the execution subject of each method embodiment of the present application is a terminal device or a server for executing ticket identification.

Referring to fig. 1, a method for detecting a ticket element in an embodiment of the present application is shown, including:

101. acquiring an original gray image of a bill to be detected;

firstly, an original gray image of a bill to be tested is obtained. The bill to be detected is a bill which needs to detect whether elements exist, for example, the bill can be a bill of a bank, and whether elements such as a house name, an account number, a signature, capital and small capital amount exist needs to be detected. In addition, if the acquired image of the bill to be tested is a color image, the color image needs to be processed by removing a background of a shading and the like, and then converted into a gray image.

102. Selecting a first area from the original gray image, and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image;

after obtaining an original gray image of a bill to be tested, selecting a part of area in the gray image, and setting the gray value of each pixel point in the area as a first gray value to obtain a first gray image. The area of the selected area is a preset proportion of the area of the original gray image, the proportion is preferably 0.5% -10%, if the proportion is too small, the added area may not achieve the desired effect, and if the proportion is too large, the area with the original elements is likely to be covered, so that the subsequent element detection is affected. The selected region may have any shape, or may be a plurality of separate regions. The first gray value is larger than the average gray value of each pixel point of the original gray image or smaller than the average gray value of each pixel point of the original gray image, and the two modes respectively correspond to the conditions of white paper and black paper. This operation corresponds to adding an object region with elements to the gray-value image, and the gray value of the region (i.e. the first gray value) should be clearly different from the gray value of the background region of the image.

Preferably, the selecting a first region in the original grayscale image may include:

selecting a preset number of pixel columns at the left boundary or the right boundary of the original gray image as the first area;

or

And selecting a preset number of pixel rows from the upper boundary or the lower boundary of the original gray image as the first area.

In selecting the first area, in order to avoid covering the area with elements as much as possible, the edge area of the original grayscale image is preferred, for example, a preset number of pixel columns may be selected as the first area at the left or right boundary of the original grayscale image, or a preset number of pixel rows may be selected as the first area at the upper or lower boundary of the original grayscale image.

Further, the first gray value may be determined by:

adding the gray value of the pixel point with the maximum gray value in the original gray image to a preset gray value to obtain a first gray value;

or

And subtracting the gray value of the pixel point with the minimum gray value in the original gray image from a preset gray value to obtain the first gray value.

The gray value of the region to be added to the original gray image should be greatly different from the gray value of the background region of the image. Therefore, the gray value of the pixel with the maximum gray value in the original gray image may be added to a preset gray value (for example, 50), or the gray value of the pixel with the minimum gray value in the original gray image may be subtracted from a preset gray value to obtain the first gray value, where the two methods respectively correspond to the case of the white paper and the case of the black paper and the white paper.

Further, the first gray value may be determined by:

sorting the gray values of all pixel points of the original gray image from large to small;

adding a gray value before the sequence in a preset proportion with a preset gray value to obtain a first gray value;

or

Sequencing the gray values of all pixel points of the original gray image from small to large;

subtracting a preset gray value from the gray value which is sequenced before the preset proportion to obtain the first gray value.

Sometimes, there are some noise points with extremely high or extremely low gray scale values on the gray scale image, and the first gray scale value is determined according to the gray scale values of these noise points, sometimes the ideal effect cannot be obtained. Therefore, the gray values of the pixels in the gray image can be sequenced, and a gray value before the preset proportion is selected to determine the first gray value. For example, if 10000 pixels are assumed, the gray value of the pixel with the gray value of the first 4% can be selected, that is, the gray value of the pixel with the gray value of the 400 th bit is ranked. The first gray value is obtained by adding the selected gray value to a preset gray value (for example, 50) or subtracting the selected gray value from a preset gray value, which correspond to the case of black characters on white paper and black characters on black paper, respectively.

103. Performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

after the first gray level image is obtained, the first gray level image is subjected to binarization processing by using an Otsu algorithm to obtain a first binarized image. The operation of step 102 corresponds to adding an additional target area with elements to the gray-scale value image. When the bill has no elements or the contrast between the elements and the image background is low, an additional target area is added into the gray value image of the bill, the contrast between the target and the background in the gray value image can be increased to a certain extent, and the more accurate maximum inter-class variance is obtained, so that the effect of performing binarization processing by adopting an Otsu algorithm is improved. Therefore, the binarized image obtained in step 103 is a good quality image capable of clearly distinguishing the target and the background.

104. Setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image;

and then, setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image. If the first gray value is greater than the average gray value of each pixel point of the original gray image, the second gray value is 0, and if the first gray value is less than the average gray value of each pixel point of the original gray image, the second gray value is 255, which correspond to the situation of a white paper and a black paper. This operation is equivalent to restoring the added target area to the background area, thereby avoiding the added target area from affecting the subsequent detection elements.

In addition, if the second binary image does not conform to the conventional reading habit (such as white paper and black characters), the black pixel points and the white pixel points of the second binary image can be exchanged, namely the black pixel points are converted into the white pixel points, the white pixel points are converted into the black pixel points, and black-white inversion is performed.

105. And judging whether the bill to be detected has elements or not according to the second binary image.

And finally, judging whether the bill to be detected has elements or not according to the second binary image. The specific determination methods are various, and for example, the determination can be performed by detecting whether the number or the proportion of specific pixel points (black points or white points) in the binarized image exceeds a preset threshold; the method can be judged by detecting the number of the pixel rows of which the number of the specific pixel points exceeds the preset number in the binary image; the determination can be made by detecting the number of the specific pixel points in the binarized image which exceeds the number of the pixel columns with the preset number, and the like.

After the original gray image of the bill to be tested is obtained, an area is selected from the image, the gray value of each pixel point in the area is set to be a specific gray value, and the operation is equivalent to adding an additional target area with elements in the gray value image. When the bill has no elements or the contrast between the elements and the image background is low, an additional target area is added into the gray value image of the bill, the contrast between the target and the background in the gray value image can be increased to a certain extent, and more accurate maximum inter-class variance is obtained, so that the effect of performing binarization processing by adopting an Otsu algorithm is improved, and more accurate bill element detection results can be obtained subsequently. In addition, after the binarization processing, the gray value of each pixel point in the area in the binarized image is set to be 0 or 255, which is equivalent to restoring the added target area to the background area, so that the influence of the added target area on subsequent detection elements is avoided.

Referring to fig. 2, another method for detecting a form element in an embodiment of the present application is shown, including:

201. acquiring an original gray image of a bill to be detected;

202. selecting a first area from the original gray image, and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image;

203. performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

204. setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image;

the steps 201-204 are the same as the steps 101-104, and the related description of the steps 101-104 can be referred to specifically.

205. Selecting a second area from the original gray image, and setting the gray value of each pixel point in the second area as the first gray value to obtain a second gray image;

if the selected first area is just covered with the position of the element, when the first area is subsequently restored to the background area, the element is erroneously restored to the background, so that the problem of missing the binarization result of the element occurs. In order to solve the problem, a second region may be selected from the original grayscale image, and the grayscale value of each pixel point in the second region is set as the first grayscale value, so as to obtain a second grayscale image. It should be noted that the selected second region does not intersect with the first region, and the area size of the second region and the specific position in the original grayscale image are not limited.

One convenient way to select the area is to make the second area and the first area symmetrical about the center point of the original gray image, for example, if the original gray image is an image with 500 (0-499 columns), and the first area is the 0-4 column area at the leftmost end in the original gray image, then the second area is the 495-499 column area at the rightmost end point symmetrical about the center point of the image with the first area.

206. Performing binarization processing on the second gray level image by using an Otsu algorithm to obtain a third binarization image;

207. setting the gray value of each pixel point in the second area in the third binary image as the second gray value to obtain a fourth binary image;

and performing the same operation processing as the first region on the selected second region to obtain another binary image, namely a fourth binary image.

208. Judging that the second gray value is 0 or 255;

if the second gray scale value is 0, go to step 209, and then go to step 211; if the second gray scale value is 255, step 210 is performed, and then step 211 is performed.

209. Adjusting the gray value of each pixel point in the second binary image to be the minimum value of the gray values of the pixel points at corresponding positions in the second binary image and the fourth binary image;

210. adjusting the gray value of each pixel point in the second binary image to be the maximum value of the gray values of the pixel points at corresponding positions in the second binary image and the fourth binary image;

in order to solve the problem that the binarization result of the elements is missing when the added area is covered with the position of the element, which causes the added area to be restored to the background area subsequently, another area which is not intersected with the area selected for the first time can be selected again in the original gray-scale image, and the other area is subjected to the same operation processing as the area selected for the first time, so that another binarization image is obtained. And finally, calculating the minimum value or the maximum value (corresponding to the situation of white paper and black paper respectively) of the gray levels of the corresponding pixel positions of the two obtained binary images to obtain the final binary image. If the area selected for the first time is covered to the position X with elements, the binarization result of the position X in the first binarized image will be lost when the added area is reduced to the background area. Because the area selected for the second time is not intersected with the area selected for the first time, namely the area selected for the second time does not cover the position X, the binarization result of the position X in the obtained second binarization image is not lost, and finally the minimum value or the maximum value of the gray levels of the corresponding pixel positions of the two obtained binarization images is obtained, so that the final binarization image with the complete binarization result of the position X can be obtained.

211. And judging whether the bill to be detected has elements or not according to the second binary image.

And finally, judging whether the bill to be detected has elements or not according to the second binary image. It should be noted that, in this embodiment, the second binarized image is generated by obtaining the minimum value or the maximum value of the gray scale of the corresponding pixel position of the two obtained binarized images, and even if the selected first region is just covered with the position of the element, the problem of missing the binarized result of the element will not occur.

On the basis of the first embodiment, another region which is not intersected with the first selected region is selected from the original gray-scale image, and the other region is subjected to the same operation processing as the first selected region to obtain another binary image. And finally, solving the minimum value or the maximum value of the gray levels of the corresponding pixel positions of the two obtained binary images to obtain the final binary image. By such an arrangement, it is possible to solve the problem that the binarization result of the element is missing due to the added area being just covered with the position of the element.

Referring to fig. 3, another method for detecting a form element in an embodiment of the present application is shown, including:

301. acquiring an original gray image of a bill to be detected;

302. selecting a first area from the original gray image, and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image;

303. performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

304. setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image;

the steps 301-304 are the same as the steps 101-104, and the related description of the steps 101-104 can be referred to.

305. Respectively counting the number of pixel points of the second gray value of each pixel row in the second binary image;

after the second binary image is obtained, the number of the pixel points of the second gray scale value of each pixel row in the second binary image is respectively counted. That is, for the case of black characters on white paper, the number of black dots of each pixel row is counted; for the case of black paper and white words, the number of white dots per pixel line is counted.

306. Determining a target pixel row of which the number of the pixel points of the second gray value is greater than a preset number threshold;

and then, determining the target pixel rows of which the number of the pixel points of the second gray value is greater than a preset number threshold, wherein the number threshold can be reasonably set according to the size of the bill image. In the case of a black-and-white character, the target pixel line is a pixel line in which the number of black dots exceeds a certain threshold, that is, a pixel line having an element such as a character in a large probability.

307. Judging whether the number of the target pixel rows exceeds a preset row number threshold value or not;

and then, judging whether the number of the target pixel rows exceeds a preset row number threshold value. If the number of the target pixel rows exceeds the preset row number threshold, executing step 308; if the number of target pixel rows does not exceed the row number threshold, go to step 309.

308. Determining that the bill to be tested has elements;

the number of the target pixel rows exceeds a preset row number threshold value, which indicates that the number of the pixel rows with high probability of having elements such as characters and the like meets the determination requirement of having elements, so that the bill to be detected can be determined to have elements.

309. And determining that the bill to be tested has no elements.

The number of the target pixel rows does not exceed the preset row number threshold, which indicates that the number of the pixel rows with elements such as characters at high probability does not meet the judgment requirement of the elements, so that the bill to be detected can be determined to have no elements.

After the binary image is obtained, a mode of counting the number of rows with specific pixel points in the binary image can be adopted when judging whether the bill to be detected has elements. For example, for a binarized image with white background and black characters, the number of black points in each line in the binarized image is counted, pixel lines with the number of black points exceeding a certain threshold value are found out, and if the number of the pixel lines exceeds a preset line number threshold value, the bill image is indicated to have characters or patterns, so that the bill to be detected is determined to have elements; if the number of the pixel lines is not the preset line number threshold value, the bill image is indicated to have no characters or patterns, so that the bill to be detected is determined to have no elements. Compared with the first embodiment of the present application, this embodiment proposes a specific manner for determining whether the to-be-detected bill has an element according to the second binary image.

Referring to fig. 4, another method for detecting a form element in the embodiment of the present application is shown, including:

401. acquiring an original gray image of a bill to be detected;

step 401 is the same as step 101, and specific reference may be made to the related description of step 101.

402. Performing black cap operation processing of an image on the original gray image;

after the original grayscale image is acquired, some pre-processing may also be performed on the original grayscale image to optimize the quality of the image before the binarization process is performed on the image. For example, black cap operation processing of the image can be performed, so that the background brightness of the gray level image is more uniform, and the influence of color difference gradual change of the image background on subsequent binaryzation by adopting an Otsu algorithm is avoided.

The black cap operation is to subtract the result of the original image from the image closing operation to obtain a small hole inside the image or a small black spot in the image foreground. When the element color of the bill is lighter and the contrast with the background is lower, the difference between the target element and the image background can be highlighted to a certain extent by adopting the black cap operation.

It should be noted that, assuming that the image background is very clean and there is no grid texture, the difference between the element and the background can be increased by using the black-cap algorithm for preprocessing. If the contrast ratio of the elements and the background is poor and the image background has a large number of grids, the difference between the elements and the background cannot be highlighted by using a black cap algorithm, and the difference between the elements and the background can be increased by adopting a variance calculation mode.

403. Detecting whether the original gray-scale image after the black cap operation processing has a transverse line;

if the original gray-scale image after the black cap operation has a horizontal line, executing step 404, and then executing step 405; if there is no horizontal line in the original gray image after the black-hat operation, step 405 is directly executed.

404. Performing horizontal line removing processing on the original gray level image subjected to black cap operation processing;

in some documents, the area for filling in the elements has a horizontal line, and if the font color of the elements is relatively light and the contrast with the image background is low, the horizontal line will have a relatively serious influence on the subsequent binarization processing. In order to eliminate the adverse effect of the horizontal lines on the binarization process, a horizontal line removal process may be performed on the original grayscale image after the black-hat operation process. Specifically, the removal of the horizontal lines can be realized by detecting pixel rows having pixels with a specific gray value (such as black dots or approximately black dots) whose number exceeds a threshold, regarding the pixel rows as the horizontal lines, and then setting the gray values of the pixels with the horizontal lines as the gray values of the image background.

405. Selecting a first area from the original gray image, and setting the gray value of each pixel point in the first area as a first gray value to obtain a first gray image;

406. performing binarization processing on the first gray level image by using an Otsu algorithm to obtain a first binarized image;

407. setting the gray value of each pixel point in the first area in the first binarized image as a second gray value to obtain a second binarized image;

408. and judging whether the bill to be detected has elements or not according to the second binary image.

The steps 405-408 are the same as the steps 102-105, and the related description of the steps 102-105 can be referred to.

After the original gray image of the bill to be tested is obtained and before binarization processing is performed, certain preprocessing operation is performed on the original gray image to optimize the quality of the image. Specifically, the black cap operation processing of the image can be executed, so that the background brightness of the gray level image is more uniform, and the influence of the color difference gradual change of the image background on the subsequent binaryzation by adopting the Otsu algorithm is avoided. In addition, there are some bills in which the area for filling in the elements has a horizontal line, and in order to eliminate the adverse effect of the horizontal line on the binarization process, the original grayscale image may be subjected to a horizontal line removal process.

It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.

For convenience of understanding, the following describes a practical application scenario of the method for detecting a document element according to the embodiment of the present application.

(1) Acquiring an original gray image of a bill to be detected;

assuming that the original gray-scale image of the acquired bill to be tested is as shown in fig. 5.1, the a image corresponds to an element (few words), the B image corresponds to no element, and the C image corresponds to an element (multiple words).

If the Dajin algorithm is directly used to perform binarization operation on the gray-scale image of FIG. 5.1, the obtained result is shown in FIG. 5.2. In fig. 5.2, it is easy to determine that the a image is an element, but if it is determined that there is no element and an element (multi-character) clearly, that is, if it is determined that the B image is no element and the C image is an element accurately, it is difficult to determine that there is an element, and there is a high possibility that an erroneous determination may occur.

(2) Performing preprocessing operations such as a black cap algorithm on the gray level image;

after the grayscale image of fig. 5.1 is obtained, preprocessing operations such as black cap algorithm are performed on the image, so as to obtain the image shown in fig. 5.3.

(3) Selecting a region for the preprocessed gray image, and setting the gray value of each pixel point in the region as a certain specific value;

in the image of fig. 5.3, the area where the 0 th to 4 th rows of pixels are located is selected, and the gray value of each pixel point in the area is set to a certain value, so that the image of fig. 5.4 is obtained. As can be seen from fig. 5.4, the effect of this operation is equivalent to adding a region different from the background image to the gray-scale image, and the contrast between the object of the image and the background can be improved to some extent.

(4) Performing binarization operation on the image obtained in the step (3) by using an Otsu algorithm;

and (5) carrying out binarization operation on the image of the figure 5.4 by using an Otsu algorithm to obtain the image of the figure 5.5.

(5) Setting the gray value of each pixel point in the selected block area as 0 for the image obtained in the step (4), and executing black-white inversion processing;

setting the gray scale value of each pixel point of the 0 th-4 th column pixels in fig. 5.5 to 0 (equivalent to restoring the added area to the image background), and then performing the black-white inversion process, the image of fig. 5.6 is obtained.

(6) And judging whether the bill to be detected has elements or not according to the image after black-white inversion processing.

Comparing fig. 5.6 with fig. 5.2, it can be clearly found that the image binarization effect of fig. 5.6 is far better than that of fig. 5.2. In fig. 5.6, it can be easily determined that the image a is an element, the image B is an element-free image, and the image C is an element-free image, thereby realizing accurate detection of the presence or absence of the bill element.

The above mainly describes a method of detecting a bill element, and an apparatus for detecting a bill element will be described below.

Referring to fig. 6, an embodiment of an apparatus for detecting a form element in an embodiment of the present application includes:

the gray image acquisition module 601 is used for acquiring an original gray image of a bill to be detected;

a region selection module 602, configured to select a first region from the original grayscale image, and set a grayscale value of each pixel point in the first region as a first grayscale value, so as to obtain a first grayscale image, where an area of the first region is a preset proportion of an area of the original grayscale image, and the first grayscale value is greater than an average grayscale value of each pixel point of the original grayscale image or is smaller than the average grayscale value of each pixel point of the original grayscale image;

a binarization processing module 603, configured to perform binarization processing on the first grayscale image by using an atrazine algorithm to obtain a first binarized image;

a region gray value setting module 604, configured to set a gray value of each pixel point in the first region in the first binarized image to be a second gray value, so as to obtain a second binarized image, where the second gray value is 0 if the first gray value is greater than an average gray value of each pixel point of the original gray image, and the second gray value is 255 if the first gray value is smaller than the average gray value of each pixel point of the original gray image;

and the element detection module 605 is configured to determine whether the to-be-detected bill has an element according to the second binary image.

Further, the apparatus for detecting a form element may further include:

a second region selection module, configured to select a second region from the original grayscale image, and set a grayscale value of each pixel point in the second region as the first grayscale value, so as to obtain a second grayscale image, where the second region and the first region do not intersect;

the second binarization processing module is used for performing binarization processing on the second gray level image by using an Otsu algorithm to obtain a third binarization image;

a second region gray value setting module, configured to set a gray value of each pixel point in the second region in the third binary image as the second gray value, so as to obtain a fourth binary image;

a first gray value adjusting module, configured to adjust a gray value of each pixel point in the second binarized image to a minimum value of gray values of pixel points at corresponding positions in the second binarized image and the fourth binarized image if the second gray value is 0;

and the second gray value adjusting module is used for adjusting the gray value of each pixel point in the second binary image to the maximum value of the gray values of the pixel points at the corresponding positions in the second binary image and the fourth binary image if the second gray value is 255.

Preferably, the region selection module may include:

a first region selection unit, configured to select a preset number of pixel rows as the first region at a left boundary or a right boundary of the original grayscale image;

and the second area selection unit is used for selecting a preset number of pixel rows from the upper boundary or the lower boundary of the original gray-scale image as the first area.

Further, the apparatus for detecting a form element may further include:

the first gray value determining module is used for adding the gray value of the pixel point with the maximum gray value in the original gray image to a preset gray value to obtain a first gray value;

and the second gray value determining module is used for subtracting the gray value of the pixel point with the minimum gray value in the original gray image from a preset gray value to obtain the first gray value.

Further, the apparatus for detecting a form element may further include:

the first gray value sorting module is used for sorting the gray values of all pixel points of the original gray image from large to small;

the third gray value determining module is used for adding a gray value which is sequenced before the preset proportion with a preset gray value to obtain the first gray value;

the second gray value sequencing module is used for sequencing the gray values of all pixel points of the original gray image from small to large;

and the fourth gray value determining module is used for subtracting a preset gray value from the gray value which is sequenced before the preset proportion to obtain the first gray value.

Further, the element detection module may include:

a pixel number counting unit, configured to count the number of pixels with the second gray scale value in each pixel row in the second binarized image respectively;

a target pixel row determining unit, configured to determine a target pixel row for which the number of pixels of the second gray scale value is greater than a preset number threshold;

the first element determining unit is used for determining that the bill to be tested has elements if the number of the target pixel lines exceeds a preset line number threshold;

and the second element determining unit is used for determining that the bill to be tested has no element if the number of the target pixel rows does not exceed the row number threshold.

Further, the apparatus for detecting a form element may further include:

the black cap operation processing module is used for executing black cap operation processing of the image on the original gray level image;

the transverse line detection module is used for detecting whether the original gray level image after the black cap operation processing has a transverse line;

and the transverse line removing module is used for executing transverse line removing processing on the original gray level image after the black cap operation processing if the transverse line exists.

The embodiment of the present application further provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of any one of the methods for detecting a ticket element as shown in fig. 1 to 4 when executing the computer program.

An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the steps of any one of the methods for detecting a ticket element as shown in fig. 1 to 4.

The embodiment of the present application further provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the steps of implementing any one of the methods for detecting a ticket element as shown in fig. 1 to 4.

Fig. 7 is a schematic diagram of a terminal device according to an embodiment of the present application. As shown in fig. 7, the terminal device 7 of this embodiment includes: a processor 70, a memory 71 and a computer program 72 stored in said memory 71 and executable on said processor 70. The processor 70, when executing the computer program 72, implements the steps in the embodiments of the methods of detecting a form element described above, such as the steps 101 to 105 shown in fig. 1. Alternatively, the processor 70, when executing the computer program 72, implements the functions of each module/unit in the above-mentioned device embodiments, such as the functions of the modules 601 to 605 shown in fig. 6.

The computer program 72 may be divided into one or more modules/units, which are stored in the memory 71 and executed by the processor 70 to accomplish the present application. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 72 in the terminal device 7.

The Processor 70 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.

The memory 71 may be an internal storage unit of the terminal device 7, such as a hard disk or a memory of the terminal device 7. The memory 71 may also be an external storage device of the terminal device 7, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the terminal device 7. Further, the memory 71 may also include both an internal storage unit and an external storage device of the terminal device 7. The memory 71 is used for storing the computer program and other programs and data required by the terminal device. The memory 71 may also be used to temporarily store data that has been output or is to be output.

It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.

It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.

In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.

Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.

In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described system embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.

The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.

In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.

The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow in the method of the embodiments described above can be realized by a computer program, which can be stored in a computer-readable storage medium and can realize the steps of the embodiments of the methods described above when the computer program is executed by a processor. . Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain other components which may be suitably increased or decreased as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media which may not include electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.

The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

25页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种多面值、多币种的外汇货币配钞装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!