浏览代码

[FE]进出记录详情页面添加识别方框

liuwenxun 4 年之前
父节点
当前提交
232317f8d4
共有 1 个文件被更改,包括 54 次插入3 次删除
  1. 54 3
      security-protection-platform/src/modules/access/index.vue

+ 54 - 3
security-protection-platform/src/modules/access/index.vue

@ -82,8 +82,9 @@ s<template>
82 82
          <div class="detail_item1">
83 83
            <div>抓拍图片</div>
84 84
            <div>
85
              <img :src="rowdata.pictureInfo.fileUrl" alt="" srcset="" style="width:100%;height:100%">
86

85
              <!-- <img :src="rowdata.pictureInfo.fileUrl" alt="" srcset="" style="width:100%;height:100%"> -->
86
              <!--处理图片里的方框-->
87
              <img :src="mainimage" alt="" srcset="" style="width:100%;height:100%">
87 88
            </div>
88 89
          </div>
89 90
          <div class="detail_item2">
@ -185,7 +186,9 @@ export default {
185 186

186 187
      // }
187 188
      // 截取后的图片
188
      newimage: ''
189
      newimage: '',
190
      // 详情的主图片
191
      mainimage: ''
189 192

190 193
    }
191 194
  },
@ -215,6 +218,8 @@ export default {
215 218
      // this.rowdata = scope.row
216 219
      // console.log(this.rowdata)
217 220
      // console.log('id是', scope.row.aiIdenLogId)
221
      this.newimage = ''
222
      this.mainimage = ''
218 223
      var res = await accessapi.getOneInAndOutRecord({ params: { aiIdenLogId: scope.row.aiIdenLogId } })
219 224

220 225
      if (res.data.success) {
@ -226,6 +231,7 @@ export default {
226 231
        // this.rowdata.alarmInfo.newImg = this.rowdata.pictureInfo.fileUrl
227 232

228 233
        this.getImage()
234
        this.getmainimage()
229 235
        // var loadTimer
230 236
        // var imgObject = new Image()
231 237
        // imgObject.setAttribute('crossOrigin', 'anonymous')
@ -360,6 +366,7 @@ export default {
360 366
        return true
361 367
      }
362 368
    },
369
    // 处理截图图片
363 370
    async getImage () {
364 371
      var loadTimer
365 372
      var imgObject = new Image()
@ -392,6 +399,50 @@ export default {
392 399
        // console.log(tnCanvas.toDataURL())
393 400
        return tnCanvas.toDataURL()
394 401
      }
402
    },
403

404
    // 处理主图片
405
    async getmainimage () {
406
      var that = this
407

408
      var x = this.rowdata.alarmInfo.face_box[0]
409
      var y = this.rowdata.alarmInfo.face_box[1]
410
      var width = this.rowdata.alarmInfo.face_box[2] - this.rowdata.alarmInfo.face_box[0]
411
      var height = this.rowdata.alarmInfo.face_box[3] - this.rowdata.alarmInfo.face_box[1]
412
      function getBase64Image (img) {
413
        var canvas = document.createElement('canvas')
414
        canvas.width = img.width
415
        canvas.height = img.height
416
        var ctx = canvas.getContext('2d')
417
        ctx.drawImage(img, 0, 0, img.width, img.height)
418
        ctx.beginPath()
419
        ctx.moveTo(x, y)
420
        ctx.lineTo(x + width, y)
421
        ctx.lineTo(x + width, y + height)
422
        ctx.lineTo(x, y + height)
423
        ctx.lineTo(x, y) // 绘制最后一笔使图像闭合
424
        ctx.lineWidth = 5
425
        ctx.strokeStyle = 'red'
426
        ctx.stroke()
427

428
        var dataURL = canvas.toDataURL('image/png') // 可选其他值 image/jpeg
429
        return dataURL
430
      }
431

432
      function main (src, cb) {
433
        var image = new Image()
434
        image.src = src + '?v=' + Math.random() // 处理缓存
435
        image.crossOrigin = '*' // 支持跨域图片
436
        image.onload = function () {
437
          var base64 = getBase64Image(image)
438
          cb && cb(base64)
439
        }
440
      }
441

442
      main(this.rowdata.pictureInfo.fileUrl, function (base64) {
443
        // console.log(base64, '是否成功打印base64')
444
        that.mainimage = base64
445
      })
395 446
    }
396 447

397 448
  }