feat: 点标注结果接入后台

This commit is contained in:
maxmon 2022-04-16 18:29:46 +08:00
parent dc1670bb4c
commit 9394e61f57
2 changed files with 61 additions and 34 deletions

View File

@ -1,12 +1,12 @@
<template> <template>
<div class="anno-img-box"> <div class="anno-img-box">
<div class="point-box"> <div class="point-box">
<img class="anno-img" id="anno-img" @click="addPoint($event)" :src="`data:image/jpeg;base64,${src}`" @dragstart="$event.preventDefault()" @contextmenu="$event.preventDefault()"> <img class="anno-img" id="anno-img" @click="addPoint($event)" :src="`data:image/jpeg;base64,${fileContent}`" @dragstart="$event.preventDefault()" @contextmenu="$event.preventDefault()">
<div v-for="point in points" :point="point" :key="`${point[0]}_${point[1]}`" :style="{ <div v-for="annoDetail in annoDetails" :point="annoDetail" :key="`${annoDetail.point[0]}_${annoDetail.point[1]}`" :style="{
left: point[0]*100 + '%', left: annoDetail.point[0]*100 + '%',
top: point[1]*100 + '%', top: annoDetail.point[1]*100 + '%',
backgroundColor: point.color backgroundColor: annoDetail.point.color
}" class="point" @contextmenu="$event.preventDefault();delPoint(point)" @mouseover="overPoint($event, point)"></div> }" class="point" @contextmenu="$event.preventDefault();delPoint(annoDetail)" @mouseover="overPoint($event, annoDetail)"></div>
</div> </div>
</div> </div>
</template> </template>
@ -16,10 +16,24 @@
export default ({ export default ({
name: 'CVPoint', name: 'CVPoint',
props: { props: {
src: { fileContent: {
type: String, type: String,
default: '', default: '',
required: true required: true
},
annoDetails: {
type: Array,
default: () => [],
required: true
},
nowType: {
type: String,
default: '1234',
required: true
},
save: {
type: Function,
required: true
} }
}, },
data () { data () {
@ -35,17 +49,27 @@ export default ({
}, },
addPoint (ev) { addPoint (ev) {
ev.preventDefault() ev.preventDefault()
if (!this.nowType) {
alert('请先选择标注类型')
return
}
const tar = ev.target const tar = ev.target
const newPoint = [ev.offsetX / tar.offsetWidth, ev.offsetY / tar.offsetHeight] const newPoint = [ev.offsetX / tar.offsetWidth, ev.offsetY / tar.offsetHeight]
console.log(newPoint) console.log(newPoint)
this.points.push(newPoint) // this.points.push(newPoint)
console.log(this.points) // console.log(this.points)
this.annoDetails.push({
point: newPoint,
type: this.nowType
})
this.save()
return false return false
}, },
delPoint (point) { delPoint (annoDetail) {
const idx = this.points.indexOf(point) const idx = this.annoDetails.indexOf(annoDetail)
console.log(point, this.points) console.log(annoDetail, this.points)
this.points.splice(idx, 1) this.annoDetails.splice(idx, 1)
this.save()
}, },
overPoint (ev, point) { overPoint (ev, point) {
if (ev.which === 3) { if (ev.which === 3) {
@ -54,16 +78,17 @@ export default ({
} }
}, },
watch: { watch: {
// src: { annoDetails: {
// handler (val) { handler (val) {
// const annoImg = document.getElementById('anno-img') // const annoImg = document.getElementById('anno-img')
// annoImg.src = val // annoImg.src = val
// console.log(annoImg.width) // console.log(annoImg.width)
// this.width = annoImg.width // this.width = annoImg.width
// this.height = annoImg.height // this.height = annoImg.height
// }, console.log(val)
// deep: true },
// } deep: true
}
} }
}) })
</script> </script>

View File

@ -108,7 +108,7 @@
<br v-if="word === '\n'" :key="idx"/> <br v-if="word === '\n'" :key="idx"/>
</template> </template>
</div> </div>
<CVPoint v-if="projectType === '图片点标注'" :src="nowText"></CVPoint> <CVPoint v-if="projectType === '图片点标注'" :fileContent="nowText" :annoDetails="ners" :nowType="'1234'" :save="save"></CVPoint>
</div> </div>
<div class="page-btn-box"> <div class="page-btn-box">
<button class="page-btn" @click="changeIdx(-1, $event)" @mouseover="setFocus('page-up')" @mouseleave="setFocus('')">上一个 {{ fastTypeKey['page-up'] ? `${fastTypeKey['page-up']}` : '' }}</button> <button class="page-btn" @click="changeIdx(-1, $event)" @mouseover="setFocus('page-up')" @mouseleave="setFocus('')">上一个 {{ fastTypeKey['page-up'] ? `${fastTypeKey['page-up']}` : '' }}</button>
@ -681,18 +681,20 @@ export default {
}, },
watch: { watch: {
ners: function () { ners: function () {
// ner if (this.projectType === '命名实体识别') {
let nowSmallAreaEnd // ner
for (let i = 0; i < this.ners.length; i++) { let nowSmallAreaEnd
const ner = this.ners[i] for (let i = 0; i < this.ners.length; i++) {
ner.isSmall = false const ner = this.ners[i]
if (nowSmallAreaEnd) { delete ner.isSmall
if (ner.start <= nowSmallAreaEnd) { if (nowSmallAreaEnd) {
ner.isSmall = true if (ner.start <= nowSmallAreaEnd) {
ner.isSmall = true
}
} }
if (!nowSmallAreaEnd) nowSmallAreaEnd = ner.end - 1
nowSmallAreaEnd = Math.max(nowSmallAreaEnd, ner.end - 1)
} }
if (!nowSmallAreaEnd) nowSmallAreaEnd = ner.end - 1
nowSmallAreaEnd = Math.max(nowSmallAreaEnd, ner.end - 1)
} }
} }
}, },