ai-label的基础用法(根据坐标点在图片上给出标识框)

// 根据坐标点图片画框
    addPicMarker(it, boundary, index) {
      // Boundary:"666 116,666 159,712 159,712 116"(左下角,左上角,右上角,右下角)
      // console.log(boundary)
      const leftX = boundary.split(",")[0].split(" ")[0]
      const rightX = boundary.split(",")[2].split(" ")[0]
      const bottomY = boundary.split(",")[0].split(" ")[1]
      const topY = boundary.split(",")[1].split(" ")[1]

      const gMap = new AILabel.Map(`dialog${index}`, {
        center: { x: 300, y: 174 }, // 根据图片在dom元素的宽高设置居中
        zoom: 600,
        mode: "PAN", // 绘制线
      })
      const gFirstImageLayer = new AILabel.Layer.Image(
        `layer${index}`, // id
        {
          src: it,
          width: 600, // 图片宽度
          height: 348, // 图片高度
          crossOrigin: false, // 图片是否跨域
          position: {
            // 图片左上角对应的坐标位置
            x: 0,
            y: 0,
          },
        }, // imageInfo
        { name: "第一个图片图层" }, // props
        { zIndex: 5 } // style
      );
      gMap.addLayer(gFirstImageLayer)

      // Boundary:"666 116,666 159,712 159,712 116"(左下角,左上角,右上角,右下角)
      const gFirstFeatureLayer = new AILabel.Layer.Feature(
        `feature${index}`, // id
        { name: "第一个矢量图层" }, // props
        { zIndex: 10 } // style
      );
      gMap.addLayer(gFirstFeatureLayer);
      const gFirstFeaturePolygon = new AILabel.Feature.Polygon(
        `polygon${index}`, // id
        {
          points: [
            // ()
            {
              x: leftX / (this.imgWidth / 600),
              y: bottomY / (this.imgHeight / 348),
            },
            {
              x: leftX / (this.imgWidth / 600),
              y: topY / (this.imgHeight / 348),
            },
            {
              x: rightX / (this.imgWidth / 600),
              y: topY / (this.imgHeight / 348),
            },
            {
              x: rightX / (this.imgWidth / 600),
              y: bottomY / (this.imgHeight / 348),
            },
          ],
        }, // shape
        { name: "第一个多边形" }, // props
        { strokeStyle: "#FFD500", lineWidth: 2 } // style
      )
      gFirstFeatureLayer.addFeature(gFirstFeaturePolygon)
      this.groupList[index].gmapLoading = false
      // this.$set(this.relaGroup[index].tas)
      this.gMap[index] = gMap
      this.gFirstFeatureLayer[index] = gFirstFeatureLayer
      this.gFirstImageLayer[index] = gFirstImageLayer
    }

效果图呈现


image.png

备注:ai-label只能在已存在的dom元素中挂载
附官方链接:http://ailabel.com.cn/public/ailabel/api/index.html#103

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容