抖音开放平台Logo
开发者文档
“/”唤起搜索
控制台
  • JS API 列表
  • 基础
  • TTML
  • 网络
  • 媒体
  • 地图
  • 文件
  • 数据缓存
  • 地理位置
  • 设备
  • 画布
  • 界面
  • 页面导航
  • 开放接口
  • 登录
  • 用户信息
  • 广告
  • 营销能力
  • 支付
  • 分享
  • 小程序跳转
  • 抖音视频能力
  • 收货地址
  • 设置
  • 授权
  • 评价能力
  • 数据分析
  • 视频拍摄器
  • 引导关注
  • 订阅消息
  • 电商插件能力(即将废弃)
  • 流量来源识别
  • 隐私信息授权
  • web化
  • 转发和挂载
  • 侧边栏能力
  • 直播能力
  • AI/AR能力
  • AI/AR 能力简介
  • 算法管理器方案
  • 算法能力简介
  • tt.getAlgorithmManager
  • AlgorithmManager
  • AlgorithmResult
  • 原生神经网络方案
  • 特效贴纸方案
  • 安全能力
  • 行业开放
  • 第三方平台
  • 其它
  • 生活服务(即将废弃)
  • 基础库 2.18.0 开始支持本方法,低版本需做兼容处理,这是一个异步方法。
    获取传入字段对应的算法管理器。目前该接口仅对白名单小程序开放,如需使用,开发者需要至控制台-小程序页面下,进入“能力-能力实验室-小程序能力”,申请AI算法管理器能力。以上仅申请接口权限,无法满足使用条件;能力使用方式及付费问题,详情请联系火山引擎商务咨询

    语法

    tt.getAlgorithmManager(options)

    参数说明

    options 为 object 类型,属性如下:
    属性名
    类型
    默认值
    必填
    说明
    最低支持版本
    width
    number
    输入图像的宽度
    2.18.0
    height
    number
    输入图像的高度
    2.18.0
    useSyncMode
    boolean
    是否使用同步模式
    2.18.0
    requirements
    string[]
    需要开启的算法类型,详情见 requirements 的合法值
    2.18.0
    success
    function
    接口调用成功的回调函数
    2.18.0
    fail
    function
    接口调用失败的回调函数
    2.18.0
    complete
    function
    接口调用结束的回调函数(调用成功、失败都会执行)
    2.18.0

    requirements 的合法值

    说明
    最低支持版本
    ['skeleton']
    肢体识别算法对应字段
    2.18.0
    ['face106']
    面部 106 点算法对应字段
    2.18.0
    ['nail']
    指甲分割算法对应字段
    2.18.0
    ['foot']
    足部识别算法对应字段
    2.18.0
    ['trackingAr']
    追踪 AR 算法对应字段
    2.26.0

    回调成功

    object 类型,属性如下:
    属性名
    类型
    说明
    最低支持版本
    algorithmManager
    获取的算法管理器
    2.18.0
    errMsg
    string
    "getAlgorithmManager:success"
    2.18.0

    回调失败

    object 类型,属性如下:
    属性名
    类型
    说明
    最低支持版本
    errMsg
    string
    "getAlgorithmManager:fail " + 详细错误信息
    2.18.0

    代码示例

    index.js
    Page({ data: {}, onLoad: function () { this.cameraContext = tt.createCameraContext(); }, initCanvasConfig() { this.cameraContext = tt.createCameraContext(); this.cameraListener = this.cameraContext.onCameraFrame((frame) => { this.frameWidth = frame.width; this.frameHeight = frame.height; this.canvas.requestAnimationFrame(() => { this.onFrame(frame); }); }); this.cameraListener.start(); }, init() { this.frameWidth = 480; this.frameHeight = 640; if (this.algorithmModule == null) { this.algorithmModule = require("./AlgorithmModule"); this.algorithmModule.initAlgorithm( this.frameWidth, this.frameHeight, this.showAlgorithmResult ); } this.cameraContext = tt.createCameraContext(); this.cameraListener = this.cameraContext.onCameraFrame((frame) => { this.onFrame(frame); }); this.cameraListener.start(); }, onFrame(cameraFrame) { if (this.algorithmModule != null) { this.algorithmModule.onFrame(cameraFrame.data); } }, showAlgorithmResult(algorithmResult) { console.log( "[debug] showAlgorithmResult :: algorithmResult = ", algorithmResult ); }, onError(e) { tt.showModal({ content: "相机出错了:" + e.detail.errMsg, }); }, });
    AlgorithmModule.js
    let algorithmManager = null; let width, height = null; let cb = null; export function initAlgorithm(_width, _height, onResultFallback) { cb = onResultFallback; width = _width; height = _height; tt.getAlgorithmManager({ width: _width, height: _height, useSyncMode: true, requirements: ["face106"], success: (algMgr) => { console.log("get algorithm Manager ~"); console.log(algMgr); algorithmManager = algMgr.algorithmManager; }, fail: (errMsg) => { console.log(errMsg); }, complete: () => { console.log("get alg mgr complete"); }, }); } export function onFrame(cameraData) { if (algorithmManager != null) { algorithmManager.doExecute({ input: cameraData, width: width, height: height, timeStamp: Date.now() / 1e9, success: (algMgr) => { cb(algMgr); }, fail: (errMsg) => { console.log(errMsg); }, }); } }

    Bug & Tip

      Tip: 传入参数 requirements 目前仅支持单个元素数组。