从点对 UIImage 进行透视校正
我正在开发一个应用程序,让用户拍照,例如名片或照片。
然后,用户将标记对象的四个角(他们将其拍下来) - 就像在许多文档/图像/名片扫描应用程序中看到的那样:
我的问题是如何根据这四点裁剪并修复视角?我已经搜索了好几天并查看了几个图像处理库,但没有任何运气。
谁能指出我正确的方向?
I'm working on a app where I'll let the user take a picture e.g of a business card or photograph.
The user will then mark the four corners of the object (which they took a picture off) - Like it is seen in a lot of document/image/business card scanning apps:
My question is how do i crop and fix the perspective according to these four points? I've been searching for days and looked at several image proccessing libraries without any luck.
Any one who can point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
从 iOS8+ 开始,核心图像过滤器名为 CIPerspectiveCorrection。您所需要做的就是传递图像和四个点。
另外还有一个支持 iOS6+ 的过滤器,称为 CIPerspectiveTransform 可以以类似的方式使用(倾斜图像)。
From iOS8+ there is Filter for Core Image called CIPerspectiveCorrection. All you need to do is pass the image and four points.
Also there is one more filter supporting iOS6+ called CIPerspectiveTransform which can be used in similar way (skewing image).
如果将此图像作为纹理加载,则使用 OpenGL 对其进行倾斜将非常简单。实际上,您只需绘制一个全屏四边形并使用黄色校正点作为每个点的 UV 坐标。
If this image were loaded in as a texture, it'd be extremely simple to skew it using OpenGL. You'd literally just draw a full-screen quad and use the yellow correction points as the UV coordinate at each point.
我不确定您是否已经尝试过 Opencv 库,但它有一个非常好的方法来校正图像。我这里有一个小片段,它需要一系列角,例如四个角,以及将其映射到的最终尺寸。
您可以阅读 warpPerspective 的手册页 OpenCV 网站。
I'm not sure if you've tried the Opencv library yet, but it has a very nice way to deskew an image. I've got here a small snippet that takes an array of corners, your four corners for example, and a final size to map it into.
You can read the man page for warpPerspective on the OpenCV site.
我不知道您的情况的确切解决方案,但有梯形的方法: http://www.comp.nus.edu.sg/~tants/tsm/TSM_recipe.html - 这个想法是不断构建变换矩阵。理论上,您可以添加将形状转换为梯形的变换。
还有很多这样的问题: https://math.stackexchange.com/ questions/13404/mapping-irregular-quadriside-to-a-rectangle ,但我没有检查解决方案。
I don't know exact solution of your case, but there is approach for trapezoid: http://www.comp.nus.edu.sg/~tants/tsm/TSM_recipe.html - the idea is to continuously build transformation matrix. Theoretically you can add transformation that converts your shape into trapecy.
And there are many questions like this: https://math.stackexchange.com/questions/13404/mapping-irregular-quadrilateral-to-a-rectangle , but I didn't check solutions.