开发项目(填空 部分)

FD:

1、

AndroidManifest:

<!--todo step 1:  add authorization of camera -->

<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA"/>

2、

private void createFaceAnalyzer() {
    // Create a face analyzer. You can create an analyzer using the provided customized face detection parameter
    // MLFaceAnalyzerSetting
    // todo step 2: add on-device face analyzer
    MLFaceAnalyzerSetting setting = new MLFaceAnalyzerSetting.Factory()
            .setFeatureType(MLFaceAnalyzerSetting.TYPE_FEATURES)
            .setPerformanceType(MLFaceAnalyzerSetting.TYPE_SPEED)
            .allowTracing()
            .create();
    analyzer = MLAnalyzerFactory.getInstance().getFaceAnalyzer(setting);

3、

private void createLensEngine() {
    // todo step 3: add on-device LensEngine

    Context context = this.getApplicationContext();
    // Create LensEngine
    this.mLensEngine = new LensEngine.Creator(context, this.analyzer)
            .setLensType(this.lensType)
            .applyDisplayDimension(640, 480)
            .applyFps(25.0f)
            .enableAutomaticFocus(true)
            .create();

}

4、

public void objectUpdateCallback(MLAnalyzer.Result<MLFace> var1, MLFace obj) {
    LiveFaceAnalyseActivity.this.overlay.clear();
    if (obj == null) {
        return;
    }

    // todo step 4: add on-device face graphic

    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);
    }
}

5、

private void takePhoto() {
    // todo step 5: add on-device face takePhoto

    this.mLensEngine.photograph(null,
            new LensEngine.PhotographListener() {
                @Override
                public void takenPhotograph(byte[] bytes) {
                    mHandler.sendEmptyMessage(STOP_PREVIEW);
                    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                    saveBitmapToDisk(bitmap);
                }
            });
}

IS:

1、

<!--todo step 1:  add authorization of READ_EXTERNAL_STORAGE ,WRITE_EXTERNAL_STORAGE -->

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

2、3、4、5

private void createImageTransactor() {
    // todo step 2: add on-device ImageSegmentation analyzer

    MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory().setAnalyzerType(MLImageSegmentationSetting.BODY_SEG).create();
    this.analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting);

    if (this.isChosen(this.originBitmap)) {
        // todo step 3: add on-device ImageSegmentation mlFrame
        MLFrame mlFrame = new MLFrame.Creator().setBitmap(this.originBitmap).create();
       // todo step 4: add on-device ImageSegmentation task

        Task<MLImageSegmentation> task = this.analyzer.asyncAnalyseFrame(mlFrame);

        task.addOnSuccessListener(new OnSuccessListener<MLImageSegmentation>() {
            @Override
            public void onSuccess(MLImageSegmentation mlImageSegmentationResults) {
                // Transacting logic for segment success.
                if (mlImageSegmentationResults != null) {
                    // todo step 5: add on-device ImageSegmentation result.

                    StillCutPhotoActivity.this.foreground = mlImageSegmentationResults.getForeground();
                    StillCutPhotoActivity.this.preview.setImageBitmap(StillCutPhotoActivity.this.foreground);
                    StillCutPhotoActivity.this.processedImage = ((BitmapDrawable) ((ImageView) StillCutPhotoActivity.this.preview).getDrawable()).getBitmap();

                } else {
                    StillCutPhotoActivity.this.displayFailure();
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                // Transacting logic for segment failure.
                StillCutPhotoActivity.this.displayFailure();
                return;
            }
        });
    } else {
        Toast.makeText(this.getApplicationContext(), R.string.please_select_picture, Toast.LENGTH_SHORT).show();
        return;
    }
}

INIT:

1、

<!--todo step 1:  add authorization of camera -->
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA"/>

2、3

private MLFaceAnalyzer createFaceAnalyzer() {
    // todo step 2: add on-device face analyzer
    MLFaceAnalyzerSetting setting = new MLFaceAnalyzerSetting.Factory()
            .setFeatureType(MLFaceAnalyzerSetting.TYPE_FEATURES)
            .setPerformanceType(MLFaceAnalyzerSetting.TYPE_SPEED)
            .allowTracing()
            .create();
    this.analyzer = MLAnalyzerFactory.getInstance().getFaceAnalyzer(setting);
    // finish
    this.analyzer.setTransactor(new FaceAnalyzerTransactor(this.mOverlay));
    return this.analyzer;
}

private void createLensEngine() {
    Context context = this.getApplicationContext();
    // todo step 3: add on-device lens engine
    this.mLensEngine = new LensEngine.Creator(context, this.analyzer)
            .setLensType(this.lensType)
            .applyDisplayDimension(1600, 1024)
            .applyFps(25.0f)
            .enableAutomaticFocus(true)
            .create();
    // finish
}

4、

public void transactResult(MLAnalyzer.Result<MLFace> result) {
    this.mGraphicOverlay.clear();
    SparseArray<MLFace> faceSparseArray = result.getAnalyseList();
    for (int i = 0; i < faceSparseArray.size(); i++) {
        // todo step 4: add on-device face graphic
        MLFaceGraphic graphic = new MLFaceGraphic(this.mGraphicOverlay, faceSparseArray.valueAt(i));
        this.mGraphicOverlay.add(graphic);
        // finish
    }
}

SD:

1、

<!--todo step 1:  add authorization of camera -->
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA"/>

2、3、4

private void createSkeletonAnalyzer() {
    // todo step 2: add on-device skeleton analyzer
    this.analyzer = MLSkeletonAnalyzerFactory.getInstance().getSkeletonAnalyzer();
    // todo step 3: set transactor of result
    this.analyzer.setTransactor(new SkeletonAnalyzerTransactor(this, this.graphicOverlay));
}

private void createLensEngine() {
    // todo step 4: add on-device lens engine
    Context context = this.getApplicationContext();
    // Create LensEngine.
    this.mLensEngine = new LensEngine.Creator(context, this.analyzer)
            .setLensType(this.lensType)
            .applyDisplayDimension(1280, 720)
            .applyFps(25.0f)
            .enableAutomaticFocus(true)
            .create();
}

5、

public void transactResult(MLAnalyzer.Result<MLSkeleton> result) {
    this.mGraphicOverlay.clear();

    SparseArray<MLSkeleton> skeletonSparseArray = result.getAnalyseList();
    List<MLSkeleton> list = new ArrayList<>();
    for (int i = 0; i < skeletonSparseArray.size(); i++) {
        list.add(skeletonSparseArray.valueAt(i));
    }
    // todo step 5: add on-device skeleton graphic
    SkeletonGraphic graphic = new SkeletonGraphic(mGraphicOverlay, list);
    this.mGraphicOverlay.add(graphic);

    LiveSkeletonAnalyseActivity mainActivity = mMainActivityWeakReference.get();
    if(mainActivity != null && !mainActivity.isFinishing()) {
        mainActivity.compareSimilarity(list);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值