uni App+H5 实现人脸识别

uni App+H5 实现人脸识别

通过h5的视频video管理设备摄像头(不要关),在打开视频摄像时快照截取人脸照片传送到后台通过API接口调用百度人脸识别结果并通过返回数据解析自己业务需求。
    1.创建LivePusher对象
that.pusher = plus.video.createLivePusher(livepusher, {
				url: ,
				top: 0px,
				left: 0px,
				width: 50%,
				height: 50%,
				position: absolute,
				aspect: 9:16,
				z-index: 999
			});
			currentWebview.append(that.pusher);
			that.pusher.preview();
    2.调取拍照事件snapshot
that.snapshTimeout = setTimeout(() => {
				that.pusher.snapshot(
					e => {
						var src = e.tempImagePath;
						that.imgToBase(src);
					},
					function(e) {
						plus.nativeUI.alert(snapshot error:  + JSON.stringify(e));
					}
				);
			}, that.snapshotTimeoutNumber);
    3.压缩图片并转换base64(我用的百度云人脸所以这里直接转换成base64)
plus.zip.compressImage(
				{
					src: imgPath,
					dst: imgPath,
					overwrite: true,
					quality: 40
				},
				zipRes => {
					setTimeout(() => {
						var reader = new plus.io.FileReader();
						reader.onloadend = res => {
							var speech = res.target.result; 
						};
						reader.readAsDataURL(plus.io.convertLocalFileSystemURL(zipRes.target));
					}, 1000);
				},
				function(error) {}
			);
    4.将图片传给后台调用百度云人脸库API比对返回结果。
经验分享 程序员 微信小程序 职场和发展