items = results.getAnalyseList();
// 開發者根據需要處理識別結果,例如,在此方法中進行相似度計算,從而在檢測到特定姿勢后進行拍照等操作。
// 需要注意,這里只對檢測結果進行處理,不可調用ML Kit提供的其他檢測相關接口。
// 將SparseArray封裝的結果轉換為List數組,以便進行相似度比較。
ListresultsList = new ArrayList<>();
for (int i = 0; i < items.size(); i++) {
resultsList.add(items.valueAt(i));
}
// 在檢測結果和模板之間進行相似度比較。
// templateList表示人體骨骼模板,可以通過靜態圖片檢測的方式生成模板,支持單人或多人模板匹配。
float result = analyzer.caluteSimilarity(resultsList, templateList);
}
@Override
public void destroy() {
// 檢測結束回調方法,用于釋放資源等。
}
}
```
2.2.3 設置識別結果處理器,實現分析器與結果處理器的綁定。
```java
analyzer.setTransactor(new SkeletonAnalyzerTransactor());
```
2.2.4 創建LensEngine,該類由ML Kit SDK提供,用于捕捉相機動態視頻流并傳入分析器。建議設置的相機顯示尺寸不小于320 * 320像素,不大于1920 * 1920像素。
```java
// Create LensEngine.
LensEngine lensEngine = new LensEngine.Creator(getApplicationContext(), analyzer)
.setLensType(LensEngine.BACK_LENS)
.applyDisplayDimension(1280, 720)
.applyFps(20.0f)
.enableAutomaticFocus(true)
.create();
```
2.2.5 開發者啟用相機,讀取視頻流并進行識別,待檢測完成,停止分析器,釋放檢測資源。
```java
if (analyzer != null) {
try {
analyzer.stop();
} catch (IOException e) {
// 異常處理。
}
}
if (lensEngine != null) {
lensEngine.release();
}
```
動態視頻流效果:

基于華為HMS ML kit人體骨骼識別技術,我們能做的還有很多:
a.在體感游戲中讓虛擬形象模擬真人動作,增加游戲趣味性。
b.輔助健身鍛煉或康復訓練時的姿勢矯正。
c.在監控中檢測異常行為。
## 更詳細的開發指南參考華為開發者聯盟官網:
[華為開發者聯盟機器學習服務開發指南](https://developer.huawei.com/consumer/cn/doc/development/HMSCore-Guides/skeleton-detection-0000001051008415)
欲了解更多詳情,請參閱:
華為開發者聯盟官網:[https://developer.huawei.com/consumer/cn/hms](https://developer.huawei.com/consumer/cn/hms)
獲取開發指導文檔:[https://developer.huawei.com/consumer/cn/doc/development](https://developer.huawei.com/consumer/cn/doc/development)
參與開發者討論請到Reddit社區:[https://www.reddit.com/r/HMSCore/](https://www.reddit.com/r/HMSCore/)
下載demo和示例代碼請到Github:[https://github.com/HMS-Core](https://github.com/HMS-Core)
解決集成問題請到Stack Overflow:[https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest](https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest)
---
原文鏈接:[https://developer.huawei.com/consumer/cn/forum/topicview?fid=18&tid=0202333916402640253](https://developer.huawei.com/consumer/cn/forum/topicview?fid=18&tid=0202333916402640253)
原作者:留下落葉