About me ✌️
- 🔭 I’m currently working on CanvasSelect
- 📫 How to reach me: [email protected]
Languages and Library
一个轻量级图片标注javascript库,支持矩形、多边形、点、折线、圆形,支持再编辑,使得图像标注更简单。
License: MIT License
About me ✌️
Languages and Library
希望能添加一个方法可以直接清空所有标注,现在只能一个个删除或者destroy掉
拜谢大神!
是什么原因呀
请问各位大神,有没有办法获取到全部已标注图形的位置信息?
大神您好,我们在实际开发中发现,当标注区域A位于B内部的时候,只有在不选中B的情况下才能够选中A,只要曾经选中过B,则无论如何均无法选中A。感谢大神!
Vue3+ts环境,onMounted和ref都通过插件做了全局引入
<script setup lang="ts">
import CanvasSelect from 'canvas-select'
let instance:any = ref(null);
let canvasWidth = ref(800);
let canvasHeight = ref(500);
onMounted(()=>{
instance = new CanvasSelect(
".canvas_container",
"https://gd-hbimg.huaban.com/cf8c6c0ccff0356a46b3ebe3e6fbb3992442398245a34-ivJ4iC"
);
})
</script>
<template>
<canvas class="container"></canvas>
</template>
<script setup>
import CanvasSelect from "canvas-select";
const instance = new CanvasSelect(
".container",
"https://cdn.jsdelivr.net/npm/@heylight/cdn@%5E1/img/onepiece.png"
);
const option = [
{
label: "rect",
labelFillStyle: "#f00",
textFillStyle: "#fff",
fillStyle: "rgba(130,22,220,.6)",
coor: [
[184, 183],
[275, 238]
],
type: 1
},
{
label: "polygon",
active: true,
coor: [
[135, 291],
[129, 319],
[146, 346],
[174, 365],
[214, 362],
[196, 337],
[161, 288]
],
type: 2
},
{
label: "dot",
coor: [345, 406],
type: 3
},
{
label: "line",
coor: [
[470, 155],
[503, 230],
[506, 298]
],
type: 4
},
{
label: "circle",
coor: [369, 197],
radius: 38,
type: 5
}
];
instance.labelMaxLen = 10;
instance.setData(option);
// 选中
instance.on("load", (src) => {
console.log("image loaded", src);
});
// 添加
instance.on("add", (info) => {
console.log("add", info);
window.info = info;
});
// 删除
instance.on("delete", (info) => {
console.log("delete", info);
window.info = info;
});
// 选中
instance.on("select", (shape) => {
console.log("select", shape);
window.shape = shape;
});
instance.on("updated", (result) => {
// console.log('标注结果', result)
const list = [...result];
list.sort((a, b) => a.index - b.index);
output.value = JSON.stringify(list, null, 2);
});
function change(num) {
instance.createType = num;
}
function zoom(type) {
instance.setScale(type);
}
function fitting() {
instance.fitZoom();
}
function changeData() {
const data = JSON.parse(output.value);
instance.setData(data);
}
function onFocus() {
instance.setFocusMode(!instance.focusMode);
}
</script>
<style scoped>
</style>
使用环境:
vue3.2 + vite4.3
问题呈现:
canvas标签在template中固定时,通过ref获取到canvas后,绘制正常;
动态更新src后,mousedown
时就会一直屏闪复现上一图层标注后的shape
每次 mousemove 均会清除图片以及标注,然后重新绘制图片和标注。是否考虑给 mousemove 事件加上节流,否则一次标注触发上百次重绘了
作者您好,能不能加一个取消选中监听事件
建议作者添加标签label的鼠标选中事件
如题:
我看到实例上有 instance.scale 的属性能拿到具体尺寸,但是setScale()方法貌似不支持设置比例大小,只能通过设置ture不断增大尺寸。
我的需求是,如果在按一下删除键,这时如果选中了某个标签,我就把这个标签删除掉,现在有选中事件,但如果我选中一个标签,然后又点了一下图片,这时所有图片都未选中,但这时并没有事件触发,如果这是按了一下删除键,但这时我又不知道这个标签是不是实际选中状态的,所以我不知道该不该删除这个标签,不知道我说明白了没。辛苦作者了,谢谢!
希望矩形那些能支持下旋转不同角度,谢谢
如何获取多边形的面积?
<template>
<main>
<div class="part0"></div>
<div class="part1">
<canvas class="can0"></canvas>
</div>
<div class="part2">
<div></div>
<div></div>
</div>
</main>
</template>
<script setup>
import {watch} from "vue";
import CanvasSelect from "canvas-select";
const can1 = new CanvasSelect('can0', 'https://unpkg.com/[email protected]/one.jpg');
let props = defineProps({
int0: {
type: Number,
default: 0
}
});
watch(props, (val) => {
console.log(val.int0);
});
</script>
大神您好,可以考虑新增change(6)作为框选模式,功能为拖拽一个选择框,对框内的已标注图形进行全选。
感谢大佬~
要是能支持 tiles 瓦片图就更棒了,我们可以预先将一张大图生成瓦片图。这样能加载的更快点。
矩形 不规则图形 点 都可以 线段不能花?
如果监听update或者instance.dataset,框在变化的时候,每时每刻都在调用。我想要的是结束框选之后的时机,
形状边线可以自定义颜色,如何自定义线的宽度?
新版本在调用change(1-5)之后,需要调用change(0),点击标注图形内部才能选中已标注内容,建议可以考虑跳过change(0)的步骤,在”创建模式“下点击已标注内容内部来实现对已标注内容的选中。
感谢大神维护了如此优秀的项目!
如全局的实例属性 如fillStyle,后期能否支持 自定义,谢谢
在有框选区域时,动态切换图片后,点击切换后的图片上的框选区域会跳到上一张图片,再次点击会又跳回去
希望新增 window.resize 的事件
锁定画布为何无法编辑标注
请问 事件 具体支持哪些事件呢?比如双击事件是不是dbclick呢?
我这边需要一个可以画一个固定宽高比的长方形,不知道是否可以帮忙加上,
又或者能否指导我给加上?目前项目比较着急需要这个,感谢!
就是在画的时候,是个长方形,长宽比是固定的,比如16:9,我拉任何一边时,增加或缩小,都是按16:9的比例进行变化的,
不知道我说明白了没。
第一次调用setScale进行缩小时,缩小比例大于5%,导致再次调用setScale放大时,恢复不到原始比例,后续缩放比例正常。
边界问题,有时候拖拽,任意操作,会出现-1的坐标。
由于firefox不支持touchEvent constructor,所以firefox无法使用该仓库进行标注
首先感谢作者.
我现在有一个需求, 就是希望要有一个查看模式, 用户只能点击选中某个形状, 但是不能拖动, 改变, 删除形状. 但是在 createType为-1时, 用户确实不能拖动形状, 但是却可以删除和改变形状.
如果用 lock 模式的话, 虽然是不能删除和改变了, 但是用户也不能选中形状了, 同时也不能放大图片.
想请教一下, 有什么办法能阻止用户的删除, 改变形状的形为吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.