WO2019019383A1 - Image correction method and apparatus, storage medium and computer device - Google Patents

Image correction method and apparatus, storage medium and computer device Download PDF

Info

Publication number
WO2019019383A1
WO2019019383A1 PCT/CN2017/104659 CN2017104659W WO2019019383A1 WO 2019019383 A1 WO2019019383 A1 WO 2019019383A1 CN 2017104659 W CN2017104659 W CN 2017104659W WO 2019019383 A1 WO2019019383 A1 WO 2019019383A1
Authority
WO
WIPO (PCT)
Prior art keywords
binary image
image
document image
tilt angle
document
Prior art date
Application number
PCT/CN2017/104659
Other languages
French (fr)
Chinese (zh)
Inventor
马向东
高雪
丁杰
李斌
陈杰
邵正铂
张捷
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019019383A1 publication Critical patent/WO2019019383A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/60Rotation of whole images or parts thereof
    • G06T3/608Rotation of whole images or parts thereof by skew deformation, e.g. two-pass or three-pass rotation

Definitions

  • the present application relates to the field of computer technology, and in particular, to an image correction method, apparatus, storage medium, and computer device.
  • the document image obtained by scanning or photographing will inevitably have the problem of being reversed or tilted, and the document image needs to be corrected.
  • the correction of the document image relies on the manual correction by the business personnel, resulting in inefficiency in correcting the document image.
  • an image correction method for solving various embodiments of the present application, an image correction method, apparatus, storage medium, and computer apparatus are provided.
  • An image correction method includes:
  • the direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  • An image correcting device comprising:
  • a processing module configured to perform binarization processing on the document image to obtain a binary image
  • a determining module configured to determine a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image; determining a position of a header in the binary image according to a size of a connected domain in the binary image; Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title;
  • the correction module is configured to perform direction correction on the document image according to the tilt angle of the document image, and obtain a document image that has undergone direction correction.
  • One or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the steps of:
  • the direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  • a computer device comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the processor to execute Next steps:
  • the direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  • FIG. 1 is a diagram showing the internal structure of a computer device in an embodiment
  • FIG. 2 is a schematic flow chart of an image correction method in an embodiment
  • FIG. 3 is a schematic diagram of a document image before and after binarization in one embodiment
  • FIG. 4 is a schematic diagram of a tilt angle of a frame in a document image in an embodiment
  • FIG. 5 is a schematic flow chart of an image correction method in another embodiment
  • Fig. 6 is a block diagram showing the structure of an image correcting device in an embodiment.
  • FIG. 1 is a schematic diagram showing the internal structure of a computer device in an embodiment.
  • the computer device includes a processor and a memory connected by a system bus.
  • the memory comprises a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium of the computer device can store an operating system and computer readable instructions that, when executed, cause the processor to perform an image correction method.
  • the processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device.
  • the internal memory can also store computer readable instructions for implementing an image correction method provided by the following embodiments when the computer readable instructions are executed by a processor.
  • FIG. 1 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the terminal to which the solution of the present application is applied.
  • the specific terminal may include a ratio. More or fewer components are shown in the figures, or some components are combined, or have different component arrangements.
  • an image correction method is provided. This embodiment is mainly illustrated by the method applied to the computer device in FIG. 1 described above. Referring to FIG. 2, the image correction method specifically includes the following steps:
  • the document image is an image containing a document, and may be a document photo or a document scan.
  • the document image to be corrected is a document image that requires direction correction.
  • the computer device can obtain a document image by photographing a physical document through a camera of the computer device, or obtain a document image by scanning a physical document by a scanner, or receiving a document image transmitted by another computer device.
  • binarization is to set the pixel points on the image to two pixel values. For example, set the gray value of the pixel on the image to 0 or 255.
  • the computer device may use a fixed threshold binarization algorithm or an adaptive threshold binarization algorithm to set pixel values above and below the threshold in the document image to one of two preset pixel values.
  • the two pixel values are the first pixel value and the second pixel value, respectively.
  • the computer device can read from the document image by calling MATLAB.
  • the RGB value of each pixel in the document image is calculated, and the gradation value of each pixel is calculated according to the RGB value of each pixel.
  • the gray value of each pixel in the document image is compared with a preset threshold, the gray value greater than the preset threshold is set to "1", and the gray value less than or equal to the preset threshold is set to "0" , binarize each pixel of the document image to obtain a binary image.
  • the border is a peripheral frame.
  • the content enclosed by the border is the content of the document.
  • the tilt angle is the angle from the standard direction.
  • the standard direction can be horizontal or vertical.
  • the tilt angle may specifically be an angle deviating from the horizontal direction, the direction is a clockwise direction, or may be an angle deviating from the vertical direction, and the direction is a counterclockwise direction.
  • the computer device can traverse the pixel values of the respective pixel points row by line, recognize the detected consecutive pixel values having the same pixel value as a straight line, and determine the straight line constituting the frame from the recognized straight lines.
  • the computer device can recalculate the angle of the line from the direction of the label, thereby obtaining the tilt angle of the frame.
  • the computer device may specifically adopt an algorithm such as a principal component analysis (PCA) algorithm or a least squares regression algorithm to obtain a tilt angle of a straight line constituting the frame.
  • PCA principal component analysis
  • Figure 3 is a diagram showing the tilt angle of the border in the document image in one embodiment.
  • the schematic shows a bezel 310 and a tilt angle 320.
  • the inclination angle 320 may be an angle 321 deviating from the horizontal direction, the direction is a clockwise direction; or may be an angle 322 deviating from the vertical direction, and the direction is a counterclockwise direction.
  • the character of the title in the document image is determined to be the largest.
  • the computer device can obtain the connected domain included in the document image, determine the size of each connected domain, and select the location of the largest connected domain as the location of the title.
  • S210 Determine a tilt angle of the document image according to the tilt angle of the border and the position of the title.
  • the computer device can determine the direction of the text sequence in the title, and determine the tilt angle of the document image based on the direction of the text sequence in the title, the position of the title in the document image, and the tilt angle of the frame.
  • the inclination angle of the document image is the inclination angle of the frame.
  • Add a right angle, and the direction of the tilt angle is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the tilt angle of the document image is the complement angle of the tilt angle of the frame, and the tilt angle The direction is counterclockwise.
  • the inclination angle of the document image is the inclination angle of the frame.
  • the oblique angle direction is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the inclination angle direction is clockwise direction.
  • the tilt angle of the document image is the inclination angle of the frame.
  • the oblique angle direction is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the tilt angle of the document image is the complementary angle of the tilt angle of the frame, and the tilt angle direction is inverse Hour direction.
  • the tilt angle of the document image is the tilt angle of the frame plus Right angle, and the direction of the tilt angle is counterclockwise; if the angle between the direction of the text sequence in the title and the upward direction of the water quality is an obtuse angle, the tilt angle of the document image is the tilt angle of the frame, and the tilt angle direction is counterclockwise.
  • the inclination angle of the document image is the inclination angle of the frame plus Upright angle, and the direction of the tilt angle is counterclockwise; if the direction of the text sequence in the title The angle with the vertical upward direction is an obtuse angle, and the inclination angle of the document image is the inclination angle of the frame plus a right angle, and the inclination angle direction is a counterclockwise direction.
  • the inclination angle of the document image is the complement of the inclination angle of the frame. Angle, and the direction of the oblique angle is clockwise; if the angle between the direction of the text sequence in the title and the vertical upward direction is an obtuse angle, the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the direction of the inclination angle is smooth Hour direction.
  • the inclination angle of the document image is the inclination angle of the frame.
  • the complementary angle, and the direction of the oblique angle is clockwise; if the angle between the direction of the text sequence in the title and the vertical upward direction is an obtuse angle, the inclination angle of the document image is the inclination angle of the frame, and the direction of the inclination angle is counterclockwise .
  • FIG 4 is a diagram showing the tilt angle of a document image in one embodiment.
  • the schematic shows a bezel 410, a tilt angle 420, and a title 430.
  • the tilt angle 420 may be an angle 421 offset from the horizontal direction, the direction is a clockwise direction, or may be an angle 422 deviating from the vertical direction, the direction being a clockwise direction.
  • the computer device can rotate the document image by an angle equal to the tilt angle in a direction of decreasing the tilt angle according to the tilt angle of the document image, thereby realizing the direction correction of the document image.
  • the image correction method automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document image according to the binary image.
  • the position of the title so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained.
  • the document image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
  • step S206 includes: extracting according to a distribution of pixel values in the binary image. a straight line included in the binary image; calculating a coordinate position of the intersection formed between the extracted straight lines; determining a straight line constituting the frame in the binary image according to the coordinate position of the intersection; determining the inclination angle of the frame according to the inclination angle of the straight line constituting the frame.
  • the computer device can traverse the pixel values of the respective pixel points row by row or column by column, and recognize the detected consecutive pixel values having the same pixel value as a straight line.
  • the computer device can further determine the intersection formed between the straight lines, and determine the pixel position of the pixel at the intersection position as the coordinate position of the intersection.
  • the computer device can further select the maximum value and the minimum value of the abscissa and the maximum value and the minimum value of the ordinate for the coordinate positions of all the intersection points, thereby determining the straight line constituting the frame in the binary image according to the determined maximum value and the minimum value.
  • the inclination angle of the bezel is determined according to the inclination angle of the straight line constituting the bezel.
  • is the vertical distance from the origin to the straight line
  • is the angle between the perpendicular and the X axis
  • ⁇ *k/180°.
  • the computer device obtains a sinusoidal curve in the parameter plane by polar coordinate transformation by taking the pixel position (Xi, Yi) of the pixel point where each pixel value in the binary image is "0".
  • the parameters k and b of the intersection corresponding to the straight line in the binary image plane can be calculated according to the coordinate position ( ⁇ , ⁇ ) of the intersection position of each sinusoid.
  • the computer device can further determine the intersection formed between the straight lines, and determine the pixel position of the pixel at the intersection position as the coordinate position of the intersection.
  • the computer device can further select the maximum value and the minimum value of the abscissa and the maximum value and the minimum value of the ordinate for the coordinate positions of all the intersection points, thereby determining the straight line constituting the frame in the binary image according to the determined maximum value and the minimum value.
  • the inclination angle of the bezel is determined according to the inclination angle of the straight line constituting the bezel.
  • the straight line constituting the frame in the binary image is determined according to the intersection of the straight lines, and the inclination of the frame is determined according to the inclination angle of the straight line constituting the frame.
  • the angle ensures the accuracy of the determined tilt angle of the border.
  • step S208 includes: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; determining a position of the connected domain having the longest shortest side length as a position of the title in the binary image .
  • the computer device may perform the connected domain analysis on the binarized document image to extract the connected domain, and may also merge the adjacent connected domains.
  • the computer device can use the Run Length Smooth Algorithm (RLSA) algorithm to analyze and merge the connected domains.
  • RLSA Run Length Smooth Algorithm
  • the algorithm can connect the pixels of adjacent connected domains to form a monolithic region, because the same text sequence is internal. The distance between the connected domains is relatively close, so the connected domains in the same text sequence can form a complete connected domain.
  • the computer device can determine the outer contour of the connected domain as the location of the connected domain.
  • the position of the connected domain can be represented by a vertex of the rectangle and a rectangle width and a rectangle height.
  • the short side of the connected domain is roughly the width or height of the character, and the computer device can determine the short side length of each connected domain, and determine the position of the connected domain having the longest short side length as the position of the title in the binary image.
  • the position of the title in the binary image is automatically determined based on the length of the short side of the connected domain, and the accuracy of the determined position of the title is ensured.
  • the image correction method further comprises: removing noise in the binary image according to the distribution of pixel values in the binary image.
  • noise is a dead point generated during binarization processing.
  • the process of removing noise is to change the process of some isolated first pixel value "1" representing the background point to the second pixel value "0" representing the former attraction.
  • four consecutive and below noises are removed.
  • the denoising process is performed, thereby avoiding the influence of the noise on the determination of the subsequent frame tilt angle, and ensuring effective subsequent data processing.
  • the image correction method further comprises: performing redundant cutting on the direction-corrected document image according to the position of the border in the binary image, and obtaining a redundant cut. Cut the documentary image.
  • the computer device can determine the area outside the border as a redundant part according to the border in the binary image, perform cutting, and retain the area enclosed by the border, thereby eliminating the problem that the edge of the document image is too much, and obtaining the correcting direction and Crop redundant document images.
  • the image correction method specifically includes the following steps:
  • S516 Perform redundant cutting on the corrected direction image according to the position of the border in the binary image to obtain a redundantly cut document image.
  • the document image after acquiring the document image to be corrected, the document image is automatically binarized to obtain a binary image, and the tilt angle of the document image frame and the document can be determined according to the binary image.
  • the position of the image title so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained.
  • the documentary image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
  • the image correction device 600 includes an acquisition module 601, a processing module 602, a determination module 603, and a correction module 604.
  • the obtaining module 601 is configured to obtain a document image to be corrected.
  • the processing module 602 is configured to perform binarization processing on the document image to obtain a binary image.
  • a determining module 603 configured to determine a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image; determine a position of the header in the binary image according to a size of the connected domain in the binary image; according to a tilt angle and a title of the border The position of the image determines the tilt angle of the document.
  • the correction module 604 is configured to perform direction correction on the document image according to the tilt angle of the document image, and obtain a document image corrected by the direction.
  • the image correcting device 600 After obtaining the document image to be corrected, the image correcting device 600 automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document according to the binary image.
  • the position of the image title so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained.
  • the documentary image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
  • the determining module 603 is further configured to: extract a line included in the binary image according to the distribution of the pixel values in the binary image; calculate a coordinate position of the intersection formed between the extracted straight lines; determine according to the coordinate position of the intersection point A line constituting a frame in the binary image; the inclination angle of the frame is determined according to the inclination angle of the line constituting the frame.
  • the straight line constituting the frame in the binary image is determined according to the intersection point of the straight line, and the tilt angle of the frame is determined according to the inclination angle of the straight line constituting the frame, thereby ensuring the determined border.
  • the accuracy of the tilt angle is determined according to the intersection point of the straight line, and the tilt angle of the frame is determined according to the inclination angle of the straight line constituting the frame, thereby ensuring the determined border.
  • the determining module 603 is further configured to extract the connected domain in the binary image; obtain the short side length of each connected domain; and determine the position of the connected domain with the longest shortest edge length as the title in the binary image s position.
  • the position of the title in the binary image is automatically determined based on the length of the short side of the connected domain, and the accuracy of the determined position of the title is ensured.
  • the processing module 602 is further configured to remove noise in the binary image according to the distribution of pixel values in the binary image.
  • the denoising process is performed, thereby avoiding the influence of the noise on the determination of the subsequent frame tilt angle, and ensuring effective subsequent data processing.
  • the correction module 604 is further configured to perform redundant cutting on the direction-corrected document image according to the position of the border in the binary image to obtain a redundantly cut document image.
  • the image correcting device in each of the above embodiments may be implemented in the form of a computer program, and the computer readable instructions corresponding to the computer program may be run on a computer device as shown in FIG.
  • the network interface may be an Ethernet card or a wireless network card.
  • the above modules may be embedded in the hardware of the terminal or may be stored in the memory of the terminal in a software form, so that the processor calls the execution of the operations corresponding to the above modules.
  • the processor can be a central processing unit (CPU), a microprocessor, a microcontroller, or the like.
  • one or more computer readable non-volatile storage media having computer readable instructions stored by one or more processors are provided for causing one or more processes Performing the following steps: obtaining a document image to be corrected; binarizing the document image to obtain a binary image; determining a tilt angle of the border in the binary image according to the distribution of pixel values in the binary image; according to the binary image
  • the size of the connected domain determines the position of the title in the binary image; the tilt angle of the document image is determined according to the tilt angle of the border and the position of the title;
  • the oblique angle corrects the direction of the document image, and obtains the document image corrected by the direction.
  • determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image comprises: extracting a line included in the binary image according to the distribution of pixel values in the binary image; calculating the extracted straight line The coordinate position of the intersection formed between the two; the straight line constituting the frame in the binary image is determined according to the coordinate position of the intersection; and the inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
  • determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; The position of the long connected domain is determined as the position of the title in the binary image.
  • the computer readable instructions cause one or more processors to perform binarization processing on the document image to obtain a binary image, and further perform the step of removing the binary value according to the distribution of pixel values in the binary image Noise in the image.
  • the computer readable instructions cause one or more processors to perform direction correction on the document image according to the tilt angle of the document image, and after obtaining the direction corrected document image, performing the following steps:
  • the position of the border in the value image is redundantly cropped by the direction-corrected document image to obtain a redundantly cut document image.
  • the storage medium After obtaining the document image to be corrected, the storage medium automatically binarizes the document image to obtain a binary image, and the tilt angle of the document image frame and the document image title can be determined according to the binary image.
  • the position is determined according to the inclination angle of the document image frame and the position of the document image title, and the direction of the document image can be corrected according to the inclination angle of the document image, and the direction correction is obtained.
  • the image is proofed, thus avoiding the workload introduced by manual correction and greatly improving the image correction efficiency.
  • a computer apparatus comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the processor to perform the step of: obtaining a single to be corrected
  • the image is obtained by binarizing the document image to obtain a binary image; determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image; determining the binary image according to the size of the connected domain in the binary image
  • the position of the title; the tilt angle of the document image is determined according to the tilt angle of the border and the position of the title; the image of the document is entered according to the tilt angle of the document image Correction of the direction of the line, obtaining a document image that has been corrected by direction.
  • determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image comprises: extracting a line included in the binary image according to the distribution of pixel values in the binary image; calculating the extracted straight line The coordinate position of the intersection formed between the two; the straight line constituting the frame in the binary image is determined according to the coordinate position of the intersection; and the inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
  • determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; The position of the long connected domain is determined as the position of the title in the binary image.
  • the computer readable instructions cause the processor to perform binarization processing on the document image to obtain a binary image, and further perform the following steps: removing noise in the binary image according to the distribution of pixel values in the binary image .
  • the computer readable instructions cause the processor to perform direction correction on the document image according to the tilt angle of the document image, and after obtaining the direction corrected document image, performing the following steps: according to the border in the binary image The location of the corrected image of the corrected image is redundantly cropped to obtain a redundantly cut document image.
  • the computer device After obtaining the document image to be corrected, the computer device automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document image title according to the binary image. The position is determined according to the inclination angle of the document image frame and the position of the document image title, and the direction of the document image can be corrected according to the inclination angle of the document image, and the direction correction is obtained.
  • the image is proofed, thus avoiding the workload introduced by manual correction and greatly improving the image correction efficiency.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or the like.

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)
  • Image Analysis (AREA)
  • Facsimile Image Signal Circuits (AREA)
  • Editing Of Facsimile Originals (AREA)

