Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

眼前多少难甘事,自古男儿当自强。这篇文章主要讲述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 | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??濂戒笉瀹规槗鎵句釜浜哄皯鐨勫湴鏂癸紝缁撴灉鎷嶅嚭鏉ョ殑鐓х墖鏄繖鏍风殑銆?/p>
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??杩欐牱鐨?/p>
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??杩樻湁杩欐牱鐨?/p>
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??涓嶇湅涓嶇煡閬擄紝鍘熸潵鎴戠殑闈㈤儴琛ㄦ儏杩欎箞涓板瘜銆傘€傛槸涓嶆槸寰堝績绱紵姣忔鎯宠鍙戜釜鍑哄幓娴殑鏈嬪弸鍦堬紝閮借鍦ㄧ櫧澶╂媿鐨勬垚鐧句笂鍗冨紶绫讳技娆剧殑鐓х墖閲岋紝鑺变笂涓€灏忔椂鎵嶈兘鎵惧埌涓€寮犺兘鐪嬬殑鐓х墖銆傘€傘€?/p>
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??涓轰簡瑙e喅绫讳技闂锛孒MS ML Kit 鎻愪緵浜嗚拷韪瘑鍒敾闈腑鏈€澶ц劯鐨勬帴鍙o紝鑳藉璇嗗埆鍥惧儚涓殑鏈€澶ц劯锛屾柟渚垮璺熻釜鍥惧儚涓殑鈥濋噸鐐圭洰鏍団€滃仛鐩稿叧鎿嶄綔鍜屽鐞嗐€傛湰鏂囦腑灏辩畝鍗曠殑璋冪敤MLMaxSizeFaceTransactor杩欎釜鎺ュ彛锛屽疄鐜版渶澶ц劯寰瑧鎶撴媿鐨勫姛鑳姐€?/p>寮€鍙戝墠鍑嗗 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鏂囦欢
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

??澧為噺娣诲姞濡備笅maven鍦板潃锛?/p>
buildscript { { maven {url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } } allprojects { repositories { maven { url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } }

鍦ㄥ簲鐢ㄧ骇鐨刡uild.gradle閲岄潰鍔犱笂SDK渚濊禆
Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿

文章图片

鍦ˋndroidManifest.xml鏂囦欢閲岄潰澧為噺娣诲姞妯″瀷鑷姩涓嬭浇【Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿】??瑕佷娇搴旂敤绋嬪簭鑳藉鍦ㄧ敤鎴蜂粠鍗庝负搴旂敤甯傚満瀹夎鎮ㄧ殑搴旂敤绋嬪簭鍚庯紝鑷姩灏嗘渶鏂扮殑鏈哄櫒瀛︿範妯″瀷鏇存柊鍒扮敤鎴疯澶囷紝璇峰皢浠ヤ笅璇彞娣诲姞鍒拌搴旂敤绋嬪簭鐨凙ndroidManifest.xml鏂囦欢涓細
< manifest ... < meta-data android:name="com.huawei.hms.ml.DEPENDENCY" android:value= "https://www.songbingjia.com/android/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(); }

鍒涘缓浜鸿劯璇嗗埆妫€娴嬪櫒??鍙互閫氳繃浜鸿劯璇嗗埆妫€娴嬮厤缃櫒鈥淢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);

寰€鏈熼摼鎺ワ細蹇湇鍔″父瑙乀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










    推荐阅读