2015-09-10 32 views
2

我試圖用zxing解碼器的C++端口來解碼這個qr碼。原圖:imageZxing在QRCode中的漢字字符

經過一些預處理我準備了一個清晰的圖像:

qr code after preprocessing

現在我收到錯誤的文本解碼這個代碼後:

rbNJ‰˚Fhttp://www.biccamera.com/

以字節爲單位:

83 72 83 62 83 4e 83 4a 83 81 83 89 81 46 0d 0a 68 74 74 70 3a 2f 2f 77 77 77 2e 62 69 63 63 61 6d 65 72 61 2e 63 6f 6d 2f 00 

閱讀上面的代碼線槽網站the online barcode reader後我接收文本:

ビックカメラ: http://www.biccamera.com/

在字節:

e3 83 93 e3 83 83 e3 82 af e3 82 ab e3 83 a1 e3 83 a9 ef bc 9a 0a 68 74 74 70 3a 2f 2f 77 77 77 2e 62 69 63 63 61 6d 65 72 61 2e 63 6f 6d 2f 0a 

的第一部分消息是不同的(我檢查和zxing libr在第一部分中使用漢字解碼)。

如何將此qrcode正確解碼爲utf8並將結果存儲在std::wstring

我當前的代碼:

#include <locale> 
#include <codecvt> 
#include <string> 

zxing::qrcode::Decoder decoder; 
zxing::Ref<zxing::DecoderResult> result = decoder.decode(zxing::Ref<zxing::BitMatrix>(bitmatrix)); 
zxing::Ref<zxing::String> ZXstring = result->getText(); 
std::string STDstring = ZXstring->getText(); 

std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter; 
std::wstring wide = converter.from_bytes(STDstring); //bad conversion exception 

回答

0

這個問題的解決方法非常簡單:

要閱讀上面的代碼,你需要編譯其他庫斑馬線:libiconv。 之後,這個二維碼將被正確解碼。

如果您使用的是Windows和Visual Studio,本文關於建立libiconv的可能會有所幫助:How to Build libiconv with Microsoft Visual Studio

在源代碼請檢查IFDEF:NO_ICONV甚至更​​好的使用CMake的啓用該庫。