java使用電腦攝像頭識(shí)別二維碼
本文實(shí)例為大家分享了java使用電腦攝像頭識(shí)別二維碼的具體代碼,供大家參考,具體內(nèi)容如下
要想攝像頭識(shí)別二維碼,需要兩個(gè)基本功能:
1、從攝像頭獲取圖像,2、根據(jù)圖片解析出二維碼信息。
在上一篇java攝像頭截圖已經(jīng)實(shí)現(xiàn)了攝像頭截圖,只要再加上zxing(或其它能從圖片中解析二維碼的組件),就能從圖像中解析出二維碼,實(shí)現(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("攝像頭截圖應(yīng)用");
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); //彈出攝像頭設(shè)備選擇
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);
}
}
最后來張效果圖(本圖僅供參考)

要想識(shí)別效果好點(diǎn),攝像頭像素最好500W以上,活動(dòng)二維碼簽到、物品掃描,只需扛臺(tái)手提,再加個(gè)高清攝像頭就行了。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java使用opencv識(shí)別二維碼的完整步驟
- Java創(chuàng)建、識(shí)別條形碼和二維碼方法示例
- 不到十行實(shí)現(xiàn)javaCV圖片OCR文字識(shí)別
- Windows下Java調(diào)用OCR進(jìn)行圖片識(shí)別
- java實(shí)現(xiàn)騰訊ocr圖片識(shí)別接口調(diào)用
- java圖片識(shí)別文字的方法
- java實(shí)現(xiàn)圖片文字識(shí)別ocr
- java指紋識(shí)別以及谷歌圖片識(shí)別技術(shù)源碼
- Java基于直方圖應(yīng)用的相似圖片識(shí)別實(shí)例
- java實(shí)現(xiàn)識(shí)別二維碼圖片功能
相關(guān)文章
springboot3請(qǐng)求參數(shù)種類及接口測(cè)試案例小結(jié)
這篇文章主要介紹了springboot3請(qǐng)求參數(shù)種類及接口測(cè)試案例小結(jié),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-10-10
Idea中maven項(xiàng)目實(shí)現(xiàn)登錄驗(yàn)證碼功能
這篇文章主要介紹了Idea中maven項(xiàng)目實(shí)現(xiàn)登錄驗(yàn)證碼功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
詳解Spring Cloud中Hystrix 線程隔離導(dǎo)致ThreadLocal數(shù)據(jù)丟失
這篇文章主要介紹了詳解Spring Cloud中Hystrix 線程隔離導(dǎo)致ThreadLocal數(shù)據(jù)丟失,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
學(xué)習(xí)Java的static與final關(guān)鍵字
本篇文章給大家詳細(xì)分析了Java的static與final關(guān)鍵字知識(shí)點(diǎn)以及相關(guān)代碼分享,有需要的讀者跟著學(xué)習(xí)下吧。2018-03-03
Spring?Bean注冊(cè)與注入實(shí)現(xiàn)方法詳解
首先,要學(xué)習(xí)Spring中的Bean的注入方式,就要先了解什么是依賴注入。依賴注入是指:讓調(diào)用類對(duì)某一接口的實(shí)現(xiàn)類的實(shí)現(xiàn)類的依賴關(guān)系由第三方注入,以此來消除調(diào)用類對(duì)某一接口實(shí)現(xiàn)類的依賴。Spring容器中支持的依賴注入方式主要有屬性注入、構(gòu)造函數(shù)注入、工廠方法注入2022-10-10
SpringBoot2.4.2下使用Redis配置Lettuce的示例
這篇文章主要介紹了SpringBoot2.4.2下使用Redis配置Lettuce,Springboot2.4.2下默認(rèn)使用的就是Lettuce而不是Jedis因此無需在依賴進(jìn)行排除Jedis,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2022-01-01
java定時(shí)任務(wù)實(shí)現(xiàn)的4種方式小結(jié)
這篇文章主要介紹了java定時(shí)任務(wù)實(shí)現(xiàn)的4種方式小結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09
idea插件之mybatis log plugin控制臺(tái)sql的問題
這篇文章主要介紹了idea插件之mybatis log plugin控制臺(tái)sql,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09

