提交代码
This commit is contained in:
		
							parent
							
								
									65c63d3317
								
							
						
					
					
						commit
						1faa3b88cc
					
				| 
						 | 
					@ -5,8 +5,8 @@
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import LabelStudio from 'label-studio';
 | 
					import LabelStudio from 'label-studio'
 | 
				
			||||||
import 'label-studio/build/static/css/main.css';
 | 
					import 'label-studio/build/static/css/main.css'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
  name: 'CustomLabelStudio',
 | 
					  name: 'CustomLabelStudio',
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ export default {
 | 
				
			||||||
          name: "自定义按钮",
 | 
					          name: "自定义按钮",
 | 
				
			||||||
          icon: "🔍",
 | 
					          icon: "🔍",
 | 
				
			||||||
          action: () => {
 | 
					          action: () => {
 | 
				
			||||||
            console.log("自定义按钮被点击了!");
 | 
					            console.log("自定义按钮被点击了!")
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      ],
 | 
					      ],
 | 
				
			||||||
| 
						 | 
					@ -40,6 +40,7 @@ export default {
 | 
				
			||||||
        "RELATIONS": "关系",
 | 
					        "RELATIONS": "关系",
 | 
				
			||||||
        "REGIONS": "区域",
 | 
					        "REGIONS": "区域",
 | 
				
			||||||
        "RESULTS": "结果",
 | 
					        "RESULTS": "结果",
 | 
				
			||||||
 | 
					        // 添加更多需要翻译的文本...
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      labelConfig: `
 | 
					      labelConfig: `
 | 
				
			||||||
        <View>
 | 
					        <View>
 | 
				
			||||||
| 
						 | 
					@ -50,9 +51,12 @@ export default {
 | 
				
			||||||
          </RectangleLabels>
 | 
					          </RectangleLabels>
 | 
				
			||||||
        </View>
 | 
					        </View>
 | 
				
			||||||
      `,
 | 
					      `,
 | 
				
			||||||
      previousAnnotations: [] // 用于保存上次的标注框数据
 | 
					      previousAnnotations: [] // 用于保存上次的标注框数据,用于比较变化
 | 
				
			||||||
    };
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					  watch:{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  mounted() {
 | 
					  mounted() {
 | 
				
			||||||
    this.initLabelStudio();
 | 
					    this.initLabelStudio();
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
| 
						 | 
					@ -75,53 +79,30 @@ export default {
 | 
				
			||||||
          firstName: "James",
 | 
					          firstName: "James",
 | 
				
			||||||
          lastName: "Dean"
 | 
					          lastName: "Dean"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        task: JSON.parse(this.task),
 | 
					        task:JSON.parse( this.task),
 | 
				
			||||||
        locale: 'zh_CN',
 | 
					        locale: 'zh_CN',
 | 
				
			||||||
        messages: this.chineseLocalization,
 | 
					        messages: this.chineseLocalization,
 | 
				
			||||||
        onLabelStudioLoad: (LS) => {
 | 
					        onLabelStudioLoad: (LS) => {
 | 
				
			||||||
          console.log("Label Studio 已加载", LS);
 | 
					          console.log("Label Studio 已加载", LS);
 | 
				
			||||||
          var c = LS.annotationStore.addAnnotation({
 | 
					
 | 
				
			||||||
 | 
					          // 定期检查标注框数据
 | 
				
			||||||
 | 
					          setInterval(() => {
 | 
				
			||||||
 | 
					            this.checkAnnotations(LS);
 | 
				
			||||||
 | 
					          }, 1000);  // 每秒检查一次
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          // 手动添加一个标注框并选中
 | 
				
			||||||
 | 
					          const annotation = LS.annotationStore.addAnnotation({
 | 
				
			||||||
            userGenerate: true
 | 
					            userGenerate: true
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
          LS.annotationStore.selectAnnotation(c.id);
 | 
					          // 获取并输出标注的几何信息
 | 
				
			||||||
          // 注册事件监听
 | 
					          const box = annotation.geometry;
 | 
				
			||||||
          LS.annotationStore.events.on('addAnnotation', this.handleAddAnnotation);
 | 
					 | 
				
			||||||
          LS.annotationStore.events.on('updateAnnotation', this.handleUpdateAnnotation);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          // 启动定期检查标注框数据
 | 
					 | 
				
			||||||
          this.startAnnotationCheck(LS);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 处理新增标注框
 | 
					 | 
				
			||||||
    handleAddAnnotation(annotation) {
 | 
					 | 
				
			||||||
      console.log("新增标注框:", annotation);
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 处理更新标注框
 | 
					 | 
				
			||||||
    handleUpdateAnnotation(annotation) {
 | 
					 | 
				
			||||||
      console.log("更新标注框:", annotation);
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 启动定期检查标注框数据
 | 
					 | 
				
			||||||
    startAnnotationCheck(LS) {
 | 
					 | 
				
			||||||
      this.checkAnnotationsInterval = setInterval(() => {
 | 
					 | 
				
			||||||
        this.checkAnnotations(LS);
 | 
					 | 
				
			||||||
      }, 1000); // 每秒检查一次
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 停止定期检查
 | 
					 | 
				
			||||||
    stopAnnotationCheck() {
 | 
					 | 
				
			||||||
      if (this.checkAnnotationsInterval) {
 | 
					 | 
				
			||||||
        clearInterval(this.checkAnnotationsInterval);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 检查标注框数据
 | 
					    // 检查标注框数据
 | 
				
			||||||
    checkAnnotations(LS) {
 | 
					    checkAnnotations(LS) {
 | 
				
			||||||
      const currentAnnotations = LS.annotationStore.data;  // 获取当前的标注数据
 | 
					      const currentAnnotations = LS.annotationStore.data;  // 获取当前的标注数据
 | 
				
			||||||
 | 
					 | 
				
			||||||
      // 如果标注数据发生了变化
 | 
					      // 如果标注数据发生了变化
 | 
				
			||||||
      if (this.hasAnnotationsChanged(currentAnnotations)) {
 | 
					      if (this.hasAnnotationsChanged(currentAnnotations)) {
 | 
				
			||||||
        console.log('标注数据发生变化:', currentAnnotations);
 | 
					        console.log('标注数据发生变化:', currentAnnotations);
 | 
				
			||||||
| 
						 | 
					@ -131,20 +112,15 @@ export default {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // 比较标注数据是否发生变化
 | 
					    // 比较标注数据是否发生变化
 | 
				
			||||||
    hasAnnotationsChanged(currentAnnotations) {
 | 
					    hasAnnotationsChanged(currentAnnotations) {
 | 
				
			||||||
      // 直接比较标注数量变化
 | 
					 | 
				
			||||||
      if (currentAnnotations.length !== this.previousAnnotations.length) {
 | 
					      if (currentAnnotations.length !== this.previousAnnotations.length) {
 | 
				
			||||||
        return true; // 数量不一样说明发生了变化
 | 
					        return true; // 数量不一样说明发生了变化
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // 比较每个标注框的 ID 和几何信息(减少深度比较)
 | 
					      // 比较每个标注框的几何信息
 | 
				
			||||||
      for (let i = 0; i < currentAnnotations.length; i++) {
 | 
					      for (let i = 0; i < currentAnnotations.length; i++) {
 | 
				
			||||||
        const current = currentAnnotations[i];
 | 
					        const current = currentAnnotations[i];
 | 
				
			||||||
        const previous = this.previousAnnotations[i];
 | 
					        const previous = this.previousAnnotations[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (current.id !== previous.id) {
 | 
					 | 
				
			||||||
          return true; // 标注 ID 不同说明发生了变化
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // 如果标注框的几何信息有变化,返回 true
 | 
					        // 如果标注框的几何信息有变化,返回 true
 | 
				
			||||||
        if (JSON.stringify(current.geometry) !== JSON.stringify(previous.geometry)) {
 | 
					        if (JSON.stringify(current.geometry) !== JSON.stringify(previous.geometry)) {
 | 
				
			||||||
          return true;
 | 
					          return true;
 | 
				
			||||||
| 
						 | 
					@ -154,7 +130,7 @@ export default {
 | 
				
			||||||
      return false;
 | 
					      return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					}
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<style scoped>
 | 
					<style scoped>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue