2013-12-13 95 views
0

我有一個代碼來解碼圖像文件並解碼它的qrcode。我正在使用zxing庫。但我怎麼能讓這個從網絡攝像頭捕捉qrcode並解碼它。我需要做什麼改變?任何一個人都可以一步一步解釋這一點。如何使用zxing通過網絡攝像頭解碼qrcode

這裏是代碼:

public class QrCodeDecoder 
{ 
    public String decode(File imageFile) 
    { 
     BufferedImage image; 
     try 
     { 
      image = ImageIO.read(imageFile); 
     } 
     catch (IOException e1) 
     { 
     return "io outch"; 
     } 

     // creating luminance source 
     LuminanceSource lumSource = new BufferedImageLuminanceSource(image); 
     BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource)); 

     // barcode decoding 
     QRCodeReader reader = new QRCodeReader(); 
     Result result = null; 
     try { 
      result = reader.decode(bitmap); 
     } 
     catch (ReaderException e) 
     { 
     return "reader error"; 
     } 

     return result.getText(); 

     } 

} 

回答

0

你很遠,從一個解決方案,我不認爲任何人都可以解釋爲「分步實施」。您首先需要找到能夠從網絡攝像頭抓取圖像的庫。您可以從this library開始,但我確定有其他人。

一旦你可以捕捉圖像,開始找出它是否在上述代碼預期的格式。如果你幸運的話,那將是,如果沒有,你將不得不在兩種格式之間進行轉換。