Search code examples
c++qr-codezxing

Zxing Kanji characters in QRCode


I'm trying to decode this qr code using c++ port of zxing decoder. Original image: image

After some preprocessing I prepared a clear image:

qr code after preprocessing

Now after decoding this code I'm receiving wrong text:

rbNJ‰F http://www.biccamera.com/

in bytes:

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

After reading the code above trough the website the online barcode reader I receive text:

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

in bytes:

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

The first part of the message is diffrent (I checked and the zxing library use Kanji decoding in the first part).

How to properly decode this qrcode to utf8 and store the result in std::wstring ?

My current code:

#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

Solution

  • The solution for this problem is really simple:

    To read the code above you need to compile zxing with an additional library: libiconv. After that this qr code will be decoded properly.

    If you use Windows and Visual studio, this article about building libiconv might be helpful: How to Build libiconv with Microsoft Visual Studio

    In source code please check the ifdef: NO_ICONV or even better enable this library using CMake.