场景识别帮助小白用户实现一键式智能拍照修图

场景识别帮助小白用户实现一键式智能拍照修图

前言

在手机相机功能日益强大的今天,相对于相机硬件的差异,图像处理算法逐渐显示出更加重要的地位。现在的消费者也开始由看重硬件能力慢慢转向对算法能力的重视。用户在拍照发朋友圈之前往往需要根据场景逐个调整画面参数,这一过程费时费力,对于小白用户又很难调节到最佳状态。有没有一种方式可以精细化区分场景,实现一键式智能拍照修图呢?华为机器学习服务近期推出的场景识别支持102种细分场景的识别,对于生活旅行常见的场景诸如沙滩、蓝天、美食、夜景、绿植、典型建筑等场景都可以精准地识别出来,配合图像矩阵进行精细化调参,帮助打造更加主动智能、省时省力的移动应用。让我们看一看增强效果。

增强效果

对于城市夜景图,场景识别可以准确识别出夜景,然后将图片中的亮部增量,暗部变暗,整个照片比之前看起来层次感更强,夜景效果更加纯粹。
在这里插入图片描述

然后测试一张天空的图片,在准确识别天空场景之后通过增强矩阵将略显昏暗的天空变得明亮起来。
在这里插入图片描述

以及对于绿植、花朵的拍照增强。
在这里插入图片描述
在这里插入图片描述

当然,以上demo对于各种图片的增强效果可能有细微的不同,当然可以根据自己的风格来选择或搭配滤镜。
所以让我们了解开发原理之后再开发自己的相机模式吧。

开发步骤

  1. 创建场景识别检测器实例
MLSceneDetectionAnalyzer analyzer = MLSceneDetectionAnalyzerFactory.getInstance().getSceneDetectionAnalyzer();
  1. 通过android.graphics.Bitmap构造MLFrame,支持的图片格式包括:jpg/jpeg/png/bmp。
MLFrame frame = new MLFrame.Creator().setBitmap(bitmap).create();
  1. 场景识别。
Task<List<MLSceneDetection>> task = this.analyzer.asyncAnalyseFrame(frame);
task.addOnSuccessListener(new OnSuccessListener<List<MLSceneDetection>>() {
    @Override
    public void onSuccess(List<MLSceneDetection> sceneInfos) {
        // Processing logic for scene detection success.
        
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(Exception e) {
        // Processing logic for scene detection failure.
        if (e instanceof MLException) {
            MLException exception = (MLException) e;
            // Obtain the result code.
            int errCode = exception.getErrCode();
            // Obtain the error information.
            String message = exception.getMessage();
        } else {
            // Other errors.
        }
    }
});

  1. 检测完成,停止分析器,释放检测资源。
if (analyzer != null) {
    analyzer.stop();
}

  1. maven地址。
buildscript {
    repositories {
        maven { url 'https://developer.huawei.com/repo/' }
    }
}
allprojects {
    repositories {
        maven { url 'https://developer.huawei.com/repo/' }
    }
}

  1. 引入SDK。
dependencies {
    // Scene detection SDK.
    implementation 'com.huawei.hms:ml-computer-vision-scenedetection:2.0.3.300'
    // Scene detection model.
    implementation 'com.huawei.hms:ml-computer-vision-scenedetection-model:2.0.3.300'
}

  1. 清单文件
<manifest
    ...
    <meta-data
        android:name="com.huawei.hms.ml.DEPENDENCY"
        android:value="1" />
    ...
</manifest>

  1. 权限。
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.autofocus" />


  1. 动态权限申请。
if (!(ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) {
    requestCameraPermission();
}

总结

华为机器学习场景识别提供的更加主动的智能是未来应用趋势,除了用于拍照效果增强,场景识别还可以用来进行相册管理及场景图片检索,帮助您构建精细化的分类获取和管理。

欲了解更多详情,请参阅:
华为开发者联盟官网:https://developer.huawei.com/consumer/cn/hms
获取开发指导文档:https://developer.huawei.com/consumer/cn/doc/development
参与开发者讨论请到Reddit社区:https://www.reddit.com/r/HMSCore/
下载demo和示例代码请到Github:https://github.com/HMS-Core
解决集成问题请到Stack Overflow:https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值