กำลังกำหนดค่ากล้อง

CameraConfig อธิบายคุณสมบัติของเซ็นเซอร์กล้องที่อยู่ด้านล่าง ซึ่งรวมถึง

  • รหัสกล้อง
  • หากมี จะใช้เซ็นเซอร์วัดความลึกหรือไม่
  • ทิศทางที่กล้องหันไป
    • หันหน้า (เซลฟี)
    • หันหลัง (ทั่วโลก)
  • ช่วง FPS (เฟรมต่อวินาที)
  • ขนาดรูปภาพ CPU
  • มิติข้อมูลพื้นผิว GPU
  • หากมี จะใช้กล้องหลายตัวสเตอริโอของอุปกรณ์หรือไม่

เมื่อสร้างเซสชัน ARCore ใหม่ ARCore จะใช้ setCameraConfig เพื่อตั้งค่ากล้องที่ตรงกับรายการการกำหนดค่าที่พร้อมใช้งานซึ่ง getSupportedCameraConfigs(CameraConfigFilter) แสดงมากที่สุด แอปของคุณสามารถใช้ CameraConfigFilter เพื่อจำกัดการกำหนดค่าของกล้องที่พร้อมใช้งานสำหรับอุปกรณ์หนึ่งๆ ในระหว่างรันไทม์ให้แคบลง โดยกรองตามความต้องการของแอป

กรณีการใช้งานทั่วไปสำหรับการกรองมีดังนี้

  • การจำกัดอัตราเฟรมของการจับภาพของกล้องไว้ที่ 30 FPS ส่วนในอุปกรณ์ที่รองรับ 60 fps นั้น ARCore จะให้ความสำคัญกับการกำหนดค่ากล้องที่รองรับอัตราเฟรมดังกล่าว หากต้องการกรองการกำหนดค่ากล้องทั้งหมดที่รองรับ 60 FPS ให้ใช้ตัวกรองกับ setTargetFps โดยใช้ TargetFps.TARGET_FPS_30

    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 จะให้ความสำคัญกับการกำหนดค่ากล้องที่ใช้เซ็นเซอร์ความลึกก่อน หากต้องการกรองการกำหนดค่าของกล้องทั้งหมดที่ใช้เซ็นเซอร์วัดความลึก ให้ใช้ตัวกรอง setDepthSensorUsage โดยใช้ DepthSensorUsage.DO_NOT_USE

    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