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.

鎶€鏈浘鐗? src=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鏂囦欢

鎶€鏈浘鐗? src=buildscript { { maven {url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } } allprojects { repositories { maven { url 鈥榟ttp://developer.huawei.com/repo/鈥榼 } }

鍦ㄥ簲鐢ㄧ骇鐨刡uild.gradle閲岄潰鍔犱笂SDK渚濊禆

鎶€鏈浘鐗? src=<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();
    }

鍒涘缓浜鸿劯璇嗗埆妫€娴嬪櫒

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

以上是关于Android | 瓒呯畝鍗曢泦鎴怘MS ML Kit瀹炵幇鏈€澶ц劯寰瑧鎶撴媿的主要内容,如果未能解决你的问题,请参考以下文章

铻嶄簯鍗虫椂閫氳SDK闆嗘垚 -- FCM鎺ㄩ€侀泦鎴愭寚鍗?Android骞冲彴)

铻嶄簯鍗虫椂閫氳SDK闆嗘垚 -- 鍥藉唴鍘傚晢鎺ㄩ€侀泦鎴愯俯鍧戠瘒(Android骞冲彴)

鍗曞厓娴嬭瘯锛?锛岄泦鎴愭祴璇曪細0

鍗曢摼琛ㄧ殑瀛︿範

鍗曢摼琛ㄧ殑鍩烘湰鎿嶄綔