1 Star 0 Fork 1

LiuRuizhou / label-img

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

图片标注工具

image annotation tool with javascript

本工具专注图形标注,不局限某种方式与格式,只输出关键点位信息,不与业务逻辑耦合,并提供方法自定义展示方式与实体属性填写的实现(持续开发当中,文档更新可能滞后)

示例

基础示例

安装

npm install label-img

or

  <script src="./labelImg.js"></script>

使用

/**
 * 生成实例
 * @element   挂载节点
 * @options   配置 非必填
 */
const labeler = new LabelImg(element, {
  width: 800,
  height: 600,
  bgColor: `#000`, // 背景色
  imagePlacement: "default", // default | center
})
// 注册图形
labeler.register("polygon", {
  type: "Polygon",
  tag: "多边形",
})
// 加载图片
labeler.load(url)
// 选择标注多边形
labeler.label("polygon")

图形

const { Shape } from "label-img"
// or
const Shape = LabelImg.Shape

// IShapeOptions
const shapeOptions = {
  id, // 图形唯一id 可自动生成
  type, // 图形类型 必填 Polygon | Ract
  name, // 图形名称
  positions, // 坐标集合 ex: [[0, 0], [100, 100]]
  data, // 自定义数据 可用于存储实体属性等内容
  tag, // 展示在图形上的说明标签
  showTag, // 是否展示标签
  closed, // 是否闭合
  visible, // 是否可见
  active, // 是否被选中
  disabled, // 是否禁用
  /**
   * { normal, active, disabled }
   * {
   *  normal: {
   *    dotColor: "red", // 坐标点颜色
   *    dotRadius: 3, // 坐标点大小
   *    lineColor: "#c30", // 连线颜色
   *    lineWidth: 2, // 连线宽度
   *    fillColor: "pink", // 填充色
   *  }
   * }
   */
  style, // 图形样式
}
const shape = new Shape(shapeOptions)
// or
/**
 * @id      图形注册ID
 * @options 配置  Partial<Omit<IShapeOptions, "type">>
 */
const shape = LabelImg.createShape(id, options)
// 添加到画布中
labeler.addShape(shape)

注册图形

/**
 * @id        图形ID   Polygon: 多边形, Ract: 矩形
 * @options   图形配置  Omit<IShapeCfg, "registerID">
 */
labeler.register(id, options)

加载图片

/**
 * @param   url || file
 * return   Promise
 */
labeler.load(param)

labeler API

isRegister(id)  // 判断是否注册
label(id, continuity)  // 选择标注类型
labelOff()  // 取消当前标注
addShape(shape, index)  // 添加图形
remove(shape || id)  // 删除图形
setActive(shape)  // 选中某一图形
getShapeList()  // 获取图形列表
setGuideLine(status?: boolean)  // 是否启用参照线
setTagShow(status?: boolean)  // 是否启用标签
isTagShow()  // 获取是否启用标签
toDataURL()  // 导出标注图片的base64格式
setContinuity(status: boolean)  // 设置是否连续标注
render()  // 渲染画面
forceRender()  // 强制渲染

Shape API

getPositions()  // 获取坐标点集合
updatePositions(positions) // 更新坐标信息
setActive(status) // 设置选中
isActive()  // 是否被选中
close()  // 图形闭合
isClose()  // 是否闭合
disabled() //禁用
isDisabled()  // 是否禁用
hidden()  // 隐藏
isHidden()  // 是否隐藏
show()  // 显示
isShowTag()  // 是否展示标签
tagShow(status?: boolean) // 控制标签展示
setTag(val)  // 标签内容
MIT License Copyright (c) 2020 hold-baby Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

label-img插件 源地址https://github.com/hold-baby/label-img 修复了一些bug以及自适应位置或图片显示不全 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/mangguoshij_mayun/label-img.git
git@gitee.com:mangguoshij_mayun/label-img.git
mangguoshij_mayun
label-img
label-img
master

搜索帮助