一、前言

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

二、增强效果

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

一、前言-LMLPHP

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

一、前言-LMLPHP

以及对于绿植、花朵的拍照增强。

一、前言-LMLPHP

一、前言-LMLPHP

当然,以上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();
 }


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

引入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'
 }

清单文件

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

权限

<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" />

动态权限申请

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


原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0204423925515690659?fid=18

原作者:timer

05-31 18:49