0
0

More than 1 year has passed since last update.

斜めに置かれた書類をまっすぐにしたい。画像変形する技術がすごい

Posted at

ドキュメントスキャナーのような画像変形を行う方法です。

Feb-27-2022 23-14-57

おいた書類をまっすぐに切り取りたい

書類などを机に置いて斜めから撮影すると、台形に移ります。
これをまっすぐな長方形にするには、画像を変形させる必要があります。

DDPerspectiveTransformが使える

ライブラリを使えば、手動で簡単に画像を整形できるUIがつかえます。

使い方

DDPerspectiveTransformをプロジェクトに入れ、UIを表示します。

let cropViewController = DDPerspectiveTransformViewController()
cropViewController.delegate = self
cropViewController.image = image
self.navigationController?.pushViewController(cropViewController, animated: true)

クロップボタンは付いていないので、ボタンを追加してDDPerspectiveTransformViewControllerのcropActionを追加します。
整形した画像はデリゲートで受け取れます。

func perspectiveTransformingDidFinish(controller: DDPerspectiveTransformViewController, croppedImage: UIImage) {
    self.imageView.image = croppedImage
}

文字の角度も綺麗に整形されます。

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0