gpt4 book ai didi

c++ - QRCode中的Zxing汉字字符

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:49:05 24 4
gpt4 key购买 nike

我正在尝试使用 zxing 解码器的 C++ 端口解码此二维码。原图:image

经过一些预处理后,我准备了一张清晰的图像:

qr code after preprocessing

解码此代码后,我收到了错误的文本:

rbNJ‰F http://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 库在第一部分使用 Kanji 解码)。

如何正确解码此二维码为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

最佳答案

这个问题的解决方案非常简单:

要阅读上面的代码,您需要使用额外的库编译 zxing:libiconv。之后这个二维码就可以正常解码了。

如果您使用 Windows 和 Visual Studio,这篇关于构建 libiconv 的文章可能会有所帮助:How to Build libiconv with Microsoft Visual Studio

在源代码中,请检查 ifdef: NO_ICONV 或使用 CMake 更好地启用此库。

关于c++ - QRCode中的Zxing汉字字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32499057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com