Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/state' title='state'>state
鍐呭 clear htm sage tle 鎿嶄綔 html 娴佺▼ 鍓嶈█
??濡傛灉澶у瀵笻MS ML Kit 浜鸿劯妫€娴嬪姛鑳芥湁鎵€浜嗚В锛岀浉淇″凡缁忓姩鎵嬭皟鐢ㄦ垜浠彁渚涚殑鎺ュ彛缂栧啓鑷繁鐨凙PP鍟︺€傜洰鍓嶅氨鏈夊皬浼欎即鍦ㄨ皟鐢ㄦ帴鍙g殑杩囩▼涓弽棣堬紝涓嶅お娓呮HMS ML Kit 鏂囨。涓殑MLMaxSizeFaceTransactor杩欎釜鎺ュ彛鐨勪娇鐢ㄦ柟娉曘€備负浜嗚澶у鏇村姞娣卞埢鐨勪簡瑙f垜浠殑鎺ュ彛锛屾柟渚垮湪鍦烘櫙涓娇鐢紝鍦ㄨ繖绡囨枃绔犱腑灏忕紪鍑嗗鎶涚爾寮曠帀锛屽ぇ瀹跺彲浠ユ墦寮€鎬濊矾锛屽澶氬皾璇曘€傚鏋滄湁灏忎紮浼存兂瑕佹繁鍏ョ殑浜嗚В鏇村姞鍏ㄩ潰鍏蜂綋鐨勫姛鑳斤紝璇峰ぇ瀹剁Щ姝?a href="https://developer.huawei.com/consumer/cn/hms/huawei-mlkit" rel="nofollow">https://developer.huawei.com/consumer/cn/hms/huawei-mlkit
銆?/p>鍦烘櫙
??鐩镐俊澶у閮芥湁鍦ㄤ簲涓€銆佸崄涓€鍑哄幓娓哥帺鐨勭粡鍘嗭紝鏄笉鏄兘鏄繖鏍风殑people mountain people sea.
android studio 瀹夎
??寰堢畝鍗曪紝涓嬭浇瀹夎鍗冲彲銆傚叿浣撲笅杞介摼鎺ワ細
??Android studio 瀹樼綉涓嬭浇閾炬帴锛?a href="https://developer.android.com/studio" rel="nofollow">https://developer.android.com/studio
??Android studio瀹夎娴佺▼鍙傝€冮摼鎺ワ細https://www.cnblogs.com/xiadewang/p/7820377.html
鍦ㄩ」鐩骇gradle閲屾坊鍔犲崕涓簃aven浠?/h2>
??鎵撳紑AndroidStudio椤圭洰绾uild.gradle鏂囦欢
buildscript { { maven {url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } } allprojects { repositories { maven { url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } }
鍦ㄥ簲鐢ㄧ骇鐨刡uild.gradle閲岄潰鍔犱笂SDK渚濊禆
<manifest ... <meta-data android:name="com.huawei.hms.ml.DEPENDENCY" android:value= " face"/> ... </manifest>
鍦ˋndroidManifest.xml鏂囦欢閲岄潰鐢宠鐩告満銆佽闂綉缁滃拰瀛樺偍鏉冮檺
<!--鐩告満鏉冮檺-->
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<!--鍐欐潈闄?->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
浠g爜寮€鍙戝叧閿楠?/h1>
鍔ㄦ€佹潈闄愮敵璇?/h2>
@Override
public void onCreate(Bundle savedInstanceState) {
鈥︹€? if (!allPermissionsGranted()) {
getRuntimePermissions();
}
鍒涘缓浜鸿劯璇嗗埆妫€娴嬪櫒
@Override
public void onCreate(Bundle savedInstanceState) {
鈥︹€? if (!allPermissionsGranted()) {
getRuntimePermissions();
}
鍒涘缓浜鸿劯璇嗗埆妫€娴嬪櫒
??鍙互閫氳繃浜鸿劯璇嗗埆妫€娴嬮厤缃櫒鈥淢LFaceAnalyzerSetting鈥濆垱寤轰汉鑴歌瘑鍒娴嬪櫒銆?/p>
MLFaceAnalyzerSetting setting =
new MLFaceAnalyzerSetting.Factory()
.setFeatureType(MLFaceAnalyzerSetting.TYPE_FEATURES)
.setKeyPointType(MLFaceAnalyzerSetting.TYPE_UNSUPPORT_KEYPOINTS)
.setMinFaceProportion(0.1f)
.setTracingAllowed(true)
.create();
??閫氳繃MLMaxSizeFaceTransactor.Creator鍒涘缓鈥淢LMaxSizeFaceTransactor鈥濆璞$敤浜庡鐞嗘娴嬪埌鐨勬渶澶ц劯锛屽叾涓璷bjectCreateCallback()鏂规硶鏄湪妫€娴嬪埌瀵硅薄鐨勬椂鍊欒皟鐢ㄧ殑锛宱bjectUpdateCallback()鏂规硶鏄湪瀵硅薄鏇存柊浜嗙殑鏃跺€欒皟鐢ㄧ殑锛屽湪鏂规硶閲岄€氳繃Overlay鍦ㄨ瘑鍒埌鐨勬渶澶т汉鑴镐笂鏍囪浜嗕竴涓柟鍧楋紝骞堕€氳繃妫€娴嬬粨鏋滆幏鍙朚LFaceEmotion鏉ヨ瘑鍒井绗戣〃鎯呰Е鍙戞媿鐓с€?/p>
MLMaxSizeFaceTransactor transactor = new MLMaxSizeFaceTransactor.Creator(analyzer, new MLResultTrailer<MLFace>() {
@Override
public void objectCreateCallback(int itemId, MLFace obj) {
LiveFaceAnalyseActivity.this.overlay.clear();
if (obj == null) {
return;
}
LocalFaceGraphic faceGraphic =
new LocalFaceGraphic(LiveFaceAnalyseActivity.this.overlay, obj, LiveFaceAnalyseActivity.this);
LiveFaceAnalyseActivity.this.overlay.addGraphic(faceGraphic);
MLFaceEmotion emotion = obj.getEmotions();
if (emotion.getSmilingProbability() > smilingPossibility) {
safeToTakePicture = false;
mHandler.sendEmptyMessage(TAKE_PHOTO);
}
}
@Override
public void objectUpdateCallback(MLAnalyzer.Result<MLFace> var1, MLFace obj) {
LiveFaceAnalyseActivity.this.overlay.clear();
if (obj == null) {
return;
}
LocalFaceGraphic faceGraphic =
new LocalFaceGraphic(LiveFaceAnalyseActivity.this.overlay, obj, LiveFaceAnalyseActivity.this);
LiveFaceAnalyseActivity.this.overlay.addGraphic(faceGraphic);
MLFaceEmotion emotion = obj.getEmotions();
if (emotion.getSmilingProbability() > smilingPossibility && safeToTakePicture) {
safeToTakePicture = false;
mHandler.sendEmptyMessage(TAKE_PHOTO);
}
}
@Override
public void lostCallback(MLAnalyzer.Result<MLFace> result) {
LiveFaceAnalyseActivity.this.overlay.clear();
}
@Override
public void completeCallback() {
LiveFaceAnalyseActivity.this.overlay.clear();
}
}).create();
this.analyzer.setTransactor(transactor);
閫氳繃LensEngine.Creator鍒涘缓LensEngine瀹炰緥杩涜瑙嗛娴佺殑浜鸿劯妫€娴嬫娴?/h2>
this.mLensEngine = new LensEngine.Creator(context, this.analyzer).setLensType(this.lensType)
.applyDisplayDimension(640, 480)
.applyFps(25.0f)
.enableAutomaticFocus(true)
.create();
鍚姩鐩告満棰勮杩涜浜鸿劯妫€娴?/h2>
this.mPreview.start(this.mLensEngine, this.overlay);
this.mLensEngine = new LensEngine.Creator(context, this.analyzer).setLensType(this.lensType)
.applyDisplayDimension(640, 480)
.applyFps(25.0f)
.enableAutomaticFocus(true)
.create();
this.mPreview.start(this.mLensEngine, this.overlay);
寰€鏈熼摼鎺ワ細蹇湇鍔″父瑙乀OP3瀹℃牳闆峰尯锛屽啀涓嶈繃瀹″氨瑕佸穿婧冨暒锛?/a>
鍐呭鏉ユ簮锛?a href="https://developer.huawei.com/consumer/cn/forum/topicview?tid=0201256372685820478&fid=18" rel="nofollow">https://developer.huawei.com/consumer/cn/forum/topicview?tid=0201256372685820478&fid=18
鍘熶綔鑰咃細littlewhite
以上是关于Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿的主要内容,如果未能解决你的问题,请参考以下文章
铻嶄簯鍗虫椂閫氳SDK闆嗘垚 -- FCM鎺ㄩ€侀泦鎴愭寚鍗?Android骞冲彴)