java使用电脑摄像头识别二维码

网友投稿 334 2023-01-21


java使用电脑摄像头识别二维码

本文实例为大家分享了java使用电脑摄像头识别二维码的具体代码,供大家参考,具体内容如下

要想摄像头识别二维码,需要两个基本功能:

1、从摄像头获取图像,2、根据图片解析出二维码信息。

在上一篇java摄像头截图已经实现了摄像头截图,只要再加上zxing(或其它能从图片中解析二维码的组件),就能从图像中解析出二维码,实现代hfdVpp码如下:

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 (trhttp://ue) {

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("rehttp://source/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以上,活动二维码签到、物品扫描,只需扛台手提,再加个高清摄像头就行了。


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:服装研发管理平台网址(服装网站开发)
下一篇:详细讲述Java中的对象转型
相关文章

 发表评论

暂时没有评论,来抢沙发吧~