Affine Transform, Simple Rotation and Scaling or something else entirely?(仿射变换、简单旋转和缩放或其他完全不同的东西?)
问题描述
场景是这样的:我有一张纸的图片,我想做一些 OCR.所以以下面的图片作为我的输入示例:
The scenario goes like this: I have a picture of a paper that I would like to do some OCR. So take the image below as my input example:
在成功检测到与纸张对应的区域后,我留下了一个 vector
的 4 个坐标,用于定义其在图像内的位置.请注意,由于拍摄照片时相机的距离和角度,这些坐标可能不会对应于完美的矩形.出于查看目的,我连接了子图像中的点,以便您了解我的意思:
After successfully detecting the area that corresponds to the paper I'm left with a vector<Point>
of 4 coordinates that define its location inside the image. Note that these coordinates will probably not correspond to a perfect rectangle due to the distance of the camera and angle when the picture was taken. For viewing purposes I connected the points in the sub-image so you can see what I mean:
在这种情况下,点是: [1215, 43] , [52, 67] , [56, 869] 和 [1216, 884]
In this case, the points are: [1215, 43] , [52, 67] , [56, 869] and [1216, 884]
此时,我需要调整这些点,使它们水平对齐.我是什么意思?如果您注意到上面子图像的区域,它会稍微旋转:图像右侧的点比另一侧的点略高.
At this moment, I need to adjust these points so they become aligned horizontally. What do I mean by that? If you notice the area of the sub-image above, it is a little rotated: the points on right side of the image are positioned a little higher than points on the other side.
换句话说,我们有图像A,它被故意夸大以看起来比现实更扭曲/旋转,然后是图像B - 这就是我想作为这个程序的最终结果:
In other words, we have image A, which was exaggerated on purpose to look a little more distorted/rotated than reality, and then image B - which is what I would like as the final result of this procedure:
A) B)
我不确定哪些技术可用于实现这种转变.应用程序还需要自动检测需要完成多少旋转,因为我无法控制图像采集过程.
I'm not sure which techniques could be used to achieve this transformation. The application also needs to detect automatically how much rotation needs to be done, as I don't have control over the image acquisition procedure.
目的是拥有一个带有标准化子图像的新Mat
.我现在并不担心可能的图像失真,我只是在寻找一种方法来确定需要在子图像上进行多少旋转以及如何应用它并获得更多矩形区域.
The purpose is to have a new Mat
with the normalized sub-image. I'm not worried about a possible image distortion right now, I'm just looking for a way to identify how much rotation needs to be done on the sub-image and how to apply it and get a more rectangular area.
推荐答案
我认为 http://felix.abecassis.me/2011/10/opencv-rotation-deskewing/ 和 http://felix.abecassis.me/2011/10/opencv-bounding-box-skew-angle/ 会派上用场.上述帖子不包括透视扭曲(仅旋转).为了获得最佳结果,您必须使用 warpPerspective
(可能与 getRotationMatrix2D
结合使用).使用线段之间的角度来确定需要多少扭曲透视.这里的假设是它们应该始终为 90 度,并且就透视而言,最接近 90 度的向量是最近的"向量.
I think http://felix.abecassis.me/2011/10/opencv-rotation-deskewing/ and http://felix.abecassis.me/2011/10/opencv-bounding-box-skew-angle/ will come in handy. The aforementioned posts don't cover perspective warping (only rotation). To get the best results, you'll have to use warpPerspective
(maybe in conjunction with getRotationMatrix2D
). Use the angles between line segments to find out how much you need to warp the perspective. THe assumption here is that they should always be 90 degrees and that the closest one to 90 degrees is the "closest" vector as far as the perspective is concerned.
不要忘记归一化你的向量!
Don't forget to normalize your vectors!
这篇关于仿射变换、简单旋转和缩放或其他完全不同的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:仿射变换、简单旋转和缩放或其他完全不同的东
基础教程推荐
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01