PC端调用摄像头扫描二维码,拿到二维码信息

<template><el-dialogtitle="扫描设备二维码":visible.sync="dialogVisible"width="40%"@close="closeCamera"><main class="reader"><el-inputv-model="result"style="width: 80% "type="textarea":rows="2"placeholder="二维码识别结果"/><button class="sweep" @click="media()">扫一扫</button></main><canvas ref="canvas" class="canvas" /><span slot="footer" class="dialog-footer"><el-button size="small" @click="dialogVisible = false">取 消</el-button><el-button type="primary" size="small" @click="onConfirm">确 定</el-button></span></el-dialog>
</template><script>
import jsQR from 'jsqr'
// import Jimp from 'jimp'
export default {name: 'Reader',data() {return {dialogVisible: false,timer: null,result: '',isAnimation: true,audio: Object,video: Object,cvsele: Object,canvas: Object}},methods: {show(val) {this.dialogVisible = truethis.$nextTick(() => {this.result = valthis.audio = new Audio('../assets/tone.mp3')this.video = document.createElement('video')this.cvsele = this.$refs.canvasthis.canvas = this.cvsele.getContext('2d')this.canvas.clearRect(0, 0, this.cvsele.width, this.cvsele.height)this.cvsele.style.display = 'none'})},draw(begin, end) {this.canvas.beginPath()this.canvas.moveTo(begin.x, begin.y)this.canvas.lineTo(end.x, end.y)this.canvas.lineWidth = 3this.canvas.strokeStyle = 'red'this.canvas.stroke()},sweep() {if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {const { videoWidth, videoHeight } = this.videothis.cvsele.width = videoWidththis.cvsele.height = videoHeightthis.canvas.drawImage(this.video, 0, 0, videoWidth, videoHeight)try {const img = this.canvas.getImageData(0, 0, videoWidth, videoHeight)this.imgurl = imgconst obj = jsQR(img.data, img.width, img.height, {inversionAttempts: 'dontInvert'})if (obj) {const loc = obj.locationthis.draw(loc.topLeftCorner, loc.topRightCorner)this.draw(loc.topRightCorner, loc.bottomRightCorner)this.draw(loc.bottomRightCorner, loc.bottomLeftCorner)this.draw(loc.bottomLeftCorner, loc.topLeftCorner)if (this.result !== obj.data) {this.audio.play()this.result = obj.datathis.isAnimation = falsecancelAnimationFrame(this.timer)setTimeout(() => {this.cvsele.style.display = 'none'}, 1000)} else {console.log(this.result !== obj.data)alert('重复的二维码,请检查后重新扫描!')}}/*  else {console.error('识别失败,请检查二维码是否正确!0000')}*/} catch (err) {console.error('识别失败,请检查二维码是否正确!', err)}}if (this.isAnimation) {this.timer = requestAnimationFrame(() => {this.sweep()})}},media() {this.isAnimation = truethis.cvsele.style.display = 'block'navigator.getUserMedia =navigator.getUserMedia ||navigator.webkitGetUserMedia ||navigator.mozGetUserMedia ||navigator.msGetUserMediaif (navigator.mediaDevices) {navigator.mediaDevices.getUserMedia({video: { facingMode: 'environment' }}).then((stream) => {this.video.srcObject = streamthis.video.setAttribute('playsinline', true)this.video.setAttribute('webkit-playsinline', true)this.video.addEventListener('loadedmetadata', () => {this.video.play()this.sweep()})}).catch((error) => {console.error(error.name + ':' + error.message + ',' + error.constraint)})} else if (navigator.getUserMedia) {navigator.getUserMedia({video: { facingMode: 'environment' }},(stream) => {this.video.srcObject = streamthis.video.setAttribute('playsinline', true)this.video.setAttribute('webkit-playsinline', true)this.video.addEventListener('loadedmetadata', () => {this.video.play()this.sweep()})},(error) => {console.error(error.name + ':' + error.message + ',' + error.constraint)})} else {if (navigator.userAgent.toLowerCase().match(/chrome/) &&location.origin.indexOf('https://') < 0) {/* console.error('获取浏览器录音功能,因安全性问题,需要在localhost 或 127.0.0.1 或 https 下才能获取权限!')*/alert('获取浏览器拍照/录音功能,因安全性问题,需要在https 下才能获取权限!')} else {alert('对不起:未识别到扫描设备!')}}},onConfirm() {if (this.result) {this.dialogVisible = falsethis.$emit('fromChild', this.result)this.closeCamera()} else {alert('请扫描二维码')}},// 关闭摄像头closeCamera() {const stream = this.video.srcObjectif (stream) {console.log(stream, 'ppppppppppp')const tracks = stream.getTracks()tracks.forEach(track => {track.stop()})this.video.srcObject = null}}}
}
</script><style lang="less">.reader {font-size: 16px;margin-bottom: 20px;.imgurl {margin: 20px;text-align: center;img {margin: 20px;padding: 10px;border: 1px solid gray;border-radius: 8px;width: 280px;height: 260px;}}.result {box-sizing: border-box;padding: 10px;border: 1px solid gray;border-radius: 8px;font-size: 16px;}}.sweep {position: relative;padding: 12px;font-size: 18px;cursor: pointer;color: white;background: #42b983;border: 1px solid #42b983;overflow: hidden;input {position: absolute;font-size: 100px;opacity: 0;}.canvas {display: none;box-sizing: border-box;position: fixed;top: 0;bottom: 0;left: 20px;}}
</style>

PC端调用摄像头扫描二维码,拿到二维码信息相关推荐

  1. vue实现PC端调用摄像头拍照人脸录入、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式

    PC端调用摄像头拍照上传base64格式到后台,这个没什么花里胡哨的骚操作,直接看代码 (canvas + video) <template><div><!--开启摄像头 ...

  2. JS PC端调用摄像头录视频截图上传文件

    创建 Catcher 类 class Catcher {URL; // 上传地址dataStream; // 流数据mediaStream; //媒体流mediaRecorder; //录制对象sta ...

  3. vue移动端页面调用手机拍照_vue实现PC端调用摄像头拍照、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式...

    export default { () { return {} }, methods: { # // 压缩图片 and 旋转角度纠正 下方代码 # 需要自行去掉 个人只作为着色效果加上 compres ...

  4. PC端调用摄像头并拍照

    该博主的方法在mac本子上测试成功.原文连接: https://juejin.cn/post/6955290885806358564

  5. C#生成二维码、调用摄像头扫描二维码

    二维码的生成和解码,有两个开源项目可以参考: 一个是google的zxing,另外一个是ThroughWork. zxing做的很全面,支持各种语言和平台,具体不多讲,自己查去.ThroughWork ...

  6. vue 调用pc端本地摄像头、麦克风实现拍照、录视频、录音 并上传到服务器指定树文件夹

    vue 调用pc端本地摄像头.麦克风实现拍照.录视频.录音 并上传 自己写blog只是为了下次方便使用 过程确实很烦 ,自己摸索加各大网站cv查看 可以直接使用 1.调用摄像头拍照 录屏 首先是npm ...

  7. 解决PC浏览器调用摄像头失败(本地可以,线上失败)

    解决PC浏览器调用摄像头失败(本地可以,线上失败) 原因:浏览器为了安全http协议获取不到摄像头权限 解决方案 1.切换https 如果域名可以使用https,切换为https即可 2.修改浏览器设 ...

  8. 手机移动端-纯js浏览器h5调用摄像头扫描识别解析 条形码+二维码

    一.场景 手机移动端-原生js 浏览器h5 解决 识别二维码 条形码功能: 不借助Hbuilder.需要自己打包成APP,比如用Hbuilder打包,浏览器端项目h5 无打包成app部署 X 不采用 ...

  9. 关于Unity调用摄像头扫描二维码与生成二维码的实现方法

    1.常用的生成二维码网址 https://cli.im/ 2.上官网下载二维码插件 http://zxingnet.codeplex.com/ 3.将下载的插件中zxing.unity.dll文件放入 ...

最新文章

  1. Matlab如何读取文本文件
  2. Android中启动Activity(startActivity)流程图分析
  3. Zookeeper详解(一):分布式与Zookeeper
  4. 数据中心继续蓬勃发展的5个原因
  5. 汇编语言:实验7寻址方式在结构化数据访问中的应用
  6. 【假期重磅福利】更新三个Oracle系列课程,共153课时,最低免费获取
  7. Linux从入门到精通——文件传输
  8. 微信公众号开发自动回复的Python库——werobot
  9. 三天掌握三菱FX系列PLC视频教程-IT学院-专题视频课程
  10. 神经网络主要有哪些特点,神经网络模型的优缺点
  11. php图书管理系统需求分析,PHP+MYsql图书管理系统设计
  12. 小瘦牛虚拟无线路由器官方版
  13. html页面通过flv.js实现视频监控直播和点播功能。
  14. xposed绕过模拟器检测_《绝地求生》手游避开模拟器检测攻略分享
  15. SpringCloud调用接口流程
  16. OPCODES学习网址
  17. CustomList
  18. 政策频繁出台,智能网联汽车安全如何“驾驭”?
  19. 2022年还有高职扩招全日制大专
  20. 不使用算术运算符(+/-)怎么求两数之和?

热门文章

  1. ubuntu安装photoshop
  2. 【perl计算基因在基因组上的距离】
  3. 小程序获取微信运动步数
  4. 朋友圈加粗字体数字_微信更新!朋友圈评论能发表情包,结果变成沙雕狂欢
  5. uIP TCP/IP协议栈在51系列单片机上的应用
  6. 工业读写器对接信捷 PLC通信示例
  7. 刨根问底:什么是yum源,yum的工作原理又是什么
  8. Spark性能优化之-数据倾斜
  9. esp32与0.96寸屏幕实现信息传输
  10. JVM、DVM(Dalvik VM)和ART虚拟机的区别