0
2

More than 1 year has passed since last update.

画像内の四角形を検出する方法です

スクリーンショット 2022-02-24 2.58.55.png

書類や標識の検出に

四角形の人工物を検出できれば、場面に応じて様々な用途に活かせそうです。
例えば、ドキュメント内の四角形の検出など。

Visionの四角形検出が使える

方法

画像にVNDetectRectangleRequestをするだけです。

let request = VNDetectRectanglesRequest()
let handler = VNImageRequestHandler(ciImage: ciImage!, options: [:])
try! handler.perform([request])
guard let results = request.results else { return }

for result in results {
    print("topLeft: \(result.topLeft)")
    print("topRight: \(result.topRight)")
    print("bottomLeft: \(result.bottomLeft)")
    print("bottomRight: \(result.bottomRight)")
    print("boundingBox: \(result.boundingBox)")
}

topLeft: (0.37335851788520813, 0.5885436534881592)
topRight: (0.5980302095413208, 0.6653665900230408)

bottomLeft: (0.45727139711380005, 0.16498719155788422)
bottomRight: (0.7020156383514404, 0.26323217153549194)

boundingBox: (0.37335851788520813, 0.16498719155788422, 0.3286571204662323, 0.5003793984651566)

画像内の正規化座標を取得できます。
Y座標は、画像の下が基準になっています。

スクリーンショット 2022-02-24 2.30.04.png

🐣


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

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

Twitter
Medium

0
2
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
2