欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java使用電腦攝像頭識別二維碼

 更新時間:2018年10月16日 10:54:20   作者:a19880813  
這篇文章主要為大家詳細介紹了java使用電腦攝像頭識別二維碼,從攝像頭獲取圖像,再根據(jù)圖片解析出二維碼信息,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java使用電腦攝像頭識別二維碼的具體代碼,供大家參考,具體內容如下

要想攝像頭識別二維碼,需要兩個基本功能:

1、從攝像頭獲取圖像,2、根據(jù)圖片解析出二維碼信息。

在上一篇java攝像頭截圖已經(jīng)實現(xiàn)了攝像頭截圖,只要再加上zxing(或其它能從圖片中解析二維碼的組件),就能從圖像中解析出二維碼,實現(xiàn)代碼如下:

package com.pengo.capture;

import javax.swing.JFrame;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import javax.media.MediaLocator;
import javax.swing.JPanel;
import javazoom.jl.player.Player;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.common.HybridBinarizer;
 
import net.sf.fmj.ui.application.CaptureDeviceBrowser;
import net.sf.fmj.ui.application.ContainerPlayer;
import net.sf.fmj.ui.application.PlayerPanelPrefs;
public class CameraFrame2 extends JFrame{
  private static int num = 0;
  public CameraFrame2() throws Exception{
   this.setTitle("攝像頭截圖應用");
   this.setSize(480, 500);
   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   final JPanel cameraPanel = new JPanel();
   this.getContentPane().setLayout(new BorderLayout());
   this.getContentPane().add(cameraPanel, BorderLayout.CENTER);
   ContainerPlayer containerPlayer = new ContainerPlayer(cameraPanel);
   MediaLocator locator = CaptureDeviceBrowser.run(null); //彈出攝像頭設備選擇
 
   PlayerPanelPrefs prefs = new PlayerPanelPrefs();
   containerPlayer.setMediaLocation(locator.toExternalForm(), prefs.autoPlay);
   
   new Thread() {
    public void run() {
     while (true) {
      try {
      Thread.sleep(1000);
       Dimension imageSize = cameraPanel.getSize();
       BufferedImage image = new BufferedImage(
         imageSize.width, imageSize.height,
         BufferedImage.TYPE_INT_ARGB);
       Graphics2D g = image.createGraphics();
       cameraPanel.paint(g);
       g.dispose();
       LuminanceSource source = new BufferedImageLuminanceSource(
         image);
       BinaryBitmap bitmap = new BinaryBitmap(
        new HybridBinarizer(source));
       Result result;
       result = new MultiFormatReader().decode(bitmap);
       System.out.println("二維碼====:" + result.getText());
       InputStream is = CameraFrame.class.getClassLoader().getResourceAsStream("resource/beep.mp3");
       Player player = new Player(is);
       player.play();
      } catch (Exception re) {
       re.printStackTrace();
      }
     }
    }
   }.start();
  }
  
  public static void main(String[] args) throws Exception{
   CameraFrame2 camera = new CameraFrame2();
   camera.setVisible(true);
  }
 }

最后來張效果圖(本圖僅供參考)


要想識別效果好點,攝像頭像素最好500W以上,活動二維碼簽到、物品掃描,只需扛臺手提,再加個高清攝像頭就行了。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 淺談Java double 相乘的結果偏差小問題

    淺談Java double 相乘的結果偏差小問題

    下面小編就為大家?guī)硪黄獪\談Java double 相乘的結果偏差小問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-01-01
  • springboot3請求參數(shù)種類及接口測試案例小結

    springboot3請求參數(shù)種類及接口測試案例小結

    這篇文章主要介紹了springboot3請求參數(shù)種類及接口測試案例小結,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-10-10
  • Idea中maven項目實現(xiàn)登錄驗證碼功能

    Idea中maven項目實現(xiàn)登錄驗證碼功能

    這篇文章主要介紹了Idea中maven項目實現(xiàn)登錄驗證碼功能,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • 詳解Spring Cloud中Hystrix 線程隔離導致ThreadLocal數(shù)據(jù)丟失

    詳解Spring Cloud中Hystrix 線程隔離導致ThreadLocal數(shù)據(jù)丟失

    這篇文章主要介紹了詳解Spring Cloud中Hystrix 線程隔離導致ThreadLocal數(shù)據(jù)丟失,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 學習Java的static與final關鍵字

    學習Java的static與final關鍵字

    本篇文章給大家詳細分析了Java的static與final關鍵字知識點以及相關代碼分享,有需要的讀者跟著學習下吧。
    2018-03-03
  • Spring?Bean注冊與注入實現(xiàn)方法詳解

    Spring?Bean注冊與注入實現(xiàn)方法詳解

    首先,要學習Spring中的Bean的注入方式,就要先了解什么是依賴注入。依賴注入是指:讓調用類對某一接口的實現(xiàn)類的實現(xiàn)類的依賴關系由第三方注入,以此來消除調用類對某一接口實現(xiàn)類的依賴。Spring容器中支持的依賴注入方式主要有屬性注入、構造函數(shù)注入、工廠方法注入
    2022-10-10
  • SpringBoot2.4.2下使用Redis配置Lettuce的示例

    SpringBoot2.4.2下使用Redis配置Lettuce的示例

    這篇文章主要介紹了SpringBoot2.4.2下使用Redis配置Lettuce,Springboot2.4.2下默認使用的就是Lettuce而不是Jedis因此無需在依賴進行排除Jedis,本文給大家介紹的非常詳細,感興趣的朋友跟隨小編一起看看吧
    2022-01-01
  • java定時任務實現(xiàn)的4種方式小結

    java定時任務實現(xiàn)的4種方式小結

    這篇文章主要介紹了java定時任務實現(xiàn)的4種方式小結,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • idea插件之mybatis log plugin控制臺sql的問題

    idea插件之mybatis log plugin控制臺sql的問題

    這篇文章主要介紹了idea插件之mybatis log plugin控制臺sql,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-09-09
  • java遞歸算法的實例詳解

    java遞歸算法的實例詳解

    在本篇文章里小編給大家整理了關于java遞歸算法的實例內容,以及相關知識點總結,需要的朋友們可以學習下。
    2020-02-02

最新評論