牙叔教程 简单易懂
产品简介
腾讯云神图·人像变换(Face Transformation)基于腾讯优图领先的人脸识别算法,提供人脸年龄变化、人脸性别转换等能力,用户上传照片即可得到实现男女性别切换、人脸变老/变年轻等效果。适用于社交娱乐、广告营销、互动传播等场景。
人像变换目前包括四个功能
- 人脸年龄变化
- 人脸性别转换
- 人像动漫化
- 人像渐变
效果展示
原图
原图.png
6岁
6岁.png
86岁
86岁.png
女装
女装.png
动漫化
动漫化.png
人像渐变
效果.gif
缘起
autojs基本支持nodejs了, 所以用腾讯云的人像变换sdk来测试一下
autojs支持的nodejs版本: 15.5.1
npm版本: 7.3.0
切勿自行升级
环境
手机: Mi 11 Pro
Android版本: 11
Autojs版本: 9.0.9
仓库
一共有2个
服务端: https://gitee.com/yashujs/tencentcloud-ft-nodejs-yashu
客户端: https://gitee.com/yashujs/portrait-transformation-client
使用步骤
服务端和客户端都是autojs实现的
服务端: autojs自带的nodejs, 使用腾讯云的人像变换的nodejs SDK;
客户端:就普通的http请求脚本
1. 服务端
- 下载客户端代码到手机
- 安装依赖: npm i --no-bin-links
- 你不知道在哪里安装依赖
1. 打开任意一个js文件
2. 左上角有一个文件, 点击它
3. 点击你这个项目文件夹右侧的三个点
4. 点击npm
5. 点击其他npm命令或包管理器
6. 输入命令 npm i --no-bin-links
- 修改秘钥config.js
- 不需要启动服务端, 启动由客户端完成
2, 客户端, 讲个大概
代码讲解
1. IP和端口
let port = "34567";
let url = "http://127.0.0.1:" + port + "/";
2. 启动服务端(重点)
startServer();
function startServer() {
$engines.execScriptFile("/storage/emulated/0/脚本/ft/ft/index.js");
events.on("exit", function () {
let r = http.get(url + "exit");
log(r.body.string());
});
}
3. 读取图片
let imgPath = "./man1.jpg";
let imgPath2 = "./man2.jpg";
let img = images.read(files.path(imgPath));
let img2 = images.read(files.path(imgPath2));
let imgBase64 = images.toBase64(img);
let img2Base64 = images.toBase64(img2);
4. 界面
$ui.layout(
<vertical>
<horizontal>
<img id="img" src="file://{{imgPath}}"></img>
<img id="img2" src="file://{{imgPath2}}"></img>
</horizontal>
<seekbar id="seekbar" progress="30" w="*" margin="20 10 20 0" />
<horizontal w="*" gravity="center">
<text text="1. 修改年龄: " textSize="20sp"></text>
<text id="age" textSize="20sp">
30
</text>
</horizontal>
<horizontal w="*" gravity="center" marginTop="10">
<text text="2. 修改性别: " textSize="20sp"></text>
<radiogroup id="gender" orientation="horizontal">
<radio text="男"></radio>
<radio text="女"></radio>
</radiogroup>
</horizontal>
<button id="cartoon" text="3. 人像动漫化"></button>
<button id="morph" bg="#bcaaa4" text="4.1 人像渐变任务提交"></button>
<text id="JobId" textSize="20sp" w="*" gravity="center">
JobId
</text>
<button id="morph2" bg="#8d6e63" text="4.2 人像渐变任务查询(请求频率限制20次/秒)"></button>
<VideoView id="video" w="wrap_content" layout_gravity="center" bg="#ffffff" />
</vertical>
);
5. 添加按钮点击事件
$ui.cartoon.click(function () {
cartoonFace(imgBase64, $ui.img);
cartoonFace(img2Base64, $ui.img2);
});
6. 按钮对应的函数, 请求格式基本一模一样
function cartoonFace(imgBase64, view) {
let body = {
action: "FaceCartoonPic",
imgBase64: imgBase64,
};
http.postJson(
url,
body,
{
headers: {
"Content-Type": "application/json",
},
},
function (res, err) {
let obj = res.body.json();
http.get(obj.ResultUrl, {}, function (res, err) {
if (err) {
log("下载图片异常");
console.error(err);
return;
}
let tempPath = files.join(files.getSdcardPath(), "脚本", "temp.jpg");
files.writeBytes(tempPath, res.body.bytes());
view.attr("src", "file://" + tempPath);
});
}
);
}
名人名言
思路是最重要的, 其他的百度, bing, stackoverflow, 安卓文档, autojs文档, 最后才是群里问问
--- 牙叔教程
声明
部分内容来自网络
本教程仅用于学习, 禁止用于其他用途
网友评论