CameraConfig
จะอธิบายพร็อพเพอร์ตี้ของ
เซ็นเซอร์ตรวจจับภายในกล้อง ซึ่งรวมถึง
- รหัสกล้อง
- จะใช้เซ็นเซอร์วัดความลึก (หากมี)
- ทิศทางที่กล้องหันไป
- กล้องหน้า (เซลฟี)
- กล้องหลัง (ทั่วโลก)
- ช่วง FPS (เฟรมต่อวินาที)
- ขนาดรูปภาพ CPU
- มิติข้อมูลพื้นผิว GPU
- หากมี ระบบจะใช้กล้องหลายตัวแบบสเตอริโอของอุปกรณ์หรือไม่
เมื่อสร้างเซสชัน ARCore ใหม่ ARCore จะใช้
setCameraConfig
เพื่อกำหนดค่ากล้อง
ซึ่งตรงกับรายการการกำหนดค่าที่พร้อมใช้งานมากที่สุดที่แสดงผลโดย
getSupportedCameraConfigs(CameraConfigFilter)
แอปของคุณใช้ CameraConfigFilter
ได้
เพื่อจำกัดการกำหนดค่ากล้องที่ใช้ได้สำหรับอุปกรณ์นั้นๆ ให้แคบลงขณะรันไทม์โดย
การกรองตามความต้องการของแอป
กรณีการใช้งานทั่วไปสําหรับการกรองมีดังนี้
การจำกัดอัตราเฟรมการจับภาพของกล้องเป็น 30 FPS ในอุปกรณ์ที่รองรับ 60 FPS, ARCore จะให้ความสำคัญกับการกำหนดค่ากล้องที่รองรับ อัตราเฟรม วิธีกรองการกำหนดค่ากล้องทั้งหมดที่รองรับ 60 FPS ออก ใช้ตัวกรองกับ
setTargetFps
โดยใช้TargetFps.TARGET_FPS_30
ป้องกันไม่ให้ ARCore ใช้เซ็นเซอร์ความลึก ในอุปกรณ์ที่มี เซ็นเซอร์ตรวจจับความลึกที่รองรับ ARCore ให้ความสำคัญกับการกำหนดค่ากล้องที่ใช้ความลึก เซ็นเซอร์ หากต้องการกรองการกำหนดค่ากล้องทั้งหมดที่ใช้เซ็นเซอร์วัดความลึกออก ให้ใช้
setDepthSensorUsage
กรองโดยใช้DepthSensorUsage.DO_NOT_USE
// Return only camera configs that will not use the depth sensor.
filter.setDepthSensorUsage(EnumSet.of(CameraConfig.DepthSensorUsage.DO_NOT_USE));// 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 และลดหน่วยความจำ ที่ต้องการแบนด์วิดท์ แต่ไม่ได้รับประกันว่าจะสามารถปรับปรุงประสิทธิภาพใน กรณีทั้งหมด
การใช้ตัวกรองการกำหนดค่ากล้อง
ทำตามขั้นตอนต่อไปนี้เพื่อเปิดใช้แอปเพื่อกรองการกำหนดค่ากล้อง
// 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));
// 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
เพื่อดูรายละเอียด