1 基于Radon变换
1.1 radon原理
二维Radon变换定义:
将(x,y)平面空间中的一条直线
p
=
x
cos
θ
+
y
sin
θ
p=x\cos\theta+y\sin\theta
p=xcosθ+ysinθ映射成Radon空间的一个点
(
p
,
θ
)
(p,\theta)
(p,θ),
连续图像的Radon变换为:
R
(
p
,
θ
)
=
∬
D
f
(
x
,
y
)
δ
(
p
−
x
cos
θ
−
y
sin
θ
)
d
x
d
y
R(p,\theta)=\iint_D f(x,y) \delta(p-x\cos\theta-y\sin\theta) \,dx\,dy
R(p,θ)=∬Df(x,y)δ(p−xcosθ−ysinθ)dxdy;
其中
δ
(
x
)
=
{
0
x!=0
1
x=0
\delta(x)_=\begin{cases}0& \text{x!=0}\\1& \text{x=0}\end{cases}
δ(x)={01x!=0x=0。
通过randon变换可以计算出该二值图片在每个方向上每条直线的值,由上面的公式可以知道如果在这条直线上的文字越多其值越大,因此最大值所在的角度即是文字的倾斜角度。
1.2 代码实现
import cv2
import sys
import time
import numpy as np
from skimage.transform import radon
img = cv2.imread('C:/Users/64975/Desktop/test_image/tt.png')
# h = 900
# ratio = img.shape[0] / h
# w = img.shape[1] / ratio
# orig = img.copy()
# resize_image = cv2.resize(orig, (int(w), h))
I = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
h, w = I.shape
(cX, cY) = (w // 2, h // 2)
if (w > 240):
I = cv2.resize(I, (240, int((h / w) * 240)))
I = I - np.mean(I)
sinogram = radon(I)
r = np.array([np.sqrt(np.mean(np.abs(line) ** 2)) for line in sinogram.transpose()])
rotation = np.argmax(r)
print('Rotation: {:.2f} degrees'.format(90 - rotation))
# Rotate and save with the original resolution
M = cv2.getRotationMatrix2D((w/2, h/2), 90 - rotation, 1)
cos = np.abs(M[0, 0])
sin = np.abs(M[0, 1])
nW = int((h * sin) + (w * cos))
nH = int((h * cos) + (w * sin))
M[0, 2] += (nW / 2) - cX
M[1, 2] += (nH / 2) - cY
dst = cv2.warpAffine(img, M, (nW, nH))
cv2.imwrite('C:/Users/64975/Desktop/test_image/out_image.jpg', dst)
cv2.imwrite('rotated.jpg', dst)
cv2.imshow('dst', dst)
cv2.waitKey()
1.3 效果






2 基于DewarpNet和DocUNet
2.1 论文调研
经过调研发现,TextIn的切边增强和弯曲矫正技术很强,他的技术参考的论文为DocUNet和DewarpNet。
DocUNet的代码地址:https://github.com/teresasun/docUnet.pytorch。
DewarpNet的代码地址:https://github.com/cvlab-stonybrook/DewarpNet。
2.2 论文效果
DocUNet:
DewarpNet:
2.3 测试效果
DocUNet提供的代码中没有训练好的模型,需要自己手动训练且从论文中可以看出DewarpNet的效果优于DocUNet,所以只对DewarpNet进行了测试。
test1:


test2:


test3:


test4:


test5:


2.4 OCR识别效果
test1:


test2:


test3:


test4:


test5:


3 Learning From Documents in the Wild to Improve Document Unwarping
论文地址:https://dl.acm.org/doi/abs/10.1145/3528233.3530756
代码地址:https://github.com/cvlab-stonybrook/PaperEdge
该模型分为两部分:大小都为139M。
3.1 模型效果










4 Geometric Representation Learning for Document Image Rectification
论文地址:https://arxiv.org/pdf/2210.08161.pdf
代码地址:https://github.com/fh2019ustc/DocGeoNet
该模型分为两部分:预处理模型为4M,另一部分为90M。
4.1 模型效果










5 opencv边缘检测
- 利用opencv提取文档轮廓
- 画出最小外接矩阵
5.1 效果测试
test1:图片有明显边界
test2:图片没有明显边界
6 Document_Scanner
6.1 基于几何矫正
6.2 基于深度学习:Semantic Segmentation using PyTorch-DeepLabV3
6.2.1 矫正效果
test1:文档有完整边界
test1:文档没有完整边界