Abstract

Disclosed is an image correction method, comprising: acquiring a document image to be corrected; carrying out binarization processing on the document image to obtain a binary image; according to the distribution of pixel values in the binary image, determining a tilt angle of a frame in the binary image; according to the size of a connected domain in the binary image, determining the location of a title in the binary image; according to the tilt angle of the frame and the location of the title, determining a tilt angle of the document image; and according to the tilt angle of the document image, correcting the direction of the document image to obtain a document image having been subjected to direction correction.

Description

影像矫正方法、装置、存储介质和计算机设备Image correction method, device, storage medium and computer equipment
相关申请的交叉引用Cross-reference to related applications
本申请要求于2017年07月25日提交中国专利局,申请号为201710612985.7,发明名称为“影像矫正方法、装置、存储介质和计算机设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims to be filed on July 25, 2017, the Chinese Patent Office, the number of which is the number of the Japanese Patent Application No. PCT Application No. In this application.
技术领域Technical field
本申请涉及计算机技术领域,特别是涉及一种影像矫正方法、装置、存储介质和计算机设备。The present application relates to the field of computer technology, and in particular, to an image correction method, apparatus, storage medium, and computer device.
背景技术Background technique
现如今,保险作为一种产品已被越来越多的用户所接受和使用。用户在购买保险时往往需要手动在纸质的保险单证上填写相关信息,业务人员再通过对对纸质填写相关信息后的保险单证进行扫描或拍摄得到的单证影像进行保存。Nowadays, insurance as a product has been accepted and used by more and more users. When purchasing insurance, users often need to manually fill in the relevant information on the paper insurance certificate, and the business personnel will save the document image obtained by scanning or photographing the insurance document after filling in the relevant information on paper.
然而,通过扫描或者拍摄等方式得到的单证影像难免会存在颠倒或者倾斜的问题,需要对单证影像进行矫正。目前对于单证影像的矫正依赖于业务人员手动进行矫正,导致对单证影像进行矫正的效率低下。However, the document image obtained by scanning or photographing will inevitably have the problem of being reversed or tilted, and the document image needs to be corrected. At present, the correction of the document image relies on the manual correction by the business personnel, resulting in inefficiency in correcting the document image.
发明内容Summary of the invention
根据本申请的各种实施例,提供一种影像矫正方法、装置、存储介质和计算机设备。According to various embodiments of the present application, an image correction method, apparatus, storage medium, and computer apparatus are provided.
一种影像矫正方法,包括:An image correction method includes:
获取待矫正的单证影像;Obtaining the document image to be corrected;
对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角; Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
一种影像矫正装置,包括:An image correcting device comprising:
获取模块,用于获取待矫正的单证影像;Obtaining a module for acquiring a document image to be corrected;
处理模块,用于对所述单证影像进行二值化处理得到二值图像;a processing module, configured to perform binarization processing on the document image to obtain a binary image;
确定模块,用于根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及a determining module, configured to determine a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image; determining a position of a header in the binary image according to a size of a connected domain in the binary image; Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
矫正模块,用于根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The correction module is configured to perform direction correction on the document image according to the tilt angle of the document image, and obtain a document image that has undergone direction correction.
一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:One or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the steps of:
获取待矫正的单证影像;Obtaining the document image to be corrected;
对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
一种计算机设备,包括存储器和处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述处理器执行以 下步骤:A computer device comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the processor to execute Next steps:
获取待矫正的单证影像;Obtaining the document image to be corrected;
对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征、目的和优点将从说明书、附图以及权利要求书变得明显。Details of one or more embodiments of the present application are set forth in the accompanying drawings and description below. Other features, objects, and advantages of the invention will be apparent from the description and appended claims.
附图说明DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings to be used in the embodiments will be briefly described below. Obviously, the drawings in the following description are only some embodiments of the present application, Those skilled in the art can also obtain other drawings based on these drawings without any creative work.
图1为一个实施例中计算机设备的内部结构图;1 is a diagram showing the internal structure of a computer device in an embodiment;
图2为一个实施例中影像矫正方法的流程示意图;2 is a schematic flow chart of an image correction method in an embodiment;
图3为一个实施例中二值化前后的单证影像的示意图;3 is a schematic diagram of a document image before and after binarization in one embodiment;
图4为一个实施例中单证影像中边框的倾斜角的示意图;4 is a schematic diagram of a tilt angle of a frame in a document image in an embodiment;
图5为另一个实施例中影像矫正方法的流程示意图;FIG. 5 is a schematic flow chart of an image correction method in another embodiment; FIG.
图6为一个实施例中影像矫正装置的结构框图。Fig. 6 is a block diagram showing the structure of an image correcting device in an embodiment.
具体实施方式Detailed ways
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施 例仅仅用以解释本申请,并不用于限定本申请。In order to make the objects, technical solutions, and advantages of the present application more comprehensible, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific implementation described herein The examples are only used to explain the present application and are not intended to limit the application.
图1为一个实施例中计算机设备的内部结构示意图。如图1所示,该计算机设备包括通过系统总线连接的处理器和存储器。其中,存储器包括非易失性存储介质和内存储器。该计算机设备的非易失性存储介质可存储操作系统和计算机可读指令,该计算机可读指令被执行时,可使得处理器执行一种影像矫正方法。该计算机设备的处理器用于提供计算和控制能力,支撑整个计算机设备的运行。该内存储器中也可储存有计算机可读指令,该计算机可读指令被处理器执行时,该计算机可读指令用于实现以下各实施例所提供的一种影像矫正方法。本领域技术人员可以理解,图1中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的终端的限定,具体的终端可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。FIG. 1 is a schematic diagram showing the internal structure of a computer device in an embodiment. As shown in FIG. 1, the computer device includes a processor and a memory connected by a system bus. Wherein, the memory comprises a non-volatile storage medium and an internal memory. The non-volatile storage medium of the computer device can store an operating system and computer readable instructions that, when executed, cause the processor to perform an image correction method. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device. The internal memory can also store computer readable instructions for implementing an image correction method provided by the following embodiments when the computer readable instructions are executed by a processor. A person skilled in the art can understand that the structure shown in FIG. 1 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the terminal to which the solution of the present application is applied. The specific terminal may include a ratio. More or fewer components are shown in the figures, or some components are combined, or have different component arrangements.
如图2所示,在一个实施例中,提供了一种影像矫正方法。本实施例主要以该方法应用于上述图1中的计算机设备来举例说明。参照图2,该影像矫正方法具体包括如下步骤:As shown in Figure 2, in one embodiment, an image correction method is provided. This embodiment is mainly illustrated by the method applied to the computer device in FIG. 1 described above. Referring to FIG. 2, the image correction method specifically includes the following steps:
S202,获取待矫正的单证影像。S202. Acquire a document image to be corrected.
其中,单证影像是包含单证的图像,可以是单证照片或者单证扫描件等。待矫正的单证影像是需要进行方向矫正的单证影像。计算机设备可通过计算机设备的摄像头拍摄实体单证得到单证影像,或者通过扫描仪扫描实体单证得到单证影像,或者接收另一计算机设备发送的单证影像。The document image is an image containing a document, and may be a document photo or a document scan. The document image to be corrected is a document image that requires direction correction. The computer device can obtain a document image by photographing a physical document through a camera of the computer device, or obtain a document image by scanning a physical document by a scanner, or receiving a document image transmitted by another computer device.
S204,对单证影像进行二值化处理得到二值图像。S204, performing binarization processing on the document image to obtain a binary image.
其中,二值化是将图像上的像素点设置为两种像素值。比如,将图像上像素点的灰度值设置为0或255。Among them, binarization is to set the pixel points on the image to two pixel values. For example, set the gray value of the pixel on the image to 0 or 255.
具体地,计算机设备可采用固定阈值二值化算法或者自适应阈值二值化算法,将单证影像中高于阈值和低于阈值的像素值分别置为预设的两种像素值中的一种,这两种像素值分别是第一像素值和第二像素值。Specifically, the computer device may use a fixed threshold binarization algorithm or an adaptive threshold binarization algorithm to set pixel values above and below the threshold in the document image to one of two preset pixel values. The two pixel values are the first pixel value and the second pixel value, respectively.
在一个实施例中,计算机设备可通过调用MATLAB从单证影像中读取到 的单证影像中各像素点的RGB值,再根据每个像素点的RGB值计算得到各像素点的灰度值。将单证影像中的各像素点的灰度值与预设阈值进行比较,将大于预设阈值的灰度值设置为“1”,将小于等于预设阈值的灰度值设置为“0”,使单证影像的各像素点二值化,得到二值图像。In one embodiment, the computer device can read from the document image by calling MATLAB. The RGB value of each pixel in the document image is calculated, and the gradation value of each pixel is calculated according to the RGB value of each pixel. The gray value of each pixel in the document image is compared with a preset threshold, the gray value greater than the preset threshold is set to "1", and the gray value less than or equal to the preset threshold is set to "0" , binarize each pixel of the document image to obtain a binary image.
S206,根据二值图像中像素值的分布确定二值图像中边框的倾斜角。S206. Determine a tilt angle of the border in the binary image according to the distribution of pixel values in the binary image.
其中,边框是外围框线。边框围住的内容即为单证的内容。倾斜角是指偏离标准方向的角度。标准方向可以是水平方向或者垂直方向。倾斜角具体可以是偏离水平方向的角度,方向为顺时针方向;也可以是偏离竖直方向的角度,方向为逆时针方向。Among them, the border is a peripheral frame. The content enclosed by the border is the content of the document. The tilt angle is the angle from the standard direction. The standard direction can be horizontal or vertical. The tilt angle may specifically be an angle deviating from the horizontal direction, the direction is a clockwise direction, or may be an angle deviating from the vertical direction, and the direction is a counterclockwise direction.
具体地,计算机设备可逐行遍历各像素点的像素值,将检测到的连续的像素值相同的像素点识别为直线,再从识别得到的直线中确定构成边框的直线。计算机设备可再计算该直线偏离标注方向的角度,进而得到边框的倾斜角。计算机设备具体可采用主成分分析(Principal Component Analysis,PCA)算法或者最小二乘回归算法等算法来得到构成边框的直线的倾斜角。Specifically, the computer device can traverse the pixel values of the respective pixel points row by line, recognize the detected consecutive pixel values having the same pixel value as a straight line, and determine the straight line constituting the frame from the recognized straight lines. The computer device can recalculate the angle of the line from the direction of the label, thereby obtaining the tilt angle of the frame. The computer device may specifically adopt an algorithm such as a principal component analysis (PCA) algorithm or a least squares regression algorithm to obtain a tilt angle of a straight line constituting the frame.
图3示出了一个实施例中单证影像中边框的倾斜角的示意图。参考图3,该示意图展示有边框310和倾斜角320。其中,倾斜角320可以是偏离水平方向的角度321,方向为顺时针方向;也可以是偏离竖直方向的角度322,方向为逆时针方向。Figure 3 is a diagram showing the tilt angle of the border in the document image in one embodiment. Referring to Figure 3, the schematic shows a bezel 310 and a tilt angle 320. Wherein, the inclination angle 320 may be an angle 321 deviating from the horizontal direction, the direction is a clockwise direction; or may be an angle 322 deviating from the vertical direction, and the direction is a counterclockwise direction.
S208,根据二值图像中连通域的大小确定二值图像中标题的位置。S208. Determine a position of the title in the binary image according to the size of the connected domain in the binary image.
在通常情况下,认定单证影像中标题的字符最大。在本实施例中,计算机设备可获取单证影像中包括的连通域,确定各连通域的大小,选取最大的连通域的位置作为标题的位置。Under normal circumstances, the character of the title in the document image is determined to be the largest. In this embodiment, the computer device can obtain the connected domain included in the document image, determine the size of each connected domain, and select the location of the largest connected domain as the location of the title.
S210,根据边框的倾斜角和标题的位置,确定单证影像的倾斜角。S210: Determine a tilt angle of the document image according to the tilt angle of the border and the position of the title.
具体地,计算机设备可确定标题中文本序列的方向,根据标题中文本序列的方向、标题在单证图像中的位置以及边框的倾斜角,确定单证影像的倾斜角。Specifically, the computer device can determine the direction of the text sequence in the title, and determine the tilt angle of the document image based on the direction of the text sequence in the title, the position of the title in the document image, and the tilt angle of the frame.
在标准方向为水平方向,且标题的位置为二值图像的顶部时,若标题中 文本序列的方向与水平向右方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角的余角,且倾斜角方向为逆时针方向;若标题中文本序列的方向与水平向右方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角的补角,且倾斜角方向为逆时针方向。When the standard direction is horizontal and the position of the title is at the top of the binary image, if in the title The angle between the direction of the text sequence and the horizontal direction to the right is an acute angle, and the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the direction of the inclination angle is counterclockwise; if the direction and the horizontal direction of the text sequence in the title The angle in the right direction is an obtuse angle, and the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the direction of the inclination angle is counterclockwise.
在标准方向为水平方向,且标题的位置为二值图像的右侧时,若标题中文本序列的方向与水平向右方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角加上直角,且倾斜角方向为顺时针方向;若标题中文本序列的方向与水平向右方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角的补角,且倾斜角方向为逆时针方向。When the standard direction is the horizontal direction and the position of the title is the right side of the binary image, if the angle between the direction of the text sequence in the title and the horizontal right direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame. Add a right angle, and the direction of the tilt angle is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the tilt angle of the document image is the complement angle of the tilt angle of the frame, and the tilt angle The direction is counterclockwise.
在标准方向为水平方向,且标题的位置为二值图像的底部时,若标题中文本序列的方向与水平向右方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角,且倾斜角方向为顺时针方向;若标题中文本序列的方向与水平向右方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角的补角,且倾斜角方向为顺时针方向。When the standard direction is the horizontal direction and the position of the title is the bottom of the binary image, if the angle between the direction of the text sequence in the title and the horizontal right direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame. And the oblique angle direction is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the inclination angle direction is clockwise direction.
在标准方向为水平方向,且标题的位置为二值图像的左侧时,若标题中文本序列的方向与水平向右方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角,且倾斜角方向为顺时针方向;若标题中文本序列的方向与水平向右方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角的余角,且倾斜角方向为逆时针方向。When the standard direction is the horizontal direction and the position of the title is the left side of the binary image, if the angle between the direction of the text sequence in the title and the horizontal right direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame. And the oblique angle direction is clockwise; if the angle between the direction of the text sequence in the title and the horizontal right direction is an obtuse angle, the tilt angle of the document image is the complementary angle of the tilt angle of the frame, and the tilt angle direction is inverse Hour direction.
在标准方向为垂直方向,且标题的位置为二值图像的顶部时,若标题中文本序列的方向与垂直向上方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角加上直角,且倾斜角方向为逆时针方向;若标题中文本序列的方向与水质向上方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角,且倾斜角方向为逆时针方向。When the standard direction is the vertical direction and the position of the title is the top of the binary image, if the angle between the direction of the text sequence in the title and the vertical upward direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame plus Right angle, and the direction of the tilt angle is counterclockwise; if the angle between the direction of the text sequence in the title and the upward direction of the water quality is an obtuse angle, the tilt angle of the document image is the tilt angle of the frame, and the tilt angle direction is counterclockwise.
在标准方向为垂直方向,且标题的位置为二值图像的右侧时,若标题中文本序列的方向与垂直向上方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角加上直角,且倾斜角方向为逆时针方向;若标题中文本序列的方向 与垂直向上方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角加上直角,且倾斜角方向为逆时针方向。When the standard direction is the vertical direction and the position of the title is the right side of the binary image, if the angle between the direction of the text sequence in the title and the vertical upward direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame plus Upright angle, and the direction of the tilt angle is counterclockwise; if the direction of the text sequence in the title The angle with the vertical upward direction is an obtuse angle, and the inclination angle of the document image is the inclination angle of the frame plus a right angle, and the inclination angle direction is a counterclockwise direction.
在标准方向为垂直方向,且标题的位置为二值图像的底部时,若标题中文本序列的方向与垂直向上方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角的补角,且倾斜角方向为顺时针方向;若标题中文本序列的方向与垂直向上方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角的余角,且倾斜角方向为顺时针方向。When the standard direction is the vertical direction and the position of the title is the bottom of the binary image, if the angle between the direction of the text sequence in the title and the vertical upward direction is an acute angle, the inclination angle of the document image is the complement of the inclination angle of the frame. Angle, and the direction of the oblique angle is clockwise; if the angle between the direction of the text sequence in the title and the vertical upward direction is an obtuse angle, the inclination angle of the document image is the complementary angle of the inclination angle of the frame, and the direction of the inclination angle is smooth Hour direction.
在标准方向为垂直方向,且标题的位置为二值图像的左侧时,若标题中文本序列的方向与垂直向上方向的夹角为锐角,则单证影像的倾斜角为边框的倾斜角的余角,且倾斜角方向为顺时针方向;若标题中文本序列的方向与垂直向上方向的夹角为钝角,则单证影像的倾斜角为边框的倾斜角,且倾斜角方向为逆时针方向。When the standard direction is the vertical direction and the position of the title is the left side of the binary image, if the angle between the direction of the text sequence in the title and the vertical upward direction is an acute angle, the inclination angle of the document image is the inclination angle of the frame. The complementary angle, and the direction of the oblique angle is clockwise; if the angle between the direction of the text sequence in the title and the vertical upward direction is an obtuse angle, the inclination angle of the document image is the inclination angle of the frame, and the direction of the inclination angle is counterclockwise .
图4示出了一个实施例中单证影像的倾斜角的示意图。参考图4,该示意图展示了边框410、倾斜角420和标题430。其中倾斜角420可以是偏离水平方向的角度421,方向为顺时针方向;也可以是偏离竖直方向的角度422,方向为顺时针方向。Figure 4 is a diagram showing the tilt angle of a document image in one embodiment. Referring to Figure 4, the schematic shows a bezel 410, a tilt angle 420, and a title 430. The tilt angle 420 may be an angle 421 offset from the horizontal direction, the direction is a clockwise direction, or may be an angle 422 deviating from the vertical direction, the direction being a clockwise direction.
S212,根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像。S212, correcting the direction of the document image according to the tilt angle of the document image, and obtaining the document image corrected by the direction.
具体地,计算机设备可根据单证影像的倾斜角,朝减小倾斜角的方向将单证影像旋转等于倾斜角的角度,从而实现对单证影像的方向矫正。Specifically, the computer device can rotate the document image by an angle equal to the tilt angle in a direction of decreasing the tilt angle according to the tilt angle of the document image, thereby realizing the direction correction of the document image.
上述影像矫正方法,在获取待矫正的单证影像后,自动对该单证影像进行二值化处理得到二值图像,即可根据该二值图像确定单证影像边框的倾斜角以及单证影像标题的位置,从而根据单证影像边框的倾斜角和单证影像标题的位置确定单证影像的倾斜角,即可根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像,从而避免了人工矫正引入的工作量,极大地提高了影像矫正效率。After obtaining the document image to be corrected, the image correction method automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document image according to the binary image. The position of the title, so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained. The document image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
在一个实施例中,步骤S206包括:根据二值图像中像素值的分布,提取 二值图像中包含的直线;计算提取的直线之间形成的交点的坐标位置;根据交点的坐标位置确定二值图像中构成边框的直线;根据构成边框的直线的倾斜角确定边框的倾斜角。In an embodiment, step S206 includes: extracting according to a distribution of pixel values in the binary image. a straight line included in the binary image; calculating a coordinate position of the intersection formed between the extracted straight lines; determining a straight line constituting the frame in the binary image according to the coordinate position of the intersection; determining the inclination angle of the frame according to the inclination angle of the straight line constituting the frame.
具体地,计算机设备可逐行或逐列遍历各像素点的像素值,将检测到的连续的像素值相同的像素点识别为直线。计算机设备可再确定各直线之间形成的交点,将交点位置处的像素点的像素位置确定为交点的坐标位置。计算机设备可再对所有交点的坐标位置,分别选取横坐标的最大值与最小值,纵坐标的最大值与最小值,从而根据确定的最大值与最小值确定二值图像中构成边框的直线,根据构成边框的直线的倾斜角确定边框的倾斜角。Specifically, the computer device can traverse the pixel values of the respective pixel points row by row or column by column, and recognize the detected consecutive pixel values having the same pixel value as a straight line. The computer device can further determine the intersection formed between the straight lines, and determine the pixel position of the pixel at the intersection position as the coordinate position of the intersection. The computer device can further select the maximum value and the minimum value of the abscissa and the maximum value and the minimum value of the ordinate for the coordinate positions of all the intersection points, thereby determining the straight line constituting the frame in the binary image according to the determined maximum value and the minimum value. The inclination angle of the bezel is determined according to the inclination angle of the straight line constituting the bezel.
在一个实施例中,在直角坐标系中,直线的直角坐标方程为y=kx+b。在极坐标空间中,直线的极坐标方程为ρ=x·cos(θ)+y·sin(θ)。其中ρ为原点到直线的垂直距离,θ表示垂线与X轴的夹角,θ=π*k/180°。对经过点A(x1,y1)的直线LA和经过点B(x2,y2)的直线LB,如果round(ρA)=round(ρB)且θA=θB,则点A和点B在同一条直线上。直角坐标空间中的一个点对应于极坐标空间中的一条线,极坐标空间中的一个点对应于直角坐标空间中的一条线。In one embodiment, in a Cartesian coordinate system, the Cartesian coordinate equation of the line is y=kx+b. In the polar coordinate space, the polar coordinate equation of the straight line is ρ=x·cos(θ)+y·sin(θ). Where ρ is the vertical distance from the origin to the straight line, and θ is the angle between the perpendicular and the X axis, θ=π*k/180°. For a straight line LA passing through point A (x1, y1) and a straight line LB passing through point B (x2, y2), if round(ρ A ) = round(ρ B ) and θ A = θ B , then point A and point B On the same line. A point in the Cartesian coordinate space corresponds to a line in the polar coordinate space, and a point in the polar coordinate space corresponds to a line in the Cartesian coordinate space.
进一步地,二值图像中“1”代表背景,“0”代表线条。计算机设备把二值图像中每个像素值为“0”的像素点所在的像素位置(Xi,Yi),通过极坐标变换得到参数平面中的正弦曲线。根据各正弦曲线交点位置的坐标位置(ρ,θ)即可计算得到该交点对应于二值图像平面中的直线的参数k与b。Further, "1" in the binary image represents the background, and "0" represents the line. The computer device obtains a sinusoidal curve in the parameter plane by polar coordinate transformation by taking the pixel position (Xi, Yi) of the pixel point where each pixel value in the binary image is "0". The parameters k and b of the intersection corresponding to the straight line in the binary image plane can be calculated according to the coordinate position (ρ, θ) of the intersection position of each sinusoid.
计算机设备可再确定各直线之间形成的交点,将交点位置处的像素点的像素位置确定为交点的坐标位置。计算机设备可再对所有交点的坐标位置,分别选取横坐标的最大值与最小值,纵坐标的最大值与最小值,从而根据确定的最大值与最小值确定二值图像中构成边框的直线,根据构成边框的直线的倾斜角确定边框的倾斜角。The computer device can further determine the intersection formed between the straight lines, and determine the pixel position of the pixel at the intersection position as the coordinate position of the intersection. The computer device can further select the maximum value and the minimum value of the abscissa and the maximum value and the minimum value of the ordinate for the coordinate positions of all the intersection points, thereby determining the straight line constituting the frame in the binary image according to the determined maximum value and the minimum value. The inclination angle of the bezel is determined according to the inclination angle of the straight line constituting the bezel.
上述实施例中,通过从二值图像中提取直线后,根据直线的交点确定二值图像中构成边框的直线,再根据构成边框的直线的倾斜角确定边框的倾斜 角,保证了确定的边框的倾斜角的准确性。In the above embodiment, after the straight line is extracted from the binary image, the straight line constituting the frame in the binary image is determined according to the intersection of the straight lines, and the inclination of the frame is determined according to the inclination angle of the straight line constituting the frame. The angle ensures the accuracy of the determined tilt angle of the border.
在一个实施例中,步骤S208包括:提取二值图像中的连通域;获取各连通域的短边长度;将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。In an embodiment, step S208 includes: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; determining a position of the connected domain having the longest shortest side length as a position of the title in the binary image .
具体地,计算机设备可将二值化后的单证影像进行连通域分析提取出连通域,还可以将相邻连通域合并。计算机设备具体可采用行程平滑(Run Length Smooth Algorithm,缩写为RLSA)算法进行连通域分析和合并,该算法可以将相邻的连通域的像素相连,形成整块的区域,由于同一文本序列内部的各个连通域之间的距离比较接近,所以相同文本序列中的连通域可以形成一个完整的连通域。Specifically, the computer device may perform the connected domain analysis on the binarized document image to extract the connected domain, and may also merge the adjacent connected domains. The computer device can use the Run Length Smooth Algorithm (RLSA) algorithm to analyze and merge the connected domains. The algorithm can connect the pixels of adjacent connected domains to form a monolithic region, because the same text sequence is internal. The distance between the connected domains is relatively close, so the connected domains in the same text sequence can form a complete connected domain.
进一步地,计算机设备可将连通域的外轮廓确定为连通域的位置。当连通域的外轮廓用矩形表示时,连通域的位置可以用矩形的一个顶点以及矩形宽和矩形高来表示。其中,连通域的短边大致为字符的宽或者高,计算机设备可确定各连通域的短边长度,将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。Further, the computer device can determine the outer contour of the connected domain as the location of the connected domain. When the outer contour of the connected domain is represented by a rectangle, the position of the connected domain can be represented by a vertex of the rectangle and a rectangle width and a rectangle height. The short side of the connected domain is roughly the width or height of the character, and the computer device can determine the short side length of each connected domain, and determine the position of the connected domain having the longest short side length as the position of the title in the binary image.
在本实施例中,自动以连通域的短边长度为依据,确定为二值图像中标题的位置,保证了确定的标题的位置的准确性。In the present embodiment, the position of the title in the binary image is automatically determined based on the length of the short side of the connected domain, and the accuracy of the determined position of the title is ensured.
在一个实施例中,步骤S204后,该影像矫正方法还包括:根据二值图像中像素值的分布去除二值图像中的噪点。In an embodiment, after step S204, the image correction method further comprises: removing noise in the binary image according to the distribution of pixel values in the binary image.
其中,噪点是在二值化处理时产生的坏点。去除噪点的过程就是把某些孤立的代表背景点的第一像素值“1”变为代表前景点的第二像素值“0”的过程。在本实施例中将连续的四个及以下的噪点去除。Among them, noise is a dead point generated during binarization processing. The process of removing noise is to change the process of some isolated first pixel value "1" representing the background point to the second pixel value "0" representing the former attraction. In the present embodiment, four consecutive and below noises are removed.
在本实施例中,在对单证影像进行二值化处理得到二值图像之后,进行去噪处理,避免了噪点对后续边框倾斜角的确定带来的影响,确保后续数据处理的有效进行。In this embodiment, after the binary image is binarized to obtain a binary image, the denoising process is performed, thereby avoiding the influence of the noise on the determination of the subsequent frame tilt angle, and ensuring effective subsequent data processing.
在一个实施例中,步骤S212后,该影像矫正方法还包括:根据二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁 剪的单证影像。In an embodiment, after the step S212, the image correction method further comprises: performing redundant cutting on the direction-corrected document image according to the position of the border in the binary image, and obtaining a redundant cut. Cut the documentary image.
具体地,计算机设备可按照二值图像中的边框,将边框外部的区域判定为冗余部分,进行裁剪,将边框围住的区域保留,消除单证影像边缘太多的问题,得到矫正方向且裁剪冗余的单证影像。Specifically, the computer device can determine the area outside the border as a redundant part according to the border in the binary image, perform cutting, and retain the area enclosed by the border, thereby eliminating the problem that the edge of the document image is too much, and obtaining the correcting direction and Crop redundant document images.
如图5所示,在一个具体地实施例中,影像矫正方法具体包括以下步骤:As shown in FIG. 5, in a specific embodiment, the image correction method specifically includes the following steps:
S502,获取待矫正的单证影像。S502. Acquire a document image to be corrected.
S504,对单证影像进行二值化处理得到二值图像。S504, performing binarization processing on the document image to obtain a binary image.
S506,根据二值图像中像素值的分布去除二值图像中的噪点。S506. Remove noise in the binary image according to the distribution of pixel values in the binary image.
S508,根据二值图像中像素值的分布,提取二值图像中包含的直线;计算提取的直线之间形成的交点的坐标位置;根据交点的坐标位置确定二值图像中构成边框的直线;根据构成边框的直线的倾斜角确定边框的倾斜角。S508, extracting a line included in the binary image according to the distribution of the pixel values in the binary image; calculating a coordinate position of the intersection formed between the extracted lines; determining a line forming the frame in the binary image according to the coordinate position of the intersection; The inclination angle of the line constituting the frame determines the inclination angle of the frame.
S510,提取二值图像中的连通域;获取各连通域的短边长度;将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。S510. Extract a connected domain in the binary image; obtain a short side length of each connected domain; and determine a position of the connected domain having the longest shortest side length as a position of the title in the binary image.
S512,根据边框的倾斜角和标题的位置,确定单证影像的倾斜角。S512, determining the tilt angle of the document image according to the tilt angle of the border and the position of the title.
S514,根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像。S514, correcting the direction of the document image according to the tilt angle of the document image, and obtaining the document image corrected by the direction.
S516,根据二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。S516: Perform redundant cutting on the corrected direction image according to the position of the border in the binary image to obtain a redundantly cut document image.
在本实施例中,在获取待矫正的单证影像后,自动对该单证影像进行二值化处理得到二值图像,即可根据该二值图像确定单证影像边框的倾斜角以及单证影像标题的位置,从而根据单证影像边框的倾斜角和单证影像标题的位置确定单证影像的倾斜角,即可根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像,从而避免了人工矫正引入的工作量,极大地提高了影像矫正效率。In this embodiment, after acquiring the document image to be corrected, the document image is automatically binarized to obtain a binary image, and the tilt angle of the document image frame and the document can be determined according to the binary image. The position of the image title, so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained. The documentary image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
应该理解的是,虽然上述各实施例的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可 以以其它的顺序执行。而且,上述各实施例中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。It should be understood that although the respective steps in the flowcharts of the above embodiments are sequentially displayed in accordance with the indication of the arrows, these steps are not necessarily performed in the order indicated by the arrows. Except as expressly stated in this document, there are no strict order limits for the execution of these steps. Execute in other order. Moreover, at least some of the steps in the above embodiments may include a plurality of sub-steps or stages, which are not necessarily performed at the same time, but may be executed at different times, and these sub-steps or stages The order of execution is not necessarily performed sequentially, but may be performed alternately or alternately with at least a portion of other steps or sub-steps or stages of other steps.
如图6所示,提供了一种影像矫正装置600,影像矫正装置600包括:获取模块601、处理模块602、确定模块603和矫正模块604。As shown in FIG. 6, an image correction device 600 is provided. The image correction device 600 includes an acquisition module 601, a processing module 602, a determination module 603, and a correction module 604.
获取模块601,用于获取待矫正的单证影像。The obtaining module 601 is configured to obtain a document image to be corrected.
处理模块602,用于对单证影像进行二值化处理得到二值图像。The processing module 602 is configured to perform binarization processing on the document image to obtain a binary image.
确定模块603,用于根据二值图像中像素值的分布确定二值图像中边框的倾斜角;根据二值图像中连通域的大小确定二值图像中标题的位置;根据边框的倾斜角和标题的位置,确定单证影像的倾斜角。a determining module 603, configured to determine a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image; determine a position of the header in the binary image according to a size of the connected domain in the binary image; according to a tilt angle and a title of the border The position of the image determines the tilt angle of the document.
矫正模块604,用于根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像。The correction module 604 is configured to perform direction correction on the document image according to the tilt angle of the document image, and obtain a document image corrected by the direction.
上述影像矫正装置600,在获取待矫正的单证影像后,自动对该单证影像进行二值化处理得到二值图像,即可根据该二值图像确定单证影像边框的倾斜角以及单证影像标题的位置,从而根据单证影像边框的倾斜角和单证影像标题的位置确定单证影像的倾斜角,即可根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像,从而避免了人工矫正引入的工作量,极大地提高了影像矫正效率。After obtaining the document image to be corrected, the image correcting device 600 automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document according to the binary image. The position of the image title, so as to determine the tilt angle of the document image according to the tilt angle of the document image frame and the position of the document image title, the direction of the document image can be corrected according to the tilt angle of the document image, and the direction correction is obtained. The documentary image avoids the workload introduced by manual correction and greatly improves the image correction efficiency.
在一个实施例中,确定模块603还用于根据二值图像中像素值的分布,提取二值图像中包含的直线;计算提取的直线之间形成的交点的坐标位置;根据交点的坐标位置确定二值图像中构成边框的直线;根据构成边框的直线的倾斜角确定边框的倾斜角。In an embodiment, the determining module 603 is further configured to: extract a line included in the binary image according to the distribution of the pixel values in the binary image; calculate a coordinate position of the intersection formed between the extracted straight lines; determine according to the coordinate position of the intersection point A line constituting a frame in the binary image; the inclination angle of the frame is determined according to the inclination angle of the line constituting the frame.
在本实施例中,通过从二值图像中提取直线后,根据直线的交点确定二值图像中构成边框的直线,再根据构成边框的直线的倾斜角确定边框的倾斜角,保证了确定的边框的倾斜角的准确性。 In this embodiment, after the straight line is extracted from the binary image, the straight line constituting the frame in the binary image is determined according to the intersection point of the straight line, and the tilt angle of the frame is determined according to the inclination angle of the straight line constituting the frame, thereby ensuring the determined border. The accuracy of the tilt angle.
在一个实施例中,确定模块603还用于提取二值图像中的连通域;获取各连通域的短边长度;将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。In an embodiment, the determining module 603 is further configured to extract the connected domain in the binary image; obtain the short side length of each connected domain; and determine the position of the connected domain with the longest shortest edge length as the title in the binary image s position.
在本实施例中,自动以连通域的短边长度为依据,确定为二值图像中标题的位置,保证了确定的标题的位置的准确性。In the present embodiment, the position of the title in the binary image is automatically determined based on the length of the short side of the connected domain, and the accuracy of the determined position of the title is ensured.
在一个实施例中,处理模块602还用于根据二值图像中像素值的分布去除二值图像中的噪点。In one embodiment, the processing module 602 is further configured to remove noise in the binary image according to the distribution of pixel values in the binary image.
在本实施例中,在对单证影像进行二值化处理得到二值图像之后,进行去噪处理,避免了噪点对后续边框倾斜角的确定带来的影响,确保后续数据处理的有效进行。In this embodiment, after the binary image is binarized to obtain a binary image, the denoising process is performed, thereby avoiding the influence of the noise on the determination of the subsequent frame tilt angle, and ensuring effective subsequent data processing.
在一个实施例中,矫正模块604还用于根据二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。In one embodiment, the correction module 604 is further configured to perform redundant cutting on the direction-corrected document image according to the position of the border in the binary image to obtain a redundantly cut document image.
在本实施例中,消除了单证影像边缘过多的问题。In this embodiment, the problem of excessive edge of the document image is eliminated.
在一个实施例中,上述各个实施例中的影像矫正装置可以实现为一种计算机程序的形式,计算机程序对应的计算机可读指令可在如图1所示的计算机设备上运行。In one embodiment, the image correcting device in each of the above embodiments may be implemented in the form of a computer program, and the computer readable instructions corresponding to the computer program may be run on a computer device as shown in FIG.
上述影像矫正装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。其中,网络接口可以是以太网卡或无线网卡等。上述各模块可以硬件形式内嵌于或独立于终端的存储器中,也可以以软件形式存储于终端的存储器中,以便于处理器调用执行以上各个模块对应的操作。该处理器可以为中央处理单元(CPU)、微处理器、单片机等。Each of the above-described image correcting devices may be implemented in whole or in part by software, hardware, and combinations thereof. The network interface may be an Ethernet card or a wireless network card. The above modules may be embedded in the hardware of the terminal or may be stored in the memory of the terminal in a software form, so that the processor calls the execution of the operations corresponding to the above modules. The processor can be a central processing unit (CPU), a microprocessor, a microcontroller, or the like.
在一个实施例中,提供了一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,该计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:获取待矫正的单证影像;对单证影像进行二值化处理得到二值图像;根据二值图像中像素值的分布确定二值图像中边框的倾斜角;根据二值图像中连通域的大小确定二值图像中标题的位置;根据边框的倾斜角和标题的位置,确定单证影像的倾斜角;根据单证影像的倾 斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像。In one embodiment, one or more computer readable non-volatile storage media having computer readable instructions stored by one or more processors are provided for causing one or more processes Performing the following steps: obtaining a document image to be corrected; binarizing the document image to obtain a binary image; determining a tilt angle of the border in the binary image according to the distribution of pixel values in the binary image; according to the binary image The size of the connected domain determines the position of the title in the binary image; the tilt angle of the document image is determined according to the tilt angle of the border and the position of the title; The oblique angle corrects the direction of the document image, and obtains the document image corrected by the direction.
在一个实施例中,根据二值图像中像素值的分布确定二值图像中边框的倾斜角,包括:根据二值图像中像素值的分布,提取二值图像中包含的直线;计算提取的直线之间形成的交点的坐标位置;根据交点的坐标位置确定二值图像中构成边框的直线;根据构成边框的直线的倾斜角确定边框的倾斜角。In one embodiment, determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image comprises: extracting a line included in the binary image according to the distribution of pixel values in the binary image; calculating the extracted straight line The coordinate position of the intersection formed between the two; the straight line constituting the frame in the binary image is determined according to the coordinate position of the intersection; and the inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
在一个实施例中,根据二值图像中连通域的大小确定二值图像中标题的位置,包括:提取二值图像中的连通域;获取各连通域的短边长度;将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。In an embodiment, determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; The position of the long connected domain is determined as the position of the title in the binary image.
在一个实施例中,计算机可读指令使得一个或多个处理器执行对单证影像进行二值化处理得到二值图像之后,还执行以下步骤:根据二值图像中像素值的分布去除二值图像中的噪点。In one embodiment, the computer readable instructions cause one or more processors to perform binarization processing on the document image to obtain a binary image, and further perform the step of removing the binary value according to the distribution of pixel values in the binary image Noise in the image.
在一个实施例中,计算机可读指令使得一个或多个处理器执行根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像之后,还执行以下步骤:根据二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。In one embodiment, the computer readable instructions cause one or more processors to perform direction correction on the document image according to the tilt angle of the document image, and after obtaining the direction corrected document image, performing the following steps: The position of the border in the value image is redundantly cropped by the direction-corrected document image to obtain a redundantly cut document image.
上述存储介质,在获取待矫正的单证影像后,自动对该单证影像进行二值化处理得到二值图像,即可根据该二值图像确定单证影像边框的倾斜角以及单证影像标题的位置,从而根据单证影像边框的倾斜角和单证影像标题的位置确定单证影像的倾斜角,即可根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像,从而避免了人工矫正引入的工作量,极大地提高了影像矫正效率。After obtaining the document image to be corrected, the storage medium automatically binarizes the document image to obtain a binary image, and the tilt angle of the document image frame and the document image title can be determined according to the binary image. The position is determined according to the inclination angle of the document image frame and the position of the document image title, and the direction of the document image can be corrected according to the inclination angle of the document image, and the direction correction is obtained. The image is proofed, thus avoiding the workload introduced by manual correction and greatly improving the image correction efficiency.
在一个实施例中,提供了一种计算机设备,包括存储器和处理器,存储器中储存有计算机可读指令,计算机可读指令被处理器执行时,使得处理器执行以下步骤:获取待矫正的单证影像;对单证影像进行二值化处理得到二值图像;根据二值图像中像素值的分布确定二值图像中边框的倾斜角;根据二值图像中连通域的大小确定二值图像中标题的位置;根据边框的倾斜角和标题的位置,确定单证影像的倾斜角;根据单证影像的倾斜角对单证影像进 行方向矫正,获得经过方向矫正的单证影像。In one embodiment, a computer apparatus is provided, comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the processor to perform the step of: obtaining a single to be corrected The image is obtained by binarizing the document image to obtain a binary image; determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image; determining the binary image according to the size of the connected domain in the binary image The position of the title; the tilt angle of the document image is determined according to the tilt angle of the border and the position of the title; the image of the document is entered according to the tilt angle of the document image Correction of the direction of the line, obtaining a document image that has been corrected by direction.
在一个实施例中,根据二值图像中像素值的分布确定二值图像中边框的倾斜角,包括:根据二值图像中像素值的分布,提取二值图像中包含的直线;计算提取的直线之间形成的交点的坐标位置;根据交点的坐标位置确定二值图像中构成边框的直线;根据构成边框的直线的倾斜角确定边框的倾斜角。In one embodiment, determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image comprises: extracting a line included in the binary image according to the distribution of pixel values in the binary image; calculating the extracted straight line The coordinate position of the intersection formed between the two; the straight line constituting the frame in the binary image is determined according to the coordinate position of the intersection; and the inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
在一个实施例中,根据二值图像中连通域的大小确定二值图像中标题的位置,包括:提取二值图像中的连通域;获取各连通域的短边长度;将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。In an embodiment, determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises: extracting a connected domain in the binary image; acquiring a short side length of each connected domain; The position of the long connected domain is determined as the position of the title in the binary image.
在一个实施例中,计算机可读指令使得处理器执行对单证影像进行二值化处理得到二值图像之后,还执行以下步骤:根据二值图像中像素值的分布去除二值图像中的噪点。In one embodiment, the computer readable instructions cause the processor to perform binarization processing on the document image to obtain a binary image, and further perform the following steps: removing noise in the binary image according to the distribution of pixel values in the binary image .
在一个实施例中,计算机可读指令使得处理器执行根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像之后,还执行以下步骤:根据二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。In one embodiment, the computer readable instructions cause the processor to perform direction correction on the document image according to the tilt angle of the document image, and after obtaining the direction corrected document image, performing the following steps: according to the border in the binary image The location of the corrected image of the corrected image is redundantly cropped to obtain a redundantly cut document image.
上述计算机设备,在获取待矫正的单证影像后,自动对该单证影像进行二值化处理得到二值图像,即可根据该二值图像确定单证影像边框的倾斜角以及单证影像标题的位置,从而根据单证影像边框的倾斜角和单证影像标题的位置确定单证影像的倾斜角,即可根据单证影像的倾斜角对单证影像进行方向矫正,获得经过方向矫正的单证影像,从而避免了人工矫正引入的工作量,极大地提高了影像矫正效率。After obtaining the document image to be corrected, the computer device automatically binarizes the document image to obtain a binary image, and can determine the tilt angle of the document image frame and the document image title according to the binary image. The position is determined according to the inclination angle of the document image frame and the position of the document image title, and the direction of the document image can be corrected according to the inclination angle of the document image, and the direction correction is obtained. The image is proofed, thus avoiding the workload introduced by manual correction and greatly improving the image correction efficiency.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机程序来指令相关的硬件来完成,所述的程序可存储于一非易失性计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory,ROM)等。One of ordinary skill in the art can understand that all or part of the process of implementing the above embodiments can be completed by a computer program to instruct related hardware, and the program can be stored in a non-volatile computer readable storage medium. Wherein, the program, when executed, may include the flow of an embodiment of the methods as described above. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or the like.
以上所述实施例的各技术特征可以进行任意的组合,为使描述简洁,未 对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments may be combined in any combination, so that the description is concise, All possible combinations of the various technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope of the present specification.
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。 The above-mentioned embodiments are merely illustrative of several embodiments of the present application, and the description thereof is more specific and detailed, but is not to be construed as limiting the scope of the claims. It should be noted that a number of variations and modifications may be made by those skilled in the art without departing from the spirit and scope of the present application. Therefore, the scope of the invention should be determined by the appended claims.

