VUE实现扫描二维码以及二维码生成

1、vue-qrcode-reader扫描二维码

调用手机摄像头需要https环境,因为HTTP协议不支持传输多媒体数据。

https环境可使用组件

vue2 扫码 vue-qrcode-reader - 简书

https://www.cnblogs.com/cxx9759/p/17021456.html2

https环境使用jsqr获取屏幕流转到video获取帧解析

使用jsQR识别二维码-CSDN博客

-------------------------------------------------------------------------------------

http环境可使用jsQr

拍一张照片在使用jsqr解析。

https://www.cnblogs.com/sunshine233/p/15740624.html

2、qrcode.vue二维码的生成

qrcode.vue插件使用方法-CSDN博客b

补充

使用jsQr时,一定记得给画布长宽赋值,避免错误。

以上都是在前端实现,Java后端二维码识别使用Google的ZXing,因为ZXing库主要专注于标准二维码的解码和生成,拍摄图片带有其他图案识别失败所以图像需要处理(图像二值化处理)。

java实现识别二维码图片功能;作者:weijx_;来源:脚本之家_站圈网

 图像二值化处理Util

  public static BufferedImage binarization(BufferedImage bi ) throws IOException {
//图像格式转换
            //String base64Data =param.getQrCodeImgbase64()
.substring(param.getQrCodeImgbase64().indexOf(",") + 1);
         // byte[] imageBytes = Base64.decodeBase64(base64Data);
         // ByteArrayInputStream bis = new ByteArrayInputStream(imageBytes);
        //  BufferedImage imagetest = ImageIO.read(bis);
//        File file = new File(filePath);
//        BufferedImage bi = ImageIO.read(file);
        // 获取当前图片的高,宽,ARGB
        int h = bi.getHeight();
        int w = bi.getWidth();
        int arr[][] = new int[w][h];

        // 获取图片每一像素点的灰度值
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                // getRGB()返回默认的RGB颜色模型(十进制)
                arr[i][j] = getImageGray(bi.getRGB(i, j));// 该点的灰度值
            }
        }

        // 构造一个类型为预定义图像类型,BufferedImage
        BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY);

        // 和预先设置的阈值大小进行比较,大的就显示为255即白色,小的就显示为0即黑色
        for (int i = 0; i < w; i++) {
            for (int j = 0; j < h; j++) {
                if (getGray(arr, i, j, w, h) > YZ) {
                    int white = new Color(255, 255, 255).getRGB();
                    bufferedImage.setRGB(i, j, white);
                } else {
                    int black = new Color(0, 0, 0).getRGB();
                    bufferedImage.setRGB(i, j, black);
                }
            }

        }
        return bufferedImage;
//        ImageIO.write(bufferedImage, "jpg", new File(fileOutputPath));
    }

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值