chrome人脸监测electron方案支持

这个功能默认是没有开启的,需要从这里开启

chrome://flags/#enable-experimental-web-platform-features

electron 设置开启方式

const { app } = require('electron')
app.commandLine.appendSwitch('enable-experimental-web-platform-features','enable')

体验地址: https://ibeeger.com/pages/face.html

如果开启可以支持脸部、文本、条形码的识别

  • FaceDetector
  • TextDetector
  • BarcodeDetector

FaceDetector

var faceDetector = new FaceDetector({fastMode: false, maxDetectedFaces: 5});
var canvas = document.createElement('canvas');
function loadface () {
  let url = document.getElementById('url').value
  var image = document.getElementById('img');
      faceDetector.detect(image).then(function (faces) {
          faces.forEach(function (item) {
            canvas.width = Math.floor(item.boundingBox.width)                          
            canvas.height = Math.floor(item.boundingBox.height)
            let ctx = canvas.getContext('2d');
            ctx.drawImage(image, Math.floor(item.boundingBox.left), Math.floor(item.boundingBox.top), Math.floor(item.boundingBox.width), Math.floor(item.boundingBox.height), 0,0,  Math.floor(item.boundingBox.width), Math.floor(item.boundingBox.height));
            let img =document.createElement('img');
            img.src = canvas.toDataURL();
            document.body.appendChild(img);
            ctx.clearRect(0,0, item.boundingBox.width, item.boundingBox.height);
          })
      }).catch(function (err) {
          console.log("err",err)
      });
}

TextDetector

let textDetector = new TextDetector();
// Assuming |theImage| is e.g. a <img> content, or a Blob.

textDetector.detect(theImage)
.then(detectedTextBlocks => {
  for (const textBlock of detectedTextBlocks) {
    console.log(
        'text @ (${textBlock.boundingBox.x}, ${textBlock.boundingBox.y}), ' +
        'size ${textBlock.boundingBox.width}x${textBlock.boundingBox.height}');
  }
}).catch(() => {
  console.error("Text Detection failed, boo.");
})

BarcodeDetector

const barcodeDetector = new BarcodeDetector({
  // (Optional) A series of barcode formats to search for.
  // Not all formats may be supported on all platforms
  formats: [
    'aztec',
    'code_128',
    'code_39',
    'code_93',
    'codabar',
    'data_matrix',
    'ean_13',
    'ean_8',
    'itf',
    'pdf417',
    'qr_code',
    'upc_a',
    'upc_e'
  ]
});
try {
  const barcodes = await barcodeDetector.detect(image);
  barcodes.forEach(barcode => console.log(barcode));
} catch (e) {
  console.error('Barcode detection failed:', e);
}

这个就没什么说的了,直接获取条形码的的数据了

文章来源: chrome人脸监测electron方案支持