Claims (20)

  1. 一种影像矫正方法,包括:An image correction method includes:
    获取待矫正的单证影像;Obtaining the document image to be corrected;
    对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
    根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
    根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
    根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
    根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  2. 根据权利要求1所述的方法,其特征在于,所述根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角包括:The method according to claim 1, wherein the determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image comprises:
    根据所述二值图像中像素值的分布,提取所述二值图像中包含的直线;Extracting a line included in the binary image according to a distribution of pixel values in the binary image;
    计算提取的所述直线之间形成的交点的坐标位置;Calculating a coordinate position of an intersection formed between the extracted straight lines;
    根据所述交点的坐标位置确定二值图像中构成边框的直线;及Determining a line constituting a frame in the binary image according to the coordinate position of the intersection; and
    根据所述构成边框的直线的倾斜角确定所述边框的倾斜角。The inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
  3. 根据权利要求1所述的方法,其特征在于,所述根据所述二值图像中连通域的大小确定所述二值图像中标题的位置包括:The method according to claim 1, wherein the determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises:
    提取所述二值图像中的连通域;Extracting a connected domain in the binary image;
    获取各所述连通域的短边长度;及Obtaining a short side length of each of the connected domains; and
    将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。The position of the connected domain having the longest length of the short side is determined as the position of the title in the binary image.
  4. 根据权利要求1所述的方法,其特征在于,所述对所述单证影像进行二值化处理得到二值图像之后还包括:The method according to claim 1, wherein the binarizing the image of the document to obtain a binary image further comprises:
    根据所述二值图像中像素值的分布去除所述二值图像中的噪点。The noise in the binary image is removed according to a distribution of pixel values in the binary image.
  5. 根据权利要求1所述的方法,其特征在于,所述根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像之后还包括: The method according to claim 1, wherein the correcting the direction of the document image according to the tilt angle of the document image, and obtaining the document image after the direction correction comprises:
    根据所述二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。According to the position of the border in the binary image, the direction-corrected document image is redundantly cropped to obtain a redundantly cut document image.
  6. 一种影像矫正装置,包括:An image correcting device comprising:
    获取模块,用于获取待矫正的单证影像;Obtaining a module for acquiring a document image to be corrected;
    处理模块,用于对所述单证影像进行二值化处理得到二值图像;a processing module, configured to perform binarization processing on the document image to obtain a binary image;
    确定模块,用于根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及a determining module, configured to determine a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image; determining a position of a header in the binary image according to a size of a connected domain in the binary image; Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
    矫正模块,用于根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The correction module is configured to perform direction correction on the document image according to the tilt angle of the document image, and obtain a document image that has undergone direction correction.
  7. 根据权利要求6所述的装置,其特征在于,所述确定模块还用于根据所述二值图像中像素值的分布,提取所述二值图像中包含的直线;计算提取的所述直线之间形成的交点的坐标位置;根据所述交点的坐标位置确定二值图像中构成边框的直线;及根据所述构成边框的直线的倾斜角确定所述边框的倾斜角。The apparatus according to claim 6, wherein the determining module is further configured to extract a line included in the binary image according to a distribution of pixel values in the binary image; and calculate the extracted straight line a coordinate position of the intersection formed therebetween; determining a straight line constituting the frame in the binary image according to the coordinate position of the intersection; and determining a tilt angle of the frame according to the inclination angle of the straight line constituting the frame.
  8. 根据权利要求6所述的装置,其特征在于,所述确定模块还用于提取所述二值图像中的连通域;获取各所述连通域的短边长度;及将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。The apparatus according to claim 6, wherein the determining module is further configured to extract a connected domain in the binary image; acquire a short side length of each connected domain; and have a longest corresponding short side length The position of the connected domain is determined as the position of the title in the binary image.
  9. 根据权利要求6所述的装置,其特征在于,所述处理模块还用于根据所述二值图像中像素值的分布去除所述二值图像中的噪点。The apparatus according to claim 6, wherein the processing module is further configured to remove noise in the binary image according to a distribution of pixel values in the binary image.
  10. 根据权利要求6所述的装置,其特征在于,所述矫正模块还用于根据所述二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。The device according to claim 6, wherein the correction module is further configured to perform redundant cutting on the direction-corrected document image according to the position of the border in the binary image, and obtain redundantly cropped Document image.
  11. 一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤: One or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the steps of:
    获取待矫正的单证影像;Obtaining the document image to be corrected;
    对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
    根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
    根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
    根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
    根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  12. 根据权利要求11所述的存储介质,其特征在于,所述根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角包括:The storage medium according to claim 11, wherein the determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image comprises:
    根据所述二值图像中像素值的分布,提取所述二值图像中包含的直线;Extracting a line included in the binary image according to a distribution of pixel values in the binary image;
    计算提取的所述直线之间形成的交点的坐标位置;Calculating a coordinate position of an intersection formed between the extracted straight lines;
    根据所述交点的坐标位置确定二值图像中构成边框的直线;及Determining a line constituting a frame in the binary image according to the coordinate position of the intersection; and
    根据所述构成边框的直线的倾斜角确定所述边框的倾斜角。The inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
  13. 根据权利要求11所述的存储介质,其特征在于,所述根据所述二值图像中连通域的大小确定所述二值图像中标题的位置包括:The storage medium according to claim 11, wherein the determining the position of the title in the binary image according to the size of the connected domain in the binary image comprises:
    提取所述二值图像中的连通域;Extracting a connected domain in the binary image;
    获取各所述连通域的短边长度;及Obtaining a short side length of each of the connected domains; and
    将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。The position of the connected domain having the longest length of the short side is determined as the position of the title in the binary image.
  14. 根据权利要求11所述的存储介质,其特征在于,所述计算机可读指令使得一个或多个处理器执行对所述单证影像进行二值化处理得到二值图像之后执行以下步骤:The storage medium according to claim 11, wherein the computer readable instructions cause the one or more processors to perform binarization processing on the document image to obtain a binary image, and then perform the following steps:
    根据所述二值图像中像素值的分布去除所述二值图像中的噪点。The noise in the binary image is removed according to a distribution of pixel values in the binary image.
  15. 根据权利要求11所述的存储介质,其特征在于,所述计算机可读指令使得一个或多个处理器执行根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像之后执行以下步骤:The storage medium according to claim 11, wherein the computer readable instructions cause one or more processors to perform direction correction on the document image according to a tilt angle of the document image to obtain a passing direction Perform the following steps after correcting the document image:
    根据所述二值图像中边框的位置,对经过方向矫正的单证影像进行冗余 裁剪,获得经过冗余裁剪的单证影像。Redundancy of the direction-corrected document image according to the position of the border in the binary image Crop to obtain a redundantly cropped document image.
  16. 一种计算机设备,包括存储器和处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述处理器执行以下步骤:A computer device comprising a memory and a processor, the memory storing computer readable instructions, the computer readable instructions being executed by the processor such that the processor performs the following steps:
    获取待矫正的单证影像;Obtaining the document image to be corrected;
    对所述单证影像进行二值化处理得到二值图像;Performing binarization processing on the document image to obtain a binary image;
    根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角;Determining a tilt angle of a border in the binary image according to a distribution of pixel values in the binary image;
    根据所述二值图像中连通域的大小确定所述二值图像中标题的位置;Determining a position of a title in the binary image according to a size of a connected domain in the binary image;
    根据所述边框的倾斜角和所述标题的位置,确定所述单证影像的倾斜角;及Determining a tilt angle of the document image according to a tilt angle of the frame and a position of the title; and
    根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像。The direction of the document image is corrected according to the tilt angle of the document image, and the document image corrected by the direction is obtained.
  17. 根据权利要求16所述的计算机设备,其特征在于,所述根据所述二值图像中像素值的分布确定所述二值图像中边框的倾斜角包括:The computer device according to claim 16, wherein the determining the tilt angle of the border in the binary image according to the distribution of the pixel values in the binary image comprises:
    根据所述二值图像中像素值的分布,提取所述二值图像中包含的直线;Extracting a line included in the binary image according to a distribution of pixel values in the binary image;
    计算提取的所述直线之间形成的交点的坐标位置;Calculating a coordinate position of an intersection formed between the extracted straight lines;
    根据所述交点的坐标位置确定二值图像中构成边框的直线;及Determining a line constituting a frame in the binary image according to the coordinate position of the intersection; and
    根据所述构成边框的直线的倾斜角确定所述边框的倾斜角。The inclination angle of the frame is determined according to the inclination angle of the straight line constituting the frame.
  18. 根据权利要求16所述的计算机设备,其特征在于,所述根据所述二值图像中连通域的大小确定所述二值图像中标题的位置包括:The computer device according to claim 16, wherein the determining the location of the title in the binary image according to the size of the connected domain in the binary image comprises:
    提取所述二值图像中的连通域;Extracting a connected domain in the binary image;
    获取各所述连通域的短边长度;及Obtaining a short side length of each of the connected domains; and
    将对应短边长度最长的连通域的位置,确定为二值图像中标题的位置。The position of the connected domain having the longest length of the short side is determined as the position of the title in the binary image.
  19. 根据权利要求16所述的计算机设备,其特征在于,所述计算机可读指令使得处理器执行对所述单证影像进行二值化处理得到二值图像之后执行以下步骤:The computer apparatus according to claim 16, wherein the computer readable instructions cause the processor to perform a binarization process on the document image to obtain a binary image, and then perform the following steps:
    根据所述二值图像中像素值的分布去除所述二值图像中的噪点。 The noise in the binary image is removed according to a distribution of pixel values in the binary image.
  20. 根据权利要求16所述的计算机设备,其特征在于,所述计算机可读指令使得处理器执行根据所述单证影像的倾斜角对所述单证影像进行方向矫正,获得经过方向矫正的单证影像之后执行以下步骤:The computer apparatus according to claim 16, wherein the computer readable instructions cause the processor to perform direction correction on the document image according to a tilt angle of the document image to obtain a direction corrected document Perform the following steps after the image:
    根据所述二值图像中边框的位置,对经过方向矫正的单证影像进行冗余裁剪,获得经过冗余裁剪的单证影像。 According to the position of the border in the binary image, the direction-corrected document image is redundantly cropped to obtain a redundantly cut document image.
