当前位置:网站首页>手势切换背景,让直播带货更加身临其境
手势切换背景,让直播带货更加身临其境
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
边栏推荐
- Six axes of calibration service
- Kubernetes V1.19.3 kubeadm 部署笔记(中)
- MES system plays an important role in the factory production management
- 腾讯云AMD云服务器怎么样好不好?
- Configure static IP address in ubuntu18.04 NAT mode -2020.11.09
- Why does it take more and more time to develop a software?
- 磁阻式随机存储器MRAM基本原理
- High quality defect analysis: let yourself write fewer bugs
- 设置背景图片的两种方式,并解决手机端背景图片高度自适应问题
- Function calculation advanced IP query tool development
猜你喜欢

5 minutes get I use GitHub's 5-year summary of these operations!

Why is your money transferred? This article tells you the answer

Implement printf function by yourself

Explore cache configuration of Android gradle plug-in

超简单集成华为系统完整性检测,搞定设备安全防护

用会声会影替换视频背景原来这么简单

cad教程 cad2016安装教程

In the third stage, day16 user module jumps to SSO single sign on jsonp / CORS cross domain user login verification

浅谈API网关(API Gateway)如何承载API经济生态链

EasyExcel根据筛选列导出(中间不空列,顺序可调整)
随机推荐
Solve the problem that the page does not refresh after the wechat applet uses switchtab to jump
缓存的数据一致性
From next year, about 30% of the web pages will be inaccessible to older Android devices
Looking for a small immutable dictionary with better performance
树莓派内网穿透建站与维护,使用内网穿透无需服务器
SEO解决方案制定,如何脱离杯弓蛇影?
The internal network penetration of raspberry is built and maintained. No server is required for intranet penetration
Cad2016 software installation tutorial
Simple use of AE (after effects)
电商/直播速看!双11跑赢李佳琦就看这款单品了!
Toolkit Pro helps interface development: shorten the project development cycle and quickly realize GUI with modern functional area style
Kubernetes V1.19.3 kubeadm 部署笔记(中)
Configure static IP address in ubuntu18.04 NAT mode -2020.11.09
QML Repeater
Restart the heap_ uaf_ hacknote
分享用MathType编辑字母与数学公式的技巧
5 minutes get I use GitHub's five-year summary of these complaints!
Which industries are suitable for enterprises to develop wechat applet?
MES system is different from traditional management in industry application
Booker · apachecn programming / back end / big data / AI learning resources 2020.11