HK1249645B - A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium - Google Patents
A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium Download PDFInfo
- Publication number
- HK1249645B HK1249645B HK18108029.8A HK18108029A HK1249645B HK 1249645 B HK1249645 B HK 1249645B HK 18108029 A HK18108029 A HK 18108029A HK 1249645 B HK1249645 B HK 1249645B
- Authority
- HK
- Hong Kong
- Prior art keywords
- value
- tilt
- image
- obtaining
- values
- Prior art date
Links
Landscapes
- Character Input (AREA)
Description
技术领域Technical Field
本发明涉及图像处理领域,尤其涉及一种倾斜图像的倾斜值获取方法、装置、终端及存储介质。The present invention relates to the field of image processing, and in particular to a method, device, terminal and storage medium for obtaining a tilt value of a tilted image.
背景技术Background Art
目前,当矩形图像发生倾斜时,如要获取其倾斜值,可以通过霍夫线段检测算法检测提取该图像的边界线,但是由于矩形图像包括沿图像的长度方向和宽度方向的边界线,再加上一些矩形图像的边界不够分明,使得同一边界上会提取出多个线段,以及还有一些矩形图像的背景不够纯净,携带有杂质线段,这样,就会导致采用霍夫线段检测算法会检测出很多条边界线。边界线不同,通常情况下斜率值也会互不相同,即使是从矩形图像的同一边界上提取的多个线段的斜率值也会有一些差异,从而使得图像的倾斜值不能唯一确定。At present, when a rectangular image is tilted, if you want to obtain its tilt value, you can use the Hough line segment detection algorithm to detect and extract the boundary lines of the image. However, since the rectangular image includes boundary lines along the length and width directions of the image, and the boundaries of some rectangular images are not clear enough, multiple line segments will be extracted on the same boundary, and the background of some rectangular images is not pure enough, and there are impurity line segments. In this way, the Hough line segment detection algorithm will detect many boundary lines. Different boundary lines usually have different slope values. Even the slope values of multiple line segments extracted from the same boundary of a rectangular image will have some differences, so that the tilt value of the image cannot be uniquely determined.
发明内容Summary of the invention
为克服现有技术中图像的倾斜值不能唯一确定的问题,本发明实施例倾斜图像的倾斜值获取方法、装置、终端及存储介质。In order to overcome the problem in the prior art that the tilt value of an image cannot be uniquely determined, embodiments of the present invention provide a method, device, terminal and storage medium for obtaining the tilt value of a tilted image.
第一方面,本发明实施例提供了一种倾斜图像的倾斜值获取方法,所述倾斜图像为矩形,所述倾斜值获取方法包括:In a first aspect, an embodiment of the present invention provides a method for obtaining a tilt value of a tilted image, wherein the tilted image is a rectangle, and the method for obtaining a tilt value includes:
解析所述倾斜图像,获取所述倾斜图像的多个边界线的坐标信息;Analyzing the oblique image to obtain coordinate information of a plurality of boundary lines of the oblique image;
根据各个坐标信息,获取各个所述边界线的第一倾斜值;According to each coordinate information, obtaining a first tilt value of each boundary line;
获取校准值;Get calibration value;
分别计算各个所述第一倾斜值与所述校准值的差值;respectively calculating the difference between each of the first tilt values and the calibration value;
将最小差值对应的第一倾斜值确定为所述倾斜图像的倾斜值。The first tilt value corresponding to the minimum difference is determined as the tilt value of the tilt image.
优选地,所述解析所述倾斜图像,获取所述倾斜图像的多个边界线的坐标信息,包括:Preferably, the analyzing the oblique image to obtain coordinate information of a plurality of boundary lines of the oblique image includes:
对所述倾斜图像进行二值化处理,得到二值化图像;Binarizing the oblique image to obtain a binary image;
基于霍夫线段检测算法对所述二值化图像进行检测,得到多个所述边界线的坐标信息。The binary image is detected based on the Hough line segment detection algorithm to obtain coordinate information of the plurality of boundary lines.
优选地所述倾斜图像为身份证图像;所述获取校准值,包括:Preferably, the tilted image is an ID card image; and obtaining the calibration value includes:
解析身份证图像,提取所有的单字符区域,所述单字符区域为包含单个字符的仿射不变区域;Parsing the ID card image and extracting all single-character regions, wherein the single-character region is an affine invariant region containing a single character;
对所有的单字符区域进行分组,得到多个单字符区域组;其中,所述单字符区域组中任意相邻的两个单字符区域之间的距离小于第一预设阈值;Grouping all the single-character regions to obtain a plurality of single-character region groups; wherein the distance between any two adjacent single-character regions in the single-character region group is less than a first preset threshold;
获取长度最大的单字符区域组;Get the single-character region group with the longest length;
获取长度最大的单字符区域组的首尾两个单字符区域的连接线段的倾斜值,并将所述连接线段的倾斜值确定为校准值。Obtain the inclination value of the connecting line segment of the first and last two single-character regions of the single-character region group with the longest length, and determine the inclination value of the connecting line segment as the calibration value.
优选地,所述对所有的单字符区域进行分组,得到多个单字符区域组,包括:Preferably, the step of grouping all the single-character regions to obtain a plurality of single-character region groups includes:
获取第一单字符区域;Get the first single character area;
获取与所述第一单字符区域的距离小于所述第一预设阈值的所有第二字单字符区域;Acquire all second-word single-character regions whose distances from the first single-character region are less than the first preset threshold;
直至获取与第n-1单字符区域的距离小于所述第一预设阈值的所有的第n字单字符区域;其中,n大于2,且所述第一单字符区域、所述第二单字符区域直至所述第n单字符区域不相同;until all n-th single-character regions whose distances from the n-1-th single-character region are less than the first preset threshold are obtained; wherein n is greater than 2, and the first single-character region, the second single-character region, and the n-th single-character region are different;
将所述第一单字符区域、所有的所述第二单字符区域直至所有的所述第n单字符区域确定为单字符区域组。优选地,所述倾斜图像包括按序排列的多个元素,多个元素的排序方向与所述倾斜图像的长度方向或宽度方向相同;The first single character region, all the second single character regions, and up to all the nth single character regions are determined as a single character region group. Preferably, the oblique image includes a plurality of elements arranged in sequence, and the ordering direction of the plurality of elements is the same as the length direction or the width direction of the oblique image;
所述获取校准值,包括:The obtaining of the calibration value comprises:
解析所述倾斜图像,提取多个元素区域,所述元素区域为包含单个元素的区域;Analyze the oblique image to extract multiple element regions, where the element region is a region containing a single element;
确定相邻的两个元素区域;Determine the adjacent area of two elements;
获取所有的第二倾斜值,所述第二倾斜值为连接相邻的两个元素区域的直线的倾斜值;Obtain all second tilt values, where the second tilt value is a tilt value of a straight line connecting two adjacent element regions;
对所有的所述第二倾斜值进行分析计算,得到所述校准值。All the second tilt values are analyzed and calculated to obtain the calibration value.
优选地,所述对所有的所述第二倾斜值进行分析计算,得到所述校准值,包括:Preferably, analyzing and calculating all the second tilt values to obtain the calibration value includes:
对所有的所述第二倾斜值进行聚类,得到多个倾斜值簇;Clustering all the second tilt values to obtain multiple tilt value clusters;
获取权重最大的倾斜值簇;Get the tilt value cluster with the largest weight;
计算权重最大的倾斜值簇的均值,得到所述校准值。The mean of the tilt value cluster with the largest weight is calculated to obtain the calibration value.
优选地,所述解析倾斜图像,提取多个元素区域,包括:Preferably, the analyzing the oblique image and extracting multiple element regions comprises:
解析倾斜图像,提取所有的最大稳定极值区域;Analyze the oblique image and extract all the maximum stable extreme value areas;
从所有的最大稳定极值区域中滤除非元素区域,得到多个所述元素区域。Non-element regions are filtered out from all maximum stable extreme value regions to obtain a plurality of element regions.
第二方面,本发明实施例提供一种倾斜图像的倾斜值获取装置,所述倾斜图像为矩形,所述倾斜值获取装置包括:In a second aspect, an embodiment of the present invention provides a device for obtaining a tilt value of a tilted image, wherein the tilted image is a rectangle, and the device for obtaining a tilt value comprises:
解析模块,用于解析所述倾斜图像,获取所述倾斜图像的多个边界线的坐标信息;A parsing module, used for parsing the oblique image and obtaining coordinate information of a plurality of boundary lines of the oblique image;
第一倾斜值获取模块,用于分别对各个坐标信息进行分析计算,得到各个所述边界线的第一倾斜值;A first tilt value acquisition module, used to analyze and calculate each coordinate information respectively to obtain a first tilt value of each boundary line;
校准值获取模块,用于获取校准值;A calibration value acquisition module, used for acquiring a calibration value;
差值计算模块,用于分别计算各个所述第一倾斜值与所述校准值的差值,以获得最小差值;A difference calculation module, used for respectively calculating the difference between each of the first tilt values and the calibration value to obtain a minimum difference;
确定模块,用于将所述最小差值对应的第一倾斜值确定为所述倾斜图像的倾斜值。A determination module is used to determine a first tilt value corresponding to the minimum difference as the tilt value of the tilt image.
第三方面,本发明实施例提供了一种终端,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述任一项所述的倾斜图像的倾斜值获取方法。In a third aspect, an embodiment of the present invention provides a terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements any of the above-mentioned methods for obtaining the tilt value of the tilted image when executing the computer program.
第四方面,本发明实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述任一项所述的倾斜图像的倾斜值获取方法。In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for obtaining the tilt value of the tilted image described in any one of the above items is implemented.
本发明实施例通过获取校准值,并将提取的各边界线的第一倾斜值与校准值一一比较,最后将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值,从而使得倾斜图像的倾斜值唯一确定。The embodiment of the present invention obtains the calibration value, compares the first tilt value of each extracted boundary line with the calibration value one by one, and finally determines the first tilt value corresponding to the minimum difference as the tilt value of the tilt image, so that the tilt value of the tilt image is uniquely determined.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
图1是本发明的倾斜图像的倾斜值获取方法的第一实施例的流程示意图;FIG1 is a schematic flow chart of a first embodiment of a method for obtaining a tilt value of a tilted image according to the present invention;
图2是本发明的倾斜图像的倾斜值获取方法的第二实施例的流程示意图;FIG2 is a schematic flow chart of a second embodiment of a method for obtaining a tilt value of a tilted image according to the present invention;
图3是本发明的校准值获取方式的实施例的流程示意图;FIG3 is a schematic flow chart of an embodiment of a calibration value acquisition method of the present invention;
图4是本发明的校准值获取方式的另一实施例的流程示意图;FIG4 is a flow chart of another embodiment of a calibration value acquisition method of the present invention;
图5是本发明的倾斜图像的倾斜值获取装置的实施例的结构示意图。FIG. 5 is a schematic structural diagram of an embodiment of a device for acquiring a tilt value of a tilted image according to the present invention.
具体实施方式DETAILED DESCRIPTION
为了使本发明所解决的技术问题、技术方案及有益效果更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the technical problems, technical solutions and beneficial effects solved by the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
请参照图1,是本发明的倾斜图像的倾斜值获取方法的第一实施例的流程示意图。该方法包括:Please refer to FIG1 , which is a flow chart of a first embodiment of a method for obtaining a tilt value of a tilted image according to the present invention. The method comprises:
步骤101,解析倾斜图像,获取倾斜图像的多个边界线的坐标信息。本步骤具体可以为对倾斜图像进行二值化处理,得到二值化图像,即黑白图像;基于霍夫线段检测算法对二值化图像进行检测,得到多个边界线的坐标信息。其中,坐标信息可以为边界线在平面直角坐标系(x,y)中的斜率和截距,也可以为边界线在其参数平面(k,b)所对应的点的坐标。Step 101, parse the oblique image and obtain the coordinate information of multiple boundary lines of the oblique image. This step can be specifically performed by binarizing the oblique image to obtain a binary image, that is, a black and white image; the binary image is detected based on the Hough line segment detection algorithm to obtain the coordinate information of multiple boundary lines. The coordinate information can be the slope and intercept of the boundary line in the plane rectangular coordinate system (x, y), or the coordinates of the point corresponding to the boundary line in its parameter plane (k, b).
倾斜图像的二值化处理是将倾斜图像中像素点的灰度值设置为第一数值或第二数值,也就是将整个倾斜图像呈现出明显的只有黑和白的视觉效果。而对倾斜图像的二值化处理方式有双峰法、迭代法、P参数法等,除去列出来的几种二值化处理方式,还有很多其他二值化处理的方式,本公开实施例对此不再一一列举。而关于二值化处理方式的详细步骤可以参考相关技术,本实施例对此不作具体阐述。需要说明的是,第一数值和第二数值可以事先设置,且第一数值大于第二数值,比如,第一数值可以为255、254、253等等,第二数值可以为0、1、2等等,而为了能够更精确地获取到倾斜图像中待检测直线(即边界线)的轮廓,进而提高直线检测的准确度,第一数值可以为255,以及第二数值可以为0,本实施例对此不作具体限定。The binarization of the oblique image is to set the gray value of the pixel in the oblique image to the first value or the second value, that is, to present the entire oblique image with an obvious visual effect of only black and white. The binarization methods for the oblique image include the bimodal method, the iterative method, the P parameter method, etc. In addition to the listed binarization methods, there are many other binarization methods, which are not listed one by one in the disclosed embodiment. The detailed steps of the binarization method can refer to the relevant technology, and this embodiment is not specifically described. It should be noted that the first value and the second value can be set in advance, and the first value is greater than the second value. For example, the first value can be 255, 254, 253, etc., and the second value can be 0, 1, 2, etc. In order to more accurately obtain the contour of the straight line (i.e., the boundary line) to be detected in the oblique image, thereby improving the accuracy of the straight line detection, the first value can be 255, and the second value can be 0, which is not specifically limited in this embodiment.
在基于霍夫线段检测算法对二值化图像进行检测之前,需要获取二值化图像中各个像素点的灰度值,基于获取的各个像素点的灰度值,从该二值化图像区域中选择灰度值为第一数值的像素点,进而确定选择的像素点的像素点坐标。Before detecting a binary image based on the Hough line segment detection algorithm, it is necessary to obtain the grayscale value of each pixel in the binary image, and based on the obtained grayscale value of each pixel, select a pixel whose grayscale value is a first value from the binary image area, and then determine the pixel coordinates of the selected pixel.
在平面直角坐标系(x,y)中,一条直线可以用方程y=kx+b来表示。对于直线上一个确定的点(x0,y0),有y0=k x0+b,这表示参数平面(k,b)中的一条直线。因此,二值化图像中的一个像素点对应其参数平面中的一条直线,二值化图像中的一条直线对应参数平面中的一个点。因此,本步骤可以对二值化图像上所有的灰度值为第一数值的像素点作霍夫变换,得到各个像素点在参数平面所对应的直线;并且确定参数平面中多条直线的相交点的坐标,统计相交点对应的相交直线的数目,将相交直线的数目超过预设数目的相交点确定为各个边界线在参数平面对应的点,以及将相交点的坐标信息确定为边界点的坐标信息。具体地,相交点的坐标(k,b)即为边界线的斜率和截距。In a plane rectangular coordinate system (x, y), a straight line can be represented by the equation y=kx+b. For a certain point (x0, y0) on the straight line, y0=kx0+b, which represents a straight line in the parameter plane (k, b). Therefore, a pixel point in the binary image corresponds to a straight line in its parameter plane, and a straight line in the binary image corresponds to a point in the parameter plane. Therefore, this step can perform Hough transform on all pixel points with grayscale values of the first value on the binary image to obtain the straight line corresponding to each pixel point in the parameter plane; and determine the coordinates of the intersection points of multiple straight lines in the parameter plane, count the number of intersection lines corresponding to the intersection points, determine the intersection points whose number of intersection lines exceeds a preset number as the points corresponding to each boundary line in the parameter plane, and determine the coordinate information of the intersection points as the coordinate information of the boundary points. Specifically, the coordinates (k, b) of the intersection points are the slope and intercept of the boundary line.
步骤102,根据各个坐标信息,获取各个边界线的第一倾斜值。第一倾斜值可以为倾斜角度或斜率。具体地,当第一倾斜值为斜率时,可以从各个边界线的坐标信息中提取出各个边界线的斜率;当第一倾斜值为倾斜角度时,可以从各个边界线的坐标信息中提取出各个边界线的斜率k,并对斜率进行计算得到倾斜角度为arctank。Step 102, according to each coordinate information, obtain the first tilt value of each boundary line. The first tilt value can be a tilt angle or a slope. Specifically, when the first tilt value is a slope, the slope of each boundary line can be extracted from the coordinate information of each boundary line; when the first tilt value is a tilt angle, the slope k of each boundary line can be extracted from the coordinate information of each boundary line, and the slope is calculated to obtain the tilt angle arctank.
步骤103,获取校准值。校准值用于对提取的各个边界线的第一倾斜值进行过滤或筛选,从中得到唯一的倾斜图像的倾斜值。校准值的获取方式包括多种。Step 103, obtaining a calibration value. The calibration value is used to filter or screen the first tilt values of each extracted boundary line, thereby obtaining a unique tilt value of the tilted image. There are many ways to obtain the calibration value.
第一种方式,当倾斜图像为长方形时,可以对获取的多个第一倾斜值进行聚类,得到两个簇,每个簇的方差都小于预设方差值;然后分别计算各个簇中各第一倾斜值对应线段的长度和;确定上述获取的两个长度和中的最大值或最小值,并将最大值或最小值对应的簇的均值作为校准值。通常情况下会提取出两类边界线:一类是与倾斜图像的长度方向大致平行的边界线,另一类是与宽度方向大致平行的边界线;并且与长度方向大致平行的所有边界线的长度之和是大于与宽度方向上大致平行的所有边界线的宽度之和,因此,通过将最大值或最小值对应的簇的均值作为校准值,便可以确定校准值所对应的直线方向,该直线方向大致平行于倾斜图像的长度方向或宽度方向。若将最大值对应的簇的均值作为校准值,那么步骤105中获取的倾斜值所对应的倾斜方向即为倾斜图像的长度方向;若将最小值对应的簇的均值作为校准值,那么步骤105中获取的倾斜值所对应的倾斜方向即为倾斜图像的宽度方向。In the first method, when the oblique image is a rectangle, the obtained multiple first oblique values can be clustered to obtain two clusters, and the variance of each cluster is less than the preset variance value; then the sum of the lengths of the line segments corresponding to the first oblique values in each cluster is calculated respectively; the maximum or minimum value of the two length sums obtained above is determined, and the mean of the cluster corresponding to the maximum or minimum value is used as the calibration value. Usually, two types of boundary lines are extracted: one is the boundary lines roughly parallel to the length direction of the oblique image, and the other is the boundary lines roughly parallel to the width direction; and the sum of the lengths of all boundary lines roughly parallel to the length direction is greater than the sum of the widths of all boundary lines roughly parallel to the width direction. Therefore, by using the mean of the cluster corresponding to the maximum or minimum value as the calibration value, the direction of the straight line corresponding to the calibration value can be determined, and the straight line direction is roughly parallel to the length direction or the width direction of the oblique image. If the mean of the cluster corresponding to the maximum value is used as the calibration value, then the tilt direction corresponding to the tilt value obtained in step 105 is the length direction of the tilted image; if the mean of the cluster corresponding to the minimum value is used as the calibration value, then the tilt direction corresponding to the tilt value obtained in step 105 is the width direction of the tilted image.
第二种方式,若倾斜图像包括按序排列的多个元素,且多个元素的排序方向与矩形的倾斜图像的长度方向或宽度方向相同,则可以解析倾斜图像,提取多个元素区域,其中,元素区域为倾斜图像中包含单个元素的区域;确定相邻的两个元素区域;获取所有的第二倾斜值,第二倾斜值为连接相邻的两个元素区域的直线的倾斜值;对所有的第二倾斜值进行分析计算,得到校准值。The second method is that if the oblique image includes multiple elements arranged in order, and the ordering direction of the multiple elements is the same as the length direction or the width direction of the rectangular oblique image, the oblique image can be parsed to extract multiple element regions, wherein the element region is a region containing a single element in the oblique image; two adjacent element regions are determined; all second inclination values are obtained, and the second inclination value is the inclination value of a straight line connecting two adjacent element regions; all second inclination values are analyzed and calculated to obtain calibration values.
采用第二种方式获取校准值的方法会在下文中作详细介绍,故在此不作赘述。The method of obtaining the calibration value using the second method will be described in detail below, so it will not be described here.
第三种方式,若倾斜图像为身份证的拍摄图像,倾斜图像包含多个字符,则可以解析倾斜图像,提取多个字符区域,其中,字符区域为包含字符的仿射不变区域;确定所有相邻的两个字符区域,其中,相邻的两个字符区域之间的距离小于预设距离值,预设距离值小于或等于字符的最小行间距;获取所有的第二倾斜值,第二倾斜值为连接相邻的两个字符区域的直线的倾斜值;对所有的第二倾斜值求均值,得到校准值。由于身份证上住址信息和号码信息分别对应的字符串之间的列间距均小于身份证上字符的最小行间距,因此,连接任意相邻的两个字符区域的直线均与倾斜图像的长度方向大致平行,从而使得校准值对应的倾斜方向即为倾斜图像的长度方向。其中,解析倾斜图像,提取多个字符区域与解析倾斜图像,提取多个元素区域的方法相同,具体见图3所示的实施例,在此不作赘述。The third method is that if the oblique image is a photograph of an ID card, and the oblique image contains multiple characters, the oblique image can be parsed to extract multiple character regions, wherein the character region is an affine invariant region containing characters; determine all two adjacent character regions, wherein the distance between the two adjacent character regions is less than a preset distance value, and the preset distance value is less than or equal to the minimum line spacing of the characters; obtain all second inclination values, wherein the second inclination value is the inclination value of the straight line connecting the two adjacent character regions; average all the second inclination values to obtain the calibration value. Since the column spacing between the character strings corresponding to the address information and the number information on the ID card is less than the minimum line spacing of the characters on the ID card, the straight line connecting any two adjacent character regions is roughly parallel to the length direction of the oblique image, so that the inclination direction corresponding to the calibration value is the length direction of the oblique image. Among them, the method of parsing the oblique image and extracting multiple character regions is the same as the method of parsing the oblique image and extracting multiple element regions, which is specifically shown in the embodiment shown in Figure 3 and will not be repeated here.
第四种方式,若倾斜图像为身份证的拍摄图像,则解析身份证图像,提取所有的单字符区域,单字符区域为包含单个字符的仿射不变区域;对所有的单字符区域进行分组,得到多个单字符区域组;其中,单字符区域组中任意相邻的两个单字符区域之间的距离小于第一预设阈值;获取长度最大的单字符区域组;获取长度最大的单字符区域组的首尾两个单字符区域的连接线段的倾斜值,并将连接线段的倾斜值确定校准值。The fourth method is, if the inclined image is a photograph of an ID card, then the ID card image is parsed to extract all single-character areas, where the single-character area is an affine invariant area containing a single character; all single-character areas are grouped to obtain multiple single-character area groups; wherein the distance between any two adjacent single-character areas in the single-character area group is less than a first preset threshold; the single-character area group with the largest length is obtained; the inclination value of the connecting line segment of the first and last two single-character areas of the single-character area group with the largest length is obtained, and the inclination value of the connecting line segment is determined as a calibration value.
步骤104,分别计算各个第一倾斜值与校准值的差值,以得到最小差值。Step 104 , respectively calculating the difference between each first tilt value and the calibration value to obtain a minimum difference.
步骤105,将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值。Step 105: determine the first tilt value corresponding to the minimum difference as the tilt value of the tilt image.
本发明实施例通过获取校准值,并将提取的各边界线的第一倾斜值与校准值一一比较,最后将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值,从而使得倾斜图像的倾斜值唯一确定。The embodiment of the present invention obtains the calibration value, compares the first tilt value of each extracted boundary line with the calibration value one by one, and finally determines the first tilt value corresponding to the minimum difference as the tilt value of the tilt image, so that the tilt value of the tilt image is uniquely determined.
请参照图2,是本发明的倾斜图像的倾斜值获取方法的第二实施例的流程示意图。本实施例中,倾斜图像来自于倾斜证件的拍摄图像。该方法包括:Please refer to FIG. 2, which is a flow chart of a second embodiment of a method for obtaining a tilt value of a tilted image of the present invention. In this embodiment, the tilted image comes from a photographed image of a tilted document. The method includes:
步骤201,获取倾斜证件的拍摄图像,其中,拍摄图像包括背景图像和倾斜图像。倾斜证件具体可以为身份证、社保卡或银行卡等。Step 201, obtaining a photographed image of a tilted document, wherein the photographed image includes a background image and a tilted image. The tilted document may be an identity card, a social security card, or a bank card.
步骤202,解析拍摄图像,去除所述背景图像,得到倾斜图像。具体地,可以获取预设倾斜图像的特征信息,该特征信息具体可以为形状特征或颜色亮度特征;在拍摄图像中查找与该特征信息相匹配的图像区域;将拍摄图像中该图像区域之外的区域(即背景图像)去除,从而得到倾斜图像。Step 202: parse the captured image, remove the background image, and obtain an oblique image. Specifically, feature information of a preset oblique image may be obtained, and the feature information may be a shape feature or a color brightness feature; search for an image region matching the feature information in the captured image; and remove the region outside the image region (i.e., the background image) in the captured image, thereby obtaining an oblique image.
步骤203,判断倾斜图像的尺寸是否大于倾斜证件的尺寸。Step 203, determining whether the size of the tilted image is larger than the size of the tilted document.
步骤204,若倾斜图像的尺寸大于倾斜证件的尺寸,则将倾斜图像的尺寸设置为倾斜证件的尺寸。若倾斜图像的尺寸小于或等于倾斜证件的尺寸,则不对倾斜图像的尺寸进行设置。Step 204: If the size of the tilted image is larger than the size of the tilted document, the size of the tilted image is set to the size of the tilted document. If the size of the tilted image is smaller than or equal to the size of the tilted document, the size of the tilted image is not set.
步骤205,解析倾斜图像,获取倾斜图像的多个边界线的坐标信息。本步骤具体可以为对倾斜图像进行二值化处理,得到二值化图像;基于霍夫线段检测算法对二值化图像进行检测,得到多个边界线的坐标信息。其中,坐标信息可以为边界线两个端点的坐标信息。Step 205, parse the oblique image to obtain coordinate information of multiple boundary lines of the oblique image. This step can specifically be to perform binarization processing on the oblique image to obtain a binary image; and to detect the binary image based on the Hough line segment detection algorithm to obtain coordinate information of multiple boundary lines. The coordinate information can be the coordinate information of the two endpoints of the boundary line.
步骤206,分别对各个坐标信息进行分析计算,得到各个边界线的第一倾斜值。第一倾斜值可以为倾斜角度或斜率。Step 206: Analyze and calculate each coordinate information to obtain a first tilt value of each boundary line. The first tilt value may be a tilt angle or a slope.
步骤207,获取校准值。校准值的获取方法也在上文中做了详细介绍,故在不作赘述。Step 207: Acquire the calibration value. The method for acquiring the calibration value has been described in detail above, so it will not be described in detail here.
步骤208,分别计算各个第一倾斜值与校准值的差值。Step 208: Calculate the difference between each first tilt value and the calibration value.
步骤209,将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值。Step 209: determine the first tilt value corresponding to the minimum difference as the tilt value of the tilt image.
由于倾斜图像是基于倾斜证件的拍摄图像得到的,因此,倾斜图像的尺寸会与倾斜证件的尺寸有偏差,而在边界线提取的过程中,倾斜图像的尺寸越大,边界线越不容易提取,因此,本发明实施例通过在倾斜图像的尺寸大于倾斜证件的尺寸时,将倾斜图像的尺寸设置为倾斜证件的尺寸,从而保证了倾斜图像不会过大,进而不会影响到边界线的提取。Since the tilted image is obtained based on the photographed image of the tilted document, the size of the tilted image will deviate from the size of the tilted document. In the process of boundary line extraction, the larger the size of the tilted image, the more difficult it is to extract the boundary line. Therefore, the embodiment of the present invention sets the size of the tilted image to the size of the tilted document when the size of the tilted image is larger than the size of the tilted document, thereby ensuring that the tilted image is not too large and will not affect the extraction of the boundary line.
请参照图3,是本发明的校准值获取方式的实施例的流程示意图。本实施例对校准值获取的第二种方式进行详细的介绍。其中,倾斜图像包括按序排列的多个元素,且多个元素的排序方向与矩形的倾斜图像的长度方向或宽度方向相同。校准值获取方式具体包括:Please refer to FIG. 3, which is a flow chart of an embodiment of the calibration value acquisition method of the present invention. This embodiment introduces the second method of obtaining the calibration value in detail. Among them, the oblique image includes multiple elements arranged in order, and the ordering direction of the multiple elements is the same as the length direction or width direction of the rectangular oblique image. The calibration value acquisition method specifically includes:
步骤301,解析倾斜图像,提取多个元素区域,其中,元素区域为包含元素的仿射不变区域。步骤301包括:Step 301, analyzing the oblique image, extracting multiple element regions, wherein the element region is an affine invariant region containing elements. Step 301 includes:
301a,解析倾斜图像,提取所有的最大稳定极值区域。最大稳定极值区域是当使用不同的灰度阈值对倾斜图像进行二值化处理时得到的最稳定的区域。具体地,本步骤包括:获取预设数目的灰度阈值,分别采用每个灰度阈值对倾斜图像进行二值化处理,得到各个灰度阈值对应的二值化图像;获取在预设灰度阈值范围对应的各个二值化图像中均保持形状稳定的区域,得到最大稳定极值区域。301a, analyze the oblique image and extract all maximum stable extreme value regions. The maximum stable extreme value region is the most stable region obtained when the oblique image is binarized using different grayscale thresholds. Specifically, this step includes: obtaining a preset number of grayscale thresholds, using each grayscale threshold to binarize the oblique image, and obtaining a binarized image corresponding to each grayscale threshold; obtaining a region that maintains a stable shape in each binarized image corresponding to a preset grayscale threshold range, and obtaining a maximum stable extreme value region.
301b,确定各个最大稳定极值区域的矩形边界。具体地,本步骤包括:确定最大稳定极值区域的轮廓;根据确定的轮廓,得到该轮廓的最小外接矩形,从而得到该最大稳定极值区域的矩形边界。其中,最小外接矩形是指以二维坐标表示的二维形状的最大范围,即以给定的二维形状各顶点中的最大横坐标、最小横坐标、最大纵坐标、最小纵坐标定下边界的矩形。301b, determine the rectangular boundaries of each maximum stable extremum region. Specifically, this step includes: determining the outline of the maximum stable extremum region; according to the determined outline, obtaining the minimum circumscribed rectangle of the outline, thereby obtaining the rectangular boundary of the maximum stable extremum region. Among them, the minimum circumscribed rectangle refers to the maximum range of the two-dimensional shape represented by two-dimensional coordinates, that is, the rectangle whose lower boundary is determined by the maximum horizontal coordinate, the minimum horizontal coordinate, the maximum vertical coordinate, and the minimum vertical coordinate of each vertex of the given two-dimensional shape.
301c,从所有的最大稳定极值区域中滤除非元素区域,得到多个元素区域,其中,非元素区域具体为第一矩形边界对应的最大稳定极值区域,元素区域为包含单个元素的区域。由于提取出来的所有最大稳定极值区域中会包括多个非元素区域,因此,需要将其滤除,以免对后续步骤的实施造成干扰,最终使得获取到校准值误差过大。由于各个最大稳定极值区域是不规则的区域,不便于计算其中心点,也不便于对非元素区域的去除,因此需要为各最大稳定极值区域确定一个外接的矩形边界,以便于对元素区域的中心点的计算。301c, filter out non-element regions from all maximum stable extreme value regions to obtain multiple element regions, wherein the non-element region is specifically the maximum stable extreme value region corresponding to the first rectangular boundary, and the element region is a region containing a single element. Since all the extracted maximum stable extreme value regions will include multiple non-element regions, they need to be filtered out to avoid interfering with the implementation of subsequent steps, which ultimately results in too large an error in the calibration value. Since each maximum stable extreme value region is an irregular region, it is not convenient to calculate its center point, nor is it convenient to remove the non-element region. Therefore, it is necessary to determine an external rectangular boundary for each maximum stable extreme value region to facilitate the calculation of the center point of the element region.
其中,301c具体为:检测是否存在第一矩形边界。第一矩形边界为位于其它矩形边界的内部的矩形边界、面积大于第二预设阈值的矩形边界、或长宽比大于第三预设阈值的矩形边界;若检测存在第一矩形边界,则从所有的最大稳定极值区域中将第一矩形边界对应的最大稳定极值区域滤除。若倾斜图像为身份证图像,第二预设阈值可以为倾斜图像的面积的四分之一,若元素为字符,那么第三预设阈值可以为1.5。Specifically, 301c is as follows: detecting whether there is a first rectangular boundary. The first rectangular boundary is a rectangular boundary located inside other rectangular boundaries, a rectangular boundary with an area greater than a second preset threshold, or a rectangular boundary with an aspect ratio greater than a third preset threshold; if the first rectangular boundary is detected to exist, the maximum stable extreme value region corresponding to the first rectangular boundary is filtered out from all maximum stable extreme value regions. If the oblique image is an ID card image, the second preset threshold may be one quarter of the area of the oblique image, and if the element is a character, the third preset threshold may be 1.5.
步骤302,确定相邻的两个元素区域。具体地,可以获取两个元素区域之间的距离;判断该距离是否小于第三预设阈值;若该距离小于第三预设阈值,则将两个元素区域确定为相邻的两个元素区域。作为第一种实施方式,两个元素区域之间的距离可以是两个元素区域中心点之间的距离。作为第二种实施方式,两个元素区域之间的距离是两个元素区域在预设坐标系中的横向距离和/或纵向距离。当图像中的多个元素排成多行和多列时,第三预设阈值小于元素行间距的两倍或列间距的两倍;或者第三预设阈值小于元素行间距的两倍,且小于元素列间距的两倍。确定的相邻的两个元素区域包括在元素排序方向上相邻的两个元素区域、和/或在垂直方向上相邻的两个元素区域。其中,垂直方向是与元素排序方向相垂直的方向。连接相邻的两个元素区域的直线方向(以下简称相邻方向)的数目取决于元素的行间距、列间距以及第三预设阈值。Step 302, determine two adjacent element regions. Specifically, the distance between the two element regions can be obtained; determine whether the distance is less than the third preset threshold; if the distance is less than the third preset threshold, the two element regions are determined as two adjacent element regions. As a first embodiment, the distance between the two element regions can be the distance between the center points of the two element regions. As a second embodiment, the distance between the two element regions is the horizontal distance and/or the vertical distance of the two element regions in the preset coordinate system. When multiple elements in the image are arranged in multiple rows and columns, the third preset threshold is less than twice the element row spacing or twice the column spacing; or the third preset threshold is less than twice the element row spacing and less than twice the element column spacing. The two adjacent element regions determined include two element regions adjacent in the element sorting direction, and/or two element regions adjacent in the vertical direction. Among them, the vertical direction is a direction perpendicular to the element sorting direction. The number of straight line directions connecting two adjacent element regions (hereinafter referred to as adjacent directions) depends on the element row spacing, column spacing and the third preset threshold.
步骤303,获取所有的第二倾斜值,第二倾斜值为连接相邻的两个元素区域的直线的倾斜值。相邻的两个元素区域之间的距离小于预设距离值。其中,预设距离值的大小可以根据实际需求自定义,本实施例中,预设距离值应小于元素的行间距或列间距的两倍。Step 303, obtain all second tilt values, where the second tilt value is the tilt value of the straight line connecting two adjacent element regions. The distance between two adjacent element regions is less than a preset distance value. The size of the preset distance value can be customized according to actual needs. In this embodiment, the preset distance value should be less than twice the row spacing or column spacing of the element.
步骤304,对所有的第二倾斜值进行分析计算,得到校准值。该步骤包括:304a,对所有的所述第二倾斜值进行聚类,得到多个倾斜值簇;304b,获取权重最大的倾斜值簇(即具有倾斜值的数目最多的倾斜值簇);304c,计算权重最大的倾斜值簇的均值,得到校准值。由于步骤302确定的相邻的两个元素区域包括沿倾斜图像长度方向相邻的元素区域和沿倾斜图像宽度方向相邻的元素区域,因此,通过聚类,并将权重最大的倾斜值簇的均值作为校准值,可以对校准值进行唯一确定。Step 304, analyze and calculate all the second tilt values to obtain the calibration value. This step includes: 304a, clustering all the second tilt values to obtain multiple tilt value clusters; 304b, obtaining the tilt value cluster with the largest weight (i.e., the tilt value cluster with the largest number of tilt values); 304c, calculating the mean of the tilt value cluster with the largest weight to obtain the calibration value. Since the two adjacent element regions determined in step 302 include element regions adjacent along the length direction of the tilt image and element regions adjacent along the width direction of the tilt image, the calibration value can be uniquely determined by clustering and taking the mean of the tilt value cluster with the largest weight as the calibration value.
其中,304a步骤具体为:获取预设数目;对所有的第二倾斜值进行聚类,得到预设数目的倾斜值簇;计算各个倾斜值簇的方差,得到最小方差值;判断所述最小方差值是否小于第一预设阈值;若最小方差值大于或等于第一预设阈值,则更新预设数目,返回执行对所有的第二倾斜值进行聚类,得到预设数目的倾斜值簇的步骤,直至最小方差值小于第一预设阈值。预设数目通常为2,其中更预设数目的方式为:对当前的预设数目的值加1,得到新值,并将新值赋值给预设数目。若倾斜图像为身份证的图像,那么第一预设值为200。Among them, step 304a is specifically as follows: obtain a preset number; cluster all the second tilt values to obtain a preset number of tilt value clusters; calculate the variance of each tilt value cluster to obtain a minimum variance value; determine whether the minimum variance value is less than a first preset threshold; if the minimum variance value is greater than or equal to the first preset threshold, update the preset number, return to perform the step of clustering all the second tilt values to obtain a preset number of tilt value clusters, until the minimum variance value is less than the first preset threshold. The preset number is usually 2, and the method of changing the preset number is: add 1 to the current preset number value to obtain a new value, and assign the new value to the preset number. If the tilted image is an image of an ID card, then the first preset value is 200.
具体地,对所有的倾斜值进行聚类,得到预设数目的倾斜值簇的步骤包括:从所有的倾斜值任意选择预设数目的倾斜值分别作为初始聚类中心;而对于所剩下其它倾斜值,则根据它们与这些初始聚类中心的相似度(即与初始聚类中心的距离),分别将它们分配给与其最相似的由初始聚类中心所代表的聚类簇,得到预设数目的聚类簇。Specifically, the step of clustering all the tilt values to obtain a preset number of tilt value clusters includes: arbitrarily selecting a preset number of tilt values from all the tilt values as initial cluster centers; and for the remaining tilt values, according to their similarity with these initial cluster centers (i.e., the distance from the initial cluster centers), respectively assigning them to the clusters represented by the initial cluster centers that are most similar to them, to obtain a preset number of clusters.
请参照图4,是本发明的校准值获取方式的另一实施例的流程示意图。本实施例对校准值获取的第四种方式进行详细的介绍。Please refer to Figure 4, which is a flow chart of another embodiment of the calibration value acquisition method of the present invention. This embodiment introduces the fourth calibration value acquisition method in detail.
步骤401,解析身份证图像,提取多个单字符区域。身份证图像包括多个按序排列的字符多行字符,字符可以为文字或数字。其中,单字符区域为包含单个字符的仿射不变区域。具体地,可以基于区域特征提取算法,对身份证图像中所有的仿射不变区域进行提取,并从中剔除非单字符区域(即不具有单个字符全部特征的仿射不变区域),从而得到单字符区域。Step 401, parse the ID card image and extract multiple single-character regions. The ID card image includes multiple characters and multiple lines of characters arranged in order, and the characters can be text or numbers. Among them, the single-character region is an affine invariant region containing a single character. Specifically, based on the regional feature extraction algorithm, all affine invariant regions in the ID card image can be extracted, and non-single-character regions (i.e., affine invariant regions that do not have all the features of a single character) can be eliminated therefrom to obtain a single-character region.
步骤402,获取第一单字符区域。其中,对于首次获取的单字符区域组而言,第一单字符区域可从提取的所有的单字符区域中随机选择;对于非首次获取的单字符区域组而言,第一单字符区域需要从剩余的单字符区域中随机选择。其中,剩余的单字符区域是指从所有的单字符区域中,剔除掉已经获取的单字符区域组后得到的多个单字符区域。Step 402, obtaining the first single-character region. For the first obtained single-character region group, the first single-character region can be randomly selected from all extracted single-character regions; for the non-first obtained single-character region group, the first single-character region needs to be randomly selected from the remaining single-character regions. The remaining single-character regions refer to the multiple single-character regions obtained after removing the already obtained single-character region group from all single-character regions.
步骤403,获取与第一单字符区域的距离小于第一预设阈值的所有的第二单字符区域。其中,单字符区域组中任意相邻的两个单字符区域之间的距离小于第一预设阈值。进一步地,为了尽可能将身份证图像上位于同一行的所有单字符区域均分为同一组中,任一单字符区域组中的任一单字符区域与另一单字符区域组中的任一单字符区域之间的距离大于或等于第一预设阈值。第一预设阈值已经在上文中,作了详细介绍,故在此不作赘述。Step 403, obtain all second single-character regions whose distances to the first single-character region are less than a first preset threshold. Among them, the distance between any two adjacent single-character regions in the single-character region group is less than the first preset threshold. Furthermore, in order to divide all single-character regions located in the same row on the ID card image into the same group as much as possible, the distance between any single-character region in any single-character region group and any single-character region in another single-character region group is greater than or equal to the first preset threshold. The first preset threshold has been introduced in detail above, so it will not be repeated here.
针对于同一行的单字符区域而言,位于中间的单字符区域通常会具有至少两个与之距离小于第一预设阈值的单字符区域,因此,为了得到所有的位于同一行的单字符区域,需要获取所有的第二单字符区域。For single-character regions in the same row, the single-character region in the middle usually has at least two single-character regions whose distances are less than the first preset threshold. Therefore, in order to obtain all single-character regions in the same row, it is necessary to obtain all second single-character regions.
步骤404,直至获取与第n-1单字符区域的距离小于第一预设阈值的所有的第n字单字符区域。本步骤可以理解为依次以新获取到的单字符区域为基准,获取与该基准距离小于第一预设阈值的所有的单字符区域,直至第n单字符区域。其中,n大于等于2。为了保证不重复获取单字符区域,第一单字符区域、第二单字符区域直至第n单字符区域各不相同。其中,n可以为预设定值,例如n可以为10。此外,n也可以为一个不定值,为了尽可能将身份证图像上位于同一行的所有单字符区域均分为同一组中,步骤404包括:获取与第n-1单字符区域的距离小于第一预设阈值的所有的第n字单字符区域,直至第n+1单字符区域获取失败。其中,第n+1单字符区域与第一单字符区域、第二单字符区域直至第n单字符区域各不相同。Step 404, until all the n-th single-character regions whose distance to the n-1th single-character region is less than the first preset threshold are obtained. This step can be understood as taking the newly obtained single-character region as the benchmark in turn, obtaining all the single-character regions whose distance to the benchmark is less than the first preset threshold, until the n-th single-character region. Wherein, n is greater than or equal to 2. In order to ensure that the single-character region is not repeatedly obtained, the first single-character region, the second single-character region, and the n-th single-character region are different from each other. Wherein, n can be a preset value, for example, n can be 10. In addition, n can also be an indefinite value. In order to divide all the single-character regions located in the same row on the ID card image into the same group as much as possible, step 404 includes: obtaining all the n-th single-character regions whose distance to the n-1th single-character region is less than the first preset threshold, until the acquisition of the n+1th single-character region fails. Wherein, the n+1th single-character region is different from the first single-character region, the second single-character region, and the n-th single-character region.
具体地,步骤404包括:获取与第二单字符区域的距离小于第一预设阈值的所有的第三单字符区域;获取与第三单字符区域的距离小于第一预设阈值的所有的第四单字符区域……直至获取与第n-1单字符区域的距离小于第一预设阈值的所有的第n单字符区域。在实施本步骤的过程中,由于第三单字符区域和第一字符区域与均第二字符区域的距离小于第一预设阈值,这样,就会导致获取的第三单字符区域和之前获取的第一单字符区域重复,因此,在实施步骤304中的过程,为了保证当前获取的单字符区域与之前获取的所有的单字符区域均不同,具体地,Specifically, step 404 includes: obtaining all third single-character regions whose distance from the second single-character region is less than the first preset threshold; obtaining all fourth single-character regions whose distance from the third single-character region is less than the first preset threshold... until obtaining all n-th single-character regions whose distance from the n-1-th single-character region is less than the first preset threshold. In the process of implementing this step, since the distances between the third single-character region and the first character region and the second character region are less than the first preset threshold, the third single-character region obtained will be repeated with the first single-character region obtained previously. Therefore, in the process of implementing step 304, in order to ensure that the currently obtained single-character region is different from all the previously obtained single-character regions, specifically,
具体地,在获取与第m-1单字符区域小于第一预设阈值的所有的第m单字符区域的步骤之后,可以判断新获取的第m单字符区域与之前获取的所有的单字符区域(包括所有的第一单字符区域、第二单字符区域直至第m单字符区域)是否有重合,若有重合,则结束进程,若没有重合,则执行下一步骤:以最新获取到的单字符区域为基准(即第m单字符区域),获取与该基准距离(m单字符区域)小于第一预设阈值的所有的第m+1单字符区域。其中,m小于或等于n-1。Specifically, after the step of acquiring all the m-th single-character regions whose distance from the m-1th single-character region is less than the first preset threshold, it can be determined whether the newly acquired m-th single-character region overlaps with all the previously acquired single-character regions (including all the first single-character regions, the second single-character regions up to the m-th single-character region). If there is overlap, the process is terminated. If there is no overlap, the next step is executed: taking the newly acquired single-character region as a reference (i.e., the m-th single-character region), all the m+1-th single-character regions whose distance from the reference (m single-character region) is less than the first preset threshold are acquired. Wherein, m is less than or equal to n-1.
步骤405,将第一单字符区域、第二单字符区域直至第n单字符区域确定为单字符区域组。Step 405: determine the first single-character region, the second single-character region, up to the nth single-character region as a single-character region group.
步骤406,获取长度最大的单字符区域组。该步骤具体包括:分别计算各单字符区域组的长度,并筛选出长度最大的单字符区域组。Step 406, obtaining the single-character region group with the largest length. This step specifically includes: calculating the length of each single-character region group respectively, and selecting the single-character region group with the largest length.
单字符区域组的长度计算包括:获取单字符区域组的首尾两个单字符区域的连接线段的长度;将连接线段的长度确定为该单字符区域组的长度。其中,获取单字符区域组的首尾两个单字符区域的连接线段的长度的步骤,包括:获取当前单字符区域组中任两个单字符区域之间的距离,并筛选出最大距离;将该最大距离确定为当前单字符区域组的首尾两个单字符区域的连接线段的长度。进一步地,筛选出长度最大的单字符区域组的步骤,包括:从获取的所有连接线段的长度中,筛选出最大长度,并将最大长度对应的单字符区域组确定为长度最大的单字符区域组。The length calculation of the single-character area group includes: obtaining the length of the connecting line segment of the first and last single-character areas of the single-character area group; and determining the length of the connecting line segment as the length of the single-character area group. Among them, the step of obtaining the length of the connecting line segment of the first and last single-character areas of the single-character area group includes: obtaining the distance between any two single-character areas in the current single-character area group, and filtering out the maximum distance; and determining the maximum distance as the length of the connecting line segment of the first and last single-character areas of the current single-character area group. Furthermore, the step of filtering out the single-character area group with the largest length includes: filtering out the maximum length from the lengths of all the connecting line segments obtained, and determining the single-character area group corresponding to the maximum length as the single-character area group with the largest length.
步骤407,获取长度最大的单字符区域组的首尾两个单字符区域的连接线段的倾斜值,并将连接线段的倾斜值确定为校准值。其中,连接线段是将首尾两个单字符区域各自的参照点作为端点的线段。其中,参照点具体为单字符区域的几何中心点。通过获取连接线段的两端点的坐标,即可以得到连接线段的倾斜值。倾斜值可以为倾斜角度,也可以为斜率。由于各个字符的形状不一,这就会导致提取的各单字符区域的几何中心点不能同时位于同一直线上,因此,通过获取长度最大的单字符区域组的首尾两个单字符区域的连接线段的倾斜值,可以尽量减少误差,使其接近于真实的身份证图像的倾斜值。Step 407, obtain the inclination value of the connecting line segment of the first and last single-character areas of the single-character area group with the longest length, and determine the inclination value of the connecting line segment as the calibration value. The connecting line segment is a line segment with the reference points of the first and last single-character areas as endpoints. The reference point is specifically the geometric center point of the single-character area. By obtaining the coordinates of the two endpoints of the connecting line segment, the inclination value of the connecting line segment can be obtained. The inclination value can be an inclination angle or a slope. Since the shapes of the characters are different, this will result in that the geometric center points of the extracted single-character areas cannot be located on the same straight line at the same time. Therefore, by obtaining the inclination value of the connecting line segment of the first and last single-character areas of the single-character area group with the longest length, the error can be minimized to be close to the inclination value of the real ID card image.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本发明实施例的实施过程构成任何限定。It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.
上文针对本发明的倾斜图像的倾斜值获取方法做了详细介绍,下面将相对于上述方法的装置做进一步阐述。The above is a detailed introduction to the method for obtaining the tilt value of a tilted image of the present invention. The following is a further explanation of the device for the method.
请参照图5,是本发明的倾斜图像的倾斜值获取装置的实施例的结构示意图。Please refer to FIG. 5 , which is a schematic diagram of the structure of an embodiment of a device for obtaining a tilt value of a tilted image according to the present invention.
倾斜值获取装置包括:解析模块501、第一倾斜值获取模块502、校准值获取模块503、差值计算模块504和确定模块505。The tilt value acquisition device comprises: an analysis module 501 , a first tilt value acquisition module 502 , a calibration value acquisition module 503 , a difference calculation module 504 and a determination module 505 .
解析模块501,用于解析倾斜图像,获取倾斜图像的多个边界线的坐标信息。本步骤具体可以为对倾斜图像进行二值化处理,得到二值化图像;基于霍夫线段检测算法对二值化图像进行检测,得到多个边界线的坐标信息。The analysis module 501 is used to analyze the oblique image and obtain the coordinate information of multiple boundary lines of the oblique image. This step can specifically be to perform binarization processing on the oblique image to obtain a binary image; and to detect the binary image based on the Hough line segment detection algorithm to obtain the coordinate information of multiple boundary lines.
第一倾斜值获取模块502,用于分别对各个坐标信息进行分析计算,得到各个边界线的第一倾斜值。第一倾斜值可以为倾斜角度或斜率。The first tilt value acquisition module 502 is used to analyze and calculate each coordinate information to obtain a first tilt value of each boundary line. The first tilt value can be a tilt angle or a slope.
校准值获取模块503,用于获取校准值。校准值的获取方式已在上文中作了详细介绍,故在此不作赘述。若倾斜图像包括按序排列的多个元素,且多个元素的排序方向与矩形的倾斜图像的长度方向或宽度方向相同,则校准值获取模块503包括元素提取单元、相邻元素确定单元、第二倾斜值获取单元和校准值计算单元。The calibration value acquisition module 503 is used to acquire the calibration value. The method of acquiring the calibration value has been described in detail above, so it will not be repeated here. If the oblique image includes a plurality of elements arranged in sequence, and the ordering direction of the plurality of elements is the same as the length direction or the width direction of the rectangular oblique image, then the calibration value acquisition module 503 includes an element extraction unit, an adjacent element determination unit, a second oblique value acquisition unit and a calibration value calculation unit.
其中,元素提取单元用于可以解析倾斜图像,提取多个元素区域,其中,元素区域为包含元素的仿射不变区域。相邻元素确定单元用于确定相邻的两个元素区域。第二倾斜值获取单元用于获取所有的第二倾斜值,第二倾斜值为连接相邻的两个元素区域的直线的倾斜值。校准值计算单元用于对所有的第二倾斜值进行分析计算,得到校准值。The element extraction unit is used to analyze the tilted image and extract multiple element regions, wherein the element region is an affine invariant region containing elements. The adjacent element determination unit is used to determine two adjacent element regions. The second tilt value acquisition unit is used to acquire all second tilt values, where the second tilt value is the tilt value of a straight line connecting two adjacent element regions. The calibration value calculation unit is used to analyze and calculate all second tilt values to obtain calibration values.
差值计算模块504,用于分别计算各个第一倾斜值与校准值的差值。The difference calculation module 504 is used to calculate the difference between each first tilt value and the calibration value.
确定模块505,用于将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值。The determination module 505 is configured to determine the first tilt value corresponding to the minimum difference as the tilt value of the tilt image.
本发明实施例通过获取校准值,并将提取的各边界线的第一倾斜值与校准值一一比较,最后将最小差值对应的第一倾斜值确定为倾斜图像的倾斜值,从而使得倾斜图像的倾斜值唯一确定。The embodiment of the present invention obtains the calibration value, compares the first tilt value of each extracted boundary line with the calibration value one by one, and finally determines the first tilt value corresponding to the minimum difference as the tilt value of the tilt image, so that the tilt value of the tilt image is uniquely determined.
此外,倾斜图像的倾斜值获取装置还包括拍摄图像获取模块、背景去除模块、判断模块和设置模块。拍摄图像获取模块,用于获取倾斜证件的拍摄图像,其中,拍摄图像包括背景图像和倾斜图像。倾斜证件具体可以为身份证、社保卡或银行卡等。背景去除模块,用于解析拍摄图像,去除所述背景图像,得到倾斜图像。判断模块,用于判断倾斜图像的尺寸是否大于倾斜证件的尺寸。设置模块,用于若倾斜图像的尺寸大于倾斜证件的尺寸,则将倾斜图像的尺寸设置为倾斜证件的尺寸。具体地,解析模块501用于解析设置模块设置的倾斜图像,获取倾斜图像的多个边界线的坐标信息。In addition, the device for obtaining the tilt value of the tilted image also includes a captured image acquisition module, a background removal module, a judgment module and a setting module. The captured image acquisition module is used to obtain a captured image of the tilted document, wherein the captured image includes a background image and a tilted image. The tilted document may specifically be an identity card, a social security card or a bank card, etc. The background removal module is used to parse the captured image, remove the background image, and obtain a tilted image. The judgment module is used to determine whether the size of the tilted image is larger than the size of the tilted document. The setting module is used to set the size of the tilted image to the size of the tilted document if the size of the tilted image is larger than the size of the tilted document. Specifically, the parsing module 501 is used to parse the tilted image set by the setting module to obtain the coordinate information of multiple boundary lines of the tilted image.
由于倾斜图像是基于倾斜证件的拍摄图像得到的,因此,倾斜图像的尺寸会与倾斜证件的尺寸有偏差,而在边界线提取的过程中,倾斜图像的尺寸越大,边界线越不容易提取,因此,本发明实施例通过在倾斜图像的尺寸大于倾斜证件的尺寸时,将倾斜图像的尺寸设置为倾斜证件的尺寸,从而保证了倾斜图像不会过大,进而不会影响到边界线的提取。Since the tilted image is obtained based on the photographed image of the tilted document, the size of the tilted image will deviate from the size of the tilted document. In the process of boundary line extraction, the larger the size of the tilted image, the more difficult it is to extract the boundary line. Therefore, the embodiment of the present invention sets the size of the tilted image to the size of the tilted document when the size of the tilted image is larger than the size of the tilted document, thereby ensuring that the tilted image is not too large and will not affect the extraction of the boundary line.
本发明实施例还提供一种终端,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述的倾斜图像的倾斜值获取方法。An embodiment of the present invention further provides a terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for obtaining the tilt value of the tilted image when executing the computer program.
本发明实施例还提供一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述的倾斜图像的倾斜值获取方法。An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for obtaining the tilt value of the tilted image is implemented.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)或随机存储记忆体(Random AccessMemory,RAM)等。A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
如上所述是结合具体内容提供的一种或多种实施方式,并不认定本发明的具体实施只局限于这些说明。凡与本发明的方法、结构等近似、雷同,或是对于本发明构思前提下做出若干技术推演或替换,都应当视为本发明的保护范围。As described above, one or more implementation methods are provided in combination with specific contents, and the specific implementation of the present invention is not limited to these descriptions. Any similarity or similarity with the method, structure, etc. of the present invention, or any technical deduction or replacement based on the concept of the present invention, shall be regarded as the protection scope of the present invention.
Claims (6)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| HK18108029.8A HK1249645B (en) | 2018-06-22 | 2018-06-22 | A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| HK18108029.8A HK1249645B (en) | 2018-06-22 | 2018-06-22 | A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| HK1249645A1 HK1249645A1 (en) | 2018-11-02 |
| HK1249645B true HK1249645B (en) | 2020-03-20 |
Family
ID=71408822
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| HK18108029.8A HK1249645B (en) | 2018-06-22 | 2018-06-22 | A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium |
Country Status (1)
| Country | Link |
|---|---|
| HK (1) | HK1249645B (en) |
-
2018
- 2018-06-22 HK HK18108029.8A patent/HK1249645B/en unknown
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US11074443B2 (en) | Method and device for acquiring slant value of slant image, terminal and storage medium | |
| CN112507782B (en) | Text image recognition method and device | |
| US9349062B2 (en) | Character recognition method and device | |
| CN111340023B (en) | Text recognition method and device, electronic equipment and storage medium | |
| CN110619333B (en) | Text line segmentation method, text line segmentation device and electronic equipment | |
| CN101425142B (en) | Method and device for determining page angle of slope | |
| US20140029853A1 (en) | Form recognition method and device | |
| WO2017148377A1 (en) | Automatic extraction method, device and system for driving licence expiration date, and storage medium | |
| CN110647882A (en) | Image correction method, device, equipment and storage medium | |
| WO2014026483A1 (en) | Character identification method and relevant device | |
| CN113661497A (en) | A matching method, apparatus, electronic device and computer-readable storage medium | |
| CN108446702B (en) | Image character segmentation method, device, equipment and storage medium | |
| CN110738204A (en) | Method and device for positioning certificate areas | |
| JP2019102061A (en) | Text line segmentation method | |
| JP2019102061A5 (en) | ||
| CN111222508B (en) | ROI-Based Scale Recognition Method, Device and Computer Equipment for House Type Drawings | |
| CN117612179A (en) | Method and device for recognizing characters in image, electronic equipment and storage medium | |
| CN113298079B (en) | Image processing method and device, electronic equipment and storage medium | |
| CN111914847B (en) | OCR (optical character recognition) method and system based on template matching | |
| CN108268868B (en) | Method and device for acquiring inclination value of identity card image, terminal and storage medium | |
| CN116434071A (en) | A method, device, equipment and medium for determining a regularized building mask | |
| JP4967045B2 (en) | Background discriminating apparatus, method and program | |
| CN109035285B (en) | Image boundary determining method and device, terminal and storage medium | |
| HK1249645B (en) | A method and device for acquiring an inclination value of an inclined image, a terminal and a storage medium | |
| CN108242059B (en) | Image boundary searching method and device |