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);
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值