ArCameraConfig
會說明基礎相機感應器的屬性,包括:
- 攝影機 ID
- 在適用情況下,是否要使用深度感應器
- 相機朝向的方向:
- 前置鏡頭 (自拍)
- 後置 (世界)
- FPS (每秒影格數) 範圍
- CPU 圖片尺寸
- GPU 紋理尺寸
- 如果有設定,是否要使用裝置的多鏡頭攝影機
建立新的 ARCore 工作階段時,ARCore 會使用 ArSession_setCameraConfig()
設定最符合 ArSession_getSupportedCameraConfigsWithFilter()
傳回的可用設定清單的相機設定。您的應用程式可以使用 ArCameraConfigFilter
,根據應用程式需求進行篩選,藉此在執行階段縮小指定裝置可用的相機設定。
常見的篩選用途包括:
將相機擷取畫面更新率限制為 30 fps。在支援 60 fps 的裝置上,ARCore 會優先採用支援該影格速率的相機設定。如要篩除支援 60 fps 的所有相機設定,請使用
AR_CAMERA_CONFIG_TARGET_FPS_30
在ArCameraConfigFilter_setTargetFps()
套用濾鏡。// Return only camera configs that target 30 FPS camera capture frame // rate. ArCameraConfigFilter_setTargetFps(session, filter, AR_CAMERA_CONFIG_TARGET_FPS_30);
禁止 ARCore 使用深度感應器。如果裝置有支援深度感應器,ARCore 會優先採用使用深度感應器的相機設定。如要篩除使用深度感應器的所有相機設定,請使用
AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE
套用ArCameraConfigFilter_setDepthSensorUsage()
篩選器。ArCameraConfigFilter_setDepthSensorUsage( session, filter, AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_DO_NOT_USE);
選取替代 GPU 紋理解析度。在支援的裝置上,ARCore 可能會提供額外的 GPU 紋理解析度。選擇較低解析度的 GPU 紋理可降低 GPU 負載及降低記憶體頻寬需求,藉此提升應用程式效能,但不保證在所有情況下都能提升效能。
使用相機設定篩選器
請按照下列步驟讓應用程式篩選相機設定。
// Create an ARCore session. ArSession* session; ArSession_create(env, context, &session); // Create a camera config list and filter for the session. ArCameraConfig* selected_config; ArCameraConfigList* configs; ArCameraConfigFilter* filter; ArCameraConfig_create(session, &selected_config); ArCameraConfigList_create(session, &configs); ArCameraConfigFilter_create(session, &filter); // Return only camera configs that target 30 fps camera capture frame rate. ArCameraConfigFilter_setTargetFps(session, filter, AR_CAMERA_CONFIG_TARGET_FPS_30); // Return only camera configs that will not use the depth sensor. ArCameraConfigFilter_setDepthSensorUsage( session, filter, AR_CAMERA_CONFIG_DEPTH_SENSOR_USAGE_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. ArSession_getSupportedCameraConfigsWithFilter(session, filter, configs); // 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. ArCameraConfigList_getItem(session, configs, 0, selected_config); // Set the camera config to use selected_config. ArSession_setCameraConfig(session, selected_config); // Free memory. ArCameraConfigFilter_destroy(filter); ArCameraConfigList_destroy(configs);
專注模式
您也可以在工作階段設定中設定聚焦模式。固定焦點通常比較適合用於追蹤 (在大多數裝置上也是 ARCore 預設值)。錄製、攝影、錄影,以及附近物件需要成為焦點時,都必須使用自動對焦功能。
詳情請參閱 ArConfig_setFocusMode()
。