200余行代码,Github 3.4k星,让你实时从视频中隐身
持续推送技术干货
const bodyPixProperties = {
  architecture: 'MobileNetV1',
  outputStride: 16,
  multiplier: 0.75,
  quantBytes: 4
}; 
// Go through pixels and figure out bounding box of body pixels.
  for (let x = 0; x < canvas.width; x++) {
    for (let y = 0; y < canvas.height; y++) {
      let n = y * canvas.width + x;
      // Human pixel found. Update bounds.
      if (segmentation.data[n] !== 0) {
        if(x < minX) {
          minX = x;
        }
        if(y < minY) {
          minY = y;
        }
        if(x > maxX) {
          maxX = x;
        }
        if(y > maxY) {
          maxY = y;
        }
        foundBody = true;
      }
    } 
  } 
// Calculate dimensions of bounding box.
  var width = maxX - minX;
  var height = maxY - minY;
  // Define scale factor to use to allow for false negatives around this region.
  var scale = 1.3;
  //  Define scaled dimensions.
  var newWidth = width * scale;
  var newHeight = height * scale;
  // Caculate the offset to place new bounding box so scaled from center of current bounding box.
  var offsetX = (newWidth - width) / 2;
  var offsetY = (newHeight - height) / 2;
  var newXMin = minX - offsetX;
  var newYMin = minY - offsetY; 
// Now loop through update backgound understanding with new data
  // if not inside a bounding box.
  for (let x = 0; x < canvas.width; x++) {
    for (let y = 0; y < canvas.height; y++) {
      // If outside bounding box and we found a body, update background.
      if (foundBody && (x < newXMin || x > newXMin + newWidth) || ( y < newYMin || y > newYMin + newHeight)) {
        // Convert xy co-ords to array offset.
        let n = y * canvas.width + x;
        data[n * 4] = dataL[n * 4];
        data[n * 4 + 1] = dataL[n * 4 + 1];
        data[n * 4 + 2] = dataL[n * 4 + 2];
        data[n * 4 + 3] = 255;            
      } else if (!foundBody) {
        // No body found at all, update all pixels.
        let n = y * canvas.width + x;
        data[n * 4] = dataL[n * 4];
        data[n * 4 + 1] = dataL[n * 4 + 1];
        data[n * 4 + 2] = dataL[n * 4 + 2];
        data[n * 4 + 3] = 255;    
      }
    }
  }
  ctx.putImageData(imageData, 0, 0);
  if (DEBUG) {
    ctx.strokeStyle = "#00FF00"
    ctx.beginPath();
    ctx.rect(newXMin, newYMin, newWidth, newHeight);
    ctx.stroke();
  }
} 
来源:机器之心
在这金三银四的季节,栈长为大家准备了四份面试宝典:
《java面试宝典5.0》
《Java(BAT)面试必备》
《350道Java面试题:整理自100+公司》
《资深java面试宝典-视频版》
分别适用于初中级,中高级,以及资深级工程师的面试复习。
内容包含java基础、javaweb、各个性能优化、JVM、锁、高并发、反射、Spring原理、微服务、Zookeeper、数据库、数据结构、限流熔断降级等等。
获取方式:点“在看”,V信扫描上面二维码:注明面试领取,更多精彩陆续奉上。
