<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 59, comments - 244, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

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

    Posted on 2012-09-10 23:50 penngo 閱讀(6499) 評論(2)  編輯  收藏 所屬分類: 練手作品
    要想攝像頭識別二維碼,需要兩個基本功能:1、從攝像頭獲取圖像,2、根據圖片解析出二維碼信息。在上一篇java攝像頭截圖已經實現了攝像頭截圖,只要再加上zxing(或其它能從圖片中解析二維碼的組件),就能從圖像中解析出二維碼,實現代碼如下:

     1 package com.pengo.capture;
     2 
     3 import javax.swing.JFrame;
     4 import java.awt.BorderLayout;
     5 import java.awt.Dimension;
     6 import java.awt.Graphics2D;
     7 import java.awt.image.BufferedImage;
     8 import java.io.InputStream;
     9 import javax.media.MediaLocator;
    10 import javax.swing.JPanel;
    11 import javazoom.jl.player.Player;
    12 import com.google.zxing.BinaryBitmap;
    13 import com.google.zxing.LuminanceSource;
    14 import com.google.zxing.MultiFormatReader;
    15 import com.google.zxing.Result;
    16 import com.google.zxing.common.HybridBinarizer;
    17 
    18 import net.sf.fmj.ui.application.CaptureDeviceBrowser;
    19 import net.sf.fmj.ui.application.ContainerPlayer;
    20 import net.sf.fmj.ui.application.PlayerPanelPrefs;
    21 public class CameraFrame2 extends JFrame{
    22     private static int num = 0;
    23     public CameraFrame2() throws Exception{
    24         this.setTitle("攝像頭截圖應用");
    25         this.setSize(480, 500);
    26         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    27         final JPanel cameraPanel = new JPanel();
    28         this.getContentPane().setLayout(new BorderLayout());
    29         this.getContentPane().add(cameraPanel, BorderLayout.CENTER);
    30         ContainerPlayer containerPlayer = new ContainerPlayer(cameraPanel);
    31         MediaLocator locator = CaptureDeviceBrowser.run(null);   //彈出攝像頭設備選擇
    32 
    33         PlayerPanelPrefs prefs = new PlayerPanelPrefs();
    34         containerPlayer.setMediaLocation(locator.toExternalForm(), prefs.autoPlay);
    35         
    36         new Thread() {
    37             public void run() {
    38                 while (true) {
    39                     try {
    40                         Thread.sleep(1000);
    41                         Dimension imageSize = cameraPanel.getSize();
    42                         BufferedImage image = new BufferedImage(
    43                                 imageSize.width, imageSize.height,
    44                                 BufferedImage.TYPE_INT_ARGB);
    45                         Graphics2D g = image.createGraphics();
    46                         cameraPanel.paint(g);
    47                         g.dispose();
    48                         LuminanceSource source = new BufferedImageLuminanceSource(
    49                                 image);
    50                         BinaryBitmap bitmap = new BinaryBitmap(
    51                                 new HybridBinarizer(source));
    52                         Result result;
    53                         result = new MultiFormatReader().decode(bitmap);
    54                         System.out.println("二維碼====:" + result.getText());
    55                         InputStream is = CameraFrame.class.getClassLoader().getResourceAsStream("resource/beep.mp3");
    56                         Player player = new Player(is);
    57                         player.play();
    58                     } catch (Exception re) {
    59                         re.printStackTrace();
    60                     }
    61                 }
    62             }
    63         }.start();
    64     }
    65     
    66     public static void main(String[] args) throws Exception{
    67         CameraFrame2 camera = new CameraFrame2();
    68         camera.setVisible(true);
    69     }
    70 }

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


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

    評論

    # re: 使用電腦攝像頭識別二維碼  回復  更多評論   

    2012-09-11 11:22 by greatghoul
    好棒的代碼。

    # re: 使用電腦攝像頭識別二維碼  回復  更多評論   

    2012-09-27 17:04 by kelven
    好代碼!

    修改第53行解決中文亂碼問題:

    Hashtable hints = new Hashtable();
    hints.put(DecodeHintType.CHARACTER_SET, "GBK");
    result = new MultiFormatReader().decode(bitmap, hints);
    主站蜘蛛池模板: 中文字幕亚洲精品资源网| 亚洲人成无码网站久久99热国产| 亚洲av无码一区二区三区乱子伦| 国产精品免费αv视频| 国产福利电影一区二区三区,亚洲国模精品一区 | 亚洲精品mv在线观看 | 最近中文字幕电影大全免费版| 亚洲伦理一区二区| 97精品免费视频| 亚洲视频国产精品| 最近免费中文字幕大全| 亚洲熟妇成人精品一区| xvideos亚洲永久网址| 夜夜爽妓女8888视频免费观看 | 久久亚洲伊人中字综合精品| 日本免费人成网ww555在线| 亚洲国产精品嫩草影院在线观看 | 成年人视频在线观看免费| 精品韩国亚洲av无码不卡区| 亚洲AV无码乱码在线观看性色扶| 一本久久免费视频| 亚洲AV无码久久精品成人| 免费观看无遮挡www的视频| 亚洲精品乱码久久久久久蜜桃图片| 国产在线a不卡免费视频| A级毛片成人网站免费看| 亚洲视频免费在线观看| 日韩免费a级毛片无码a∨| 毛片亚洲AV无码精品国产午夜| 亚洲精品国自产拍在线观看| 九九美女网站免费| 亚洲熟妇成人精品一区| 国产亚洲精品自在线观看| 桃子视频在线观看高清免费完整| 亚洲AV无码一区二区一二区| 国产亚洲精品影视在线产品| 1000部啪啪未满十八勿入免费| 麻豆亚洲AV成人无码久久精品| 亚洲高清专区日韩精品| 最近高清国语中文在线观看免费| 一级毛片免费视频网站|