像camscanner一样裁剪UIImage [英] Cropping UIImage like camscanner

查看:175
本文介绍了像camscanner一样裁剪UIImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了我的应用功能。我想要裁剪功能类似于Cam Scanner Cropping。
CAM-SCANNER的屏幕是:
我创建了类似的裁剪视图。

I am stuck in my application feature. I want cropping feature similar to Cam Scanner Cropping. The screens of CAM-SCANNER are: I have created similar crop view.

我已获得四角的CGPoint。
但我如何才能获得倾斜的裁剪图像。

如果可能,请提供一些建议。

Please provide me some suggestions if possible.

推荐答案

这是透视变换问题。在这种情况下,他们正在2D平面上绘制3D投影。

This is a perspective transform problem. In this case they are plotting a 3D projection in a 2D plane.

因为,第一个图像具有四边形的选择角,当您将其转换为矩形时,那么您将需要添加更多像素信息(插值)或删除一些像素。

As, the first image has selection corners in quadrilateral shape and when you transform it in a rectangular shape, then you will either need to add more pixel information(interpolation) or remove some pixels.

所以现在的实际问题是为裁剪的图像添加额外的像素信息并将其投影以生成第二张图像。它可以通过多种方式实现:

So now actual problem is to add additional pixel information to cropped image and project it to generate second image. It can be implemented in various ways:

<>您可以通过应用带插值的透视变换矩阵来实现它。

<> you can implement it by your own by applying perspective tranformation matrix with interpolation.

<>您可以使用 OpenGL

<> you can use OpenGL .

<>您可以使用 OpenCV
..还有很多方法可以实现它。

<> you can use OpenCV. .. and there are many more ways to implement it.

我使用OpenCV解决了这个问题。以下OpenCV中的函数将帮助您实现此目的。

I had solved this problem using OpenCV. Following functions in OpenCV will help you to achieve this.


  1. cvPerspectiveTransform

cvWarpPerspective

首先函数将使用源和目标投影坐标计算变换矩阵。在你的情况下,src数组将包含来自CGPoint的所有角落的值。并且dest将具有矩形投影点,例如{(0,0)(200,0)(200,150)(0,150)}。

First function will calculate transformation matrix using source and destination projection coordinates. In your case src array will have values from CGPoint for all the corners. And dest will have rectangular projection points for example {(0,0)(200,0)(200,150)(0,150)}.

一旦获得变换矩阵,您将需要将它传递给第二个功能。您可以访问此 主题

Once you get transformation matrix you will need to pass it to second function. you can visit this thread.

OpenCV库可能没有其他替代方案,但它有很好的图像处理算法集合。

There may be few other alternatives to OpenCV library, but it has good collection of image processing algorithms.

带有opencv库的iOS应用程序可用在 eosgarden

iOS application with opencv library is available at eosgarden.

这篇关于像camscanner一样裁剪UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