PCT/CN2017/104659 2017-07-25 2017-09-29 Image correction method and apparatus, storage medium and computer device WO2019019383A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710612985.7 2017-07-25
CN201710612985.7A CN107680046A (en) 2017-07-25 2017-07-25 Image rectification method, device, storage medium and computer equipment

Publications (1)

Publication Number Publication Date
WO2019019383A1 true WO2019019383A1 (en) 2019-01-31

Family

ID=61133805

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/104659 WO2019019383A1 (en) 2017-07-25 2017-09-29 Image correction method and apparatus, storage medium and computer device

Country Status (2)

Country Link
CN (1) CN107680046A (en)
WO (1) WO2019019383A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109815954A (en) * 2019-01-31 2019-05-28 科大讯飞股份有限公司 Correction for direction method, apparatus, equipment and the storage medium of VAT invoice image

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080025641A1 (en) * 2006-07-25 2008-01-31 Samsung Electronics Co., Ltd Apparatus and method to rotate a bitmap image
CN101662581A (en) * 2009-09-09 2010-03-03 谭洪舟 Multifunctional certificate information collection system
CN101770575A (en) * 2008-12-31 2010-07-07 汉王科技股份有限公司 Method and device for measuring image inclination angle of business card
CN105405054A (en) * 2015-12-11 2016-03-16 平安科技(深圳)有限公司 Insurance claim antifraud implementation method based on claim photo deep learning and server
CN105869085A (en) * 2016-03-29 2016-08-17 河北师范大学 Transcript inputting system and method for processing images

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102496018B (en) * 2011-12-08 2013-07-24 方正国际软件有限公司 Document skew detection method and system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080025641A1 (en) * 2006-07-25 2008-01-31 Samsung Electronics Co., Ltd Apparatus and method to rotate a bitmap image
CN101770575A (en) * 2008-12-31 2010-07-07 汉王科技股份有限公司 Method and device for measuring image inclination angle of business card
CN101662581A (en) * 2009-09-09 2010-03-03 谭洪舟 Multifunctional certificate information collection system
CN105405054A (en) * 2015-12-11 2016-03-16 平安科技(深圳)有限公司 Insurance claim antifraud implementation method based on claim photo deep learning and server
CN105869085A (en) * 2016-03-29 2016-08-17 河北师范大学 Transcript inputting system and method for processing images

