Cropping UIImage like camscanner

前端 未结 3 1833
你的背包
你的背包 2020-12-24 09:06

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.

3条回答
  •  伪装坚强ぢ
    2020-12-24 09:37

    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.

    <> you can use OpenGL .

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

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

    1. cvPerspectiveTransform

    2. cvWarpPerspective

    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.

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

    iOS application with opencv library is available at eosgarden.

提交回复
热议问题