当前位置:网站首页>手势切换背景,让直播带货更加身临其境
手势切换背景,让直播带货更加身临其境
2020-11-09 16:56:00 【华为开发者论坛】
前言
由于今年疫情改变了各类人群的购物习惯,电商市场份额持续攀升,而直播电商作为一种崭新的交易方式正在重塑流量入口格局,越来越多消费者通过直播带货的方式进入商品页。因此主播为了获取更好的直播效果,往往要花费更多时间准备商品亮点介绍、优惠措施、展示环节,每一个环节都对最终交易结果产生直接影响。以往商家在固定布景的直播间带货,很容易让观众产生审美疲劳,当观众看不到自己对口的商品时往往因为不感兴趣而离开,除非超级段子手,否则主播无法在所有商品环节让每个观众保持兴致盎然,导致的结果可能是直播观看人数随着商品介绍不增反减。 现在借助华为机器学习服务推出的图像分割技术就可以实现根据不同商品品类、需求数字化实时替换各种静态和动态布景,让直播随着切换的各种风格背景变得生动有趣。该技术采用语义分割的方式分割出主播人像,比如介绍家居类商品时可以立即切换成家居风格的房间,介绍户外运动装备时也可以实时切换到户外,观众通过这种创新体验也更能找到身临其境的代入感。
功能介绍
Demo基于华为机器学习服务推出的图像分割和手部关键点识别两大技术,开发通过手势切换背景功能,为了避免误操作,本次Demo设置只有大幅挥手时才切换背景,加载自定义的背景后支持向前切换(向右拨动)和向后切换(向左拨动),操作方式和手机一致,支持动态视频背景,同时如果想采用定制化的手势进行背景切换或实现其他手势特效,可以集成华为ML Kit手部关键点识别进行定制开发。
是不是很具有想象力的交互体验?让我们一起看看是如何实现的。
开发步骤
- 添加HUAWEI agcp插件以及Maven代码库。
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
- Full SDK方式集成。
dependencies{
// 引入图像分割基础SDK
implementation 'com.huawei.hms:ml-computer-vision-segmentation:2.0.4.300'
// 引入多类别分割模型包
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-multiclass-model:2.0.4.300'
// 引入人像分割模型包
implementation 'com.huawei.hms:ml-computer-vision-image-segmentation-body-model:2.0.4.300'
// 引入手势识别基础SDK
implementation 'com.huawei.hms:ml-computer-vision-handkeypoint:2.0.4.300'
// 引入手部关键点检测模型包
implementation 'com.huawei.hms:ml-computer-vision-handkeypoint-model:2.0.4.300'
}
-
在文件头添加配置。 在apply plugin: 'com.android.application'后添加apply plugin: 'com.huawei.agconnect'
-
自动更新机器学习模型 在AndroidManifest.xml文件中添加
<manifest
...
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="imgseg,handkeypoint" />
...
</manifest>
- 创建图像分割检测器。
MLImageSegmentationAnalyzer imageSegmentationAnalyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer();//图像分割分析器
MLHandKeypointAnalyzer handKeypointAnalyzer = MLHandKeypointAnalyzerFactory.getInstance().getHandKeypointAnalyzer();//手势识别分析器
MLCompositeAnalyzer analyzer = new MLCompositeAnalyzer.Creator()
.add(imageSegmentationAnalyzer)
.add(handKeypointAnalyzer)
.create();
- 创建识别结果处理类。
public class ImageSegmentAnalyzerTransactor implements MLAnalyzer.MLTransactor<MLImageSegmentation> {
@Override
public void transactResult(MLAnalyzer.Result<MLImageSegmentation> results) {
SparseArray<MLImageSegmentation> items = results.getAnalyseList();
// 开发者根据需要处理识别结果,需要注意,这里只对检测结果进行处理。
// 不可调用ML Kit提供的其他检测相关接口。
}
@Override
public void destroy() {
// 检测结束回调方法,用于释放资源等。
}
}
public class HandKeypointTransactor implements MLAnalyzer.MLTransactor<List<MLHandKeypoints>> {
@Override
public void transactResult(MLAnalyzer.Result<List<MLHandKeypoints>> results) {
SparseArray<List<MLHandKeypoints>> analyseList = results.getAnalyseList();
// 开发者根据需要处理识别结果,需要注意,这里只对检测结果进行处理。
// 不可调用ML Kit提供的其他检测相关接口。
}
@Override
public void destroy() {
// 检测结束回调方法,用于释放资源等。
}
}
- 设置识别结果处理器,实现分析器与结果处理器的绑定.
imageSegmentationAnalyzer.setTransactor(new ImageSegmentAnalyzerTransactor());
handKeypointAnalyzer.setTransactor(new HandKeypointTransactor());
- 创建LensEngine
Context context = this.getApplicationContext();
LensEngine lensEngine = new LensEngine.Creator(context,analyzer)
// 设置摄像头前后置模式,LensEngine.BACK_LENS为后置,LensEngine.FRONT_LENS为前置。
.setLensType(LensEngine.FRONT_LENS)
.applyDisplayDimension(1280, 720)
.applyFps(20.0f)
.enableAutomaticFocus(true)
.create();
- 启动相机,读取视频流,进行识别。
// 请自行实现SurfaceView控件的其他逻辑。
SurfaceView mSurfaceView = new SurfaceView(this);
try {
lensEngine.run(mSurfaceView.getHolder());
} catch (IOException e) {
// 异常处理逻辑。
}
- 检测完成,停止分析器,释放检测资源。
if (analyzer != null) {
try {
analyzer.stop();
} catch (IOException e) {
// 异常处理。
}
}
if (lensEngine != null) {
lensEngine.release();
}
总结
综上,通过引入包、建立检测、分析与结果处理等几个简单的步骤就可以快速实现这个小小的黑科技。另外通过图像分割技术,我们还可以做很多东西,比如视频网站中的蒙版弹幕,结合一些前端渲染技术轻松避免弹幕遮盖人体部分,或者利用现有素材制作各种尺寸的精美写真照片,语义分割的一大好处就是可以精准地控制你想要分割出来的物体,除了人像还可以对美食、宠物、建筑、风景甚至花花草草等进行分割,再也不用死磕电脑上的专业修图软件了。
Github Demo
更详细的开发指南参考华为开发者联盟官网:https://developer.huawei.com/consumer/cn/hms/huawei-mlkit
原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0204395267288570031?fid=18 原作者:timer
版权声明
本文为[华为开发者论坛]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4478396/blog/4710170
边栏推荐
- js对象数组去重
- 企业公司开发微信小程序适用于哪些行业?
- 缓存的数据一致性
- On agile development concept and iterative development scheme
- 5 minutes get I use GitHub's 5-year summary of these operations!
- How to choose the development of Biao fan interactive interpretation program?
- 5分钟GET我使用Github 5 年总结的这些骚操作!
- 堆重启_uaf_hacknote
- 揭秘在召唤师峡谷中移动路径选择逻辑?
- Express yourself with wechat expression translation, programmer's little romance, get up quickly!
猜你喜欢
明年起旧版本安卓设备将无法浏览大约30%的网页
MES system is different from traditional management in industry application
树莓派内网穿透建站与维护,使用内网穿透无需服务器
CAD2016下载AutoCAD2016下载安装详细教程CAD下载
Toolkit Pro助力界面开发:缩短项目开发周期,快速实现具有现代功能区样式的GUI
H264Nalu头部解析
How to design and implement storage QoS?
从一次需求改良漫谈php文件分片上传
In depth analysis of the multi-user shopping mall system from search to create a profit point
详解Git
随机推荐
Rongyun has completed several hundred million RMB round D financing, and will continue to build global cloud communication capability
电商/直播速看!双11跑赢李佳琦就看这款单品了!
[share] interface tests how to transfer files in post request
CentOS查看CPU核心数及cpuinfo解析
5分钟GET我使用Github 5 年总结的这些骚操作!
从一次需求改良漫谈php文件分片上传
Installation and testing of Flink
浅谈API网关(API Gateway)如何承载API经济生态链
SEO solution development, how to break away from the shadow of the bow?
Knowledge mapping 1.1 -- starting from NER
高质量的缺陷分析:让自己少写 bug
The selection of wire displacement encoder needs the guidance of precise electronics
深入分析商淘多用户商城系统如何从搜索着手打造盈利点
你的钱为什么会被转走,这篇文章告诉你答案
微服务框架 Go-Micro 集成 Nacos 实战之服务注册与发现
Revealing the logic of moving path selection in Summoner Canyon?
Super discount, cloud server 88 yuan seconds
Help enterprises to get rid of difficulties, famous enterprises return home Engineers: success depends on it!
Low power Bluetooth single chip helps Internet of things
高质量的缺陷分析:让自己少写 bug