Also Published As

Publication number Publication date
CN107680046A (en) 2018-02-09

Similar Documents

Publication Publication Date Title
WO2020140698A1 (en) Table data acquisition method and apparatus, and server
US10176395B2 (en) Automatic correction of skewing of digital images
TWI425444B (en) Method and device for detecting and correcting skewed image data
WO2014160433A2 (en) Systems and methods for classifying objects in digital images captured using mobile devices
US20170372156A1 (en) Table data recovering in case of image distortion
KR101434776B1 (en) Method and apparatus for correcting corner point of image and image processing device
US9077926B2 (en) Image processing method and image processing apparatus
JP2014147046A (en) Image processing apparatus, image processing method, and computer program
JP6542230B2 (en) Method and system for correcting projected distortion
JP5984880B2 (en) Image processing device
WO2019019383A1 (en) Image correction method and apparatus, storage medium and computer device
JP4970385B2 (en) Two-dimensional code reader and program thereof
CN108647680B (en) Image positioning frame detection method and device
US11570331B2 (en) Image processing apparatus, image processing method, and storage medium
JP2004086436A (en) Image processor, image processing method, program, and storage medium
JP2012095173A (en) Image processing device, image formation device, and image processing method
JP4872895B2 (en) Face centerline detection device
JP5453215B2 (en) Image processing apparatus, image forming apparatus, and image processing method
JP2019174887A (en) Image processing device
JP6226206B2 (en) Image processing apparatus, image processing method, and image processing program
JP6810892B2 (en) Image processing device
TW202425615A (en) Duplex document copying system and method thereof
JP6573124B2 (en) Image processing device
CN110569847A (en) Character inclination angle determining method, character inclination correcting method and computer
JP4829757B2 (en) Ruled line extraction apparatus and method

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17918758

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17918758

Country of ref document: EP

Kind code of ref document: A1