カメラの設定

CameraConfig では、次のような、基盤となるカメラセンサーのプロパティについて説明します。

  • カメラ ID
  • 深度センサーが使用されるかどうか(使用可能な場合)
  • カメラの向き:
    • 正面(自撮り)
    • 背面(ワールド)
  • FPS(フレーム/秒)の範囲
  • CPU イメージのサイズ
  • GPU テクスチャの次元
  • 存在する場合、デバイスのステレオ マルチカメラを使用するかどうか

新しい ARCore セッションを作成する際、ARCore は setCameraConfig を使用して、getSupportedCameraConfigs(CameraConfigFilter) から返される利用可能な設定のリストに最適なカメラ設定を設定します。アプリでは、CameraConfigFilter を使用してアプリのニーズに基づいてフィルタリングすることで、実行時に特定のデバイスで使用可能なカメラ構成を絞り込むことができます。

フィルタリングの一般的な使用例は次のとおりです。

  • カメラのキャプチャ フレームレートを 30 fps に制限する。60 fps をサポートするデバイスでは、ARCore はそのフレームレートをサポートするカメラ設定を優先します。60 fps をサポートするすべてのカメラ構成を除外するには、TargetFps.TARGET_FPS_30 を使用して setTargetFps でフィルタを適用します。

    Java

    // Return only camera configs that target 30 FPS camera capture frame rate.
    filter.setTargetFps(EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30));

    Kotlin

    // Return only camera configs that target 30 FPS camera capture frame rate.
    filter.targetFps = EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30)

  • ARCore が奥行きセンサーを使わないようにするサポートされている深度センサーを搭載したデバイスでは、ARCore は奥行きセンサーを使用するカメラ構成を優先します。奥行きセンサーを使用するすべてのカメラ構成を除外するには、DepthSensorUsage.DO_NOT_USE を使用して setDepthSensorUsage フィルタを適用します。

    Java

    // Return only camera configs that will not use the depth sensor.
    filter.setDepthSensorUsage(EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE));

    Kotlin

    // Return only camera configs that will not use the depth sensor.
    filter.depthSensorUsage = EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE)

  • 代替 GPU テクスチャ解像度の選択サポートされているデバイスでは、ARCore によって追加の GPU テクスチャ解像度が提供される場合があります。低解像度の GPU テクスチャを選択すると、GPU の負荷が軽減され、メモリ帯域幅の要件が軽減されるため、アプリのパフォーマンスを改善できる可能性があります。ただし、すべてのケースでパフォーマンスが向上するとは限りません。

カメラ構成フィルタの使用

アプリでカメラ構成をフィルタできるようにするには、次の手順を行います。

Java

// Create a camera config filter for the session.
CameraConfigFilter filter = new CameraConfigFilter(session);

// Return only camera configs that target 30 fps camera capture frame rate.
filter.setTargetFps(EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30));

// Return only camera configs that will not use the depth sensor.
filter.setDepthSensorUsage(EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE));

// Get list of configs that match filter settings.
// In this case, this list is guaranteed to contain at least one element,
// because both TargetFps.TARGET_FPS_30 and DepthSensorUsage.DO_NOT_USE
// are supported on all ARCore supported devices.
List<CameraConfig> cameraConfigList = session.getSupportedCameraConfigs(filter);

// Use element 0 from the list of returned camera configs. This is because
// it contains the camera config that best matches the specified filter
// settings.
session.setCameraConfig(cameraConfigList.get(0));

Kotlin

// Create a camera config filter for the session.
val filter = CameraConfigFilter(session)

// Return only camera configs that target 30 fps camera capture frame rate.
filter.targetFps = EnumSet.of(CameraConfig.TargetFps.TARGET_FPS_30)

// Return only camera configs that will not use the depth sensor.
filter.depthSensorUsage = EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE)

// Get list of configs that match filter settings.
// In this case, this list is guaranteed to contain at least one element,
// because both TargetFps.TARGET_FPS_30 and DepthSensorUsage.DO_NOT_USE
// are supported on all ARCore supported devices.
val cameraConfigList = session.getSupportedCameraConfigs(filter)

// Use element 0 from the list of returned camera configs. This is because
// it contains the camera config that best matches the specified filter
// settings.
session.cameraConfig = cameraConfigList[0]

フォーカス モード

セッション構成でフォーカス モードを設定することもできます。固定フォーカスは、一般的にトラッキングに適しています(ほとんどのデバイスで ARCore のデフォルトです)。 録画、写真撮影、動画撮影、近くの物体へのフォーカスが必要な場合は、オート フォーカスが必要になります。

詳しくは、Config.FocusMode をご覧ください。