页面图片如何被整理成看起来好像被扫描了? [英] How can picture of page be straightened out to look as if it was scanned?
问题描述
我见过应用程序,并想知道如何以编程方式拍摄图像。定义它需要如何转换,使其看起来与相机平行,而不是倾斜的视角。
然后合并多张照片以创建pdf文件。例如,此应用可以执行此操作:
- 输入图片
-
查找主要轮廓
理想情况下整个网格,但即使外部轮廓也足够(如果不存在网格)。您需要将轮廓分为水平(红色)和垂直(绿色)曲线(或一组点)。
-
样本轮廓曲线按4 等距点
由于图像失真(不仅仅是旋转),我们需要至少使用双三次插值。为此,我们需要每个补丁16点(Aqua)。
-
添加镜像点以覆盖整个网格
$ b图像上的
$ b是镜像(黄色)点,仅适用于水平轮廓,对于垂直轮廓也应该这样做(不适合我在图像中,并且不想为此扩大分辨率)和还有角点,所以你得到
6x6
控制点。镜子可以线性完成(就像我一样)。
现在转换完成如下:
- 处理所有像素
dst(x0,y0)
目标图像 -
处理
x,y
作为三次插值的参数
如果
xs,ys
是目标图像分辨率,那么:u =(3.0 * x)/ xs
v =(3.0 * y)/ ys
现在,立方插值通常在参数
t =< 0.0,1.0)
上完成,所以
如果u =< 0.0,1.0>
使用t = u
和控制点0 ,1,2,3-
。
如果u =< 1.0,2.0)
使用t = u-1.0
并控制积分1,2,3,4
如果u =< 2.0,3.0>
使用t = u-2.0
和控制点2,3,4,5
纵向轮廓和
v
也是如此。计算xi,yi
作为(u,v)
的双三次插值。并复制像素:dst(x,y)= src(xi,yi);
这只是最近邻居,但你也可以使用双线性...作为立方曲线我会使用此多项式。
双三次插值背后的想法简单。在4个水平轮廓上对应于参数
u
的计算点。这将为您提供4个垂直方向的最终三次插值控制点和v
作为参数。结果坐标是您的源像素位置。
有关详细信息,请参阅:
- 如何生成多点线性插值?
- 双立方插值
- < a href =https://stackoverflow.com/a/39316776/2521214> OpenCV Birdseye视图,不会丢失数据
如果您没有网格,请使用可以作为一个网格使用的任何信息。例如,文本行可以被视为此轮廓...
I have seen apps, and wondered how can I programmatically take a picture of image. Define how it needs to be transformed so that it looks parallel to camera and not skewed perspective wise.
Then combine multiple photos to create a pdf file. For example this app does it: https://play.google.com/store/apps/details?id=com.appxy.tinyscan&hl=en
I do not use books for such trivial things so sorry I can not recommend any (especially in English). What you need to do is this:
- input image
find main contours
ideally whole grid but even outer contour will suffice (in case no grid is present). You need to divide the contour into horizontal (Red) and vertical (Green) curves (or set of points).
sample contour curves by 4 "equidistant" points
as the image is distorted (not just rotated) then we need to use at least bi-cubic interpolation. For that we need 16 points (Aqua) per patch.
add mirror points to cover whole grid
on the image are mirrored (Yellow) points only for horizontal contours you should do this also for vertical contours (did not fit me in the image and did not want to enlarge resolution just for that) and also for the corner points so you got
6x6
control points. The mirror can be done linearly (like I did).
Now the transformation is done like this:
- Process all pixels
dst(x0,y0)
of target image Handle
x,y
as parameter for cubic interpolationif
xs,ys
is target image resolution then:u=(3.0*x)/xs v=(3.0*y)/ys
Now cubic interpolation is usually done on parameter
t=<0.0,1.0)
so
ifu=<0.0,1.0>
uset=u
and control points0,1,2,3
.
ifu=<1.0,2.0)
uset=u-1.0
and control points1,2,3,4
ifu=<2.0,3.0>
uset=u-2.0
and control points2,3,4,5
The same goes for vertical contours and
v
. Computexi,yi
as bi cubic interpolation of(u,v)
. And copy pixel:dst(x,y)=src(xi,yi);
This is just nearest neighbor but you can also use bilinear for this ... As cubic curve I would use this polynomial.
The idea behind bi-cubic interpolation is easy. compute point corresponding to parameter
u
on 4 horizontal contours. That will give you 4 control points for the final cubic interpolation in vertical direction andv
as parameter. Resulting coordinate is your source pixel position.
For more info see:
- How can i produce multi point linear interpolation?
- Bicubic interpolation
- OpenCV Birdseye view without loss of data
In case you do not have a grid use any info that can be used as one. For example lines of text can be considered a contour for this ...
这篇关于页面图片如何被整理成看起来好像被扫描了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!