0
1

More than 1 year has passed since last update.

ARKitのCapturedFrameをVisionなどで解析してARインタラクションを作る場合があるが、
この際ARKitSessionDelegateで取得できるフレームとディスプレイに表示されているフレームの領域が違うことがある。(キャプチャされた一部分を表示していることがある)

例えば、iPhone11ではディスプレイが 414x896 だが、キャプチャしたフレームサイズは 1440x1920 である。

ディスプレイ内にフレーム縦幅は全て収まっているが、横は中心部しか収まっていない。

スクリーンショット 2022-03-03 22.48.10.png

ディスプレイに表示されている領域でフレームをクロップするコード。

func session(_ session: ARSession, didUpdate frame: ARFrame) {
    let pixelBuffer = frame.capturedImage
    let ciImage = CIImage(cvPixelBuffer: pixelBuffer, options: [:]).oriented(.right)
    let aspect =  arView.bounds.width / arView.bounds.height
    let widthForDisplayAspect = ciImage.extent.height * aspect
    let cropped = ciImage.cropped(to: CGRect(x: ciImage.extent.width/2-widthForDisplayAspect/2, y: 0, width: widthForDisplayAspect, height: ciImage.extent.height))
}

これを解析すれば、ディスプレイ表示されたフレームを基準に解析できる。

🐣


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

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

Twitter
Medium
GitHub

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