QR code and one-dimensional code recognition Series 1 on iOS

Source: Internet
Author: User
Tags decode all intl

During this time, two-dimensional code and one-dimensional code are recognized on IOS.

I have encountered numerous problems during this period. I would like to summarize them and hope to provide them with reference.

On iOS, the two open-source identification programs zbar and zxing are first searched for information on the Internet for QR code recognition,

On iOS, zbar can recognize one-dimensional code (bar code) and two-dimensional code,

Zxing can only recognize two-dimensional codes, but zxing can recognize one-dimensional codes and two-dimensional codes on Android. However, it does not support one-dimensional code recognition on IOS, this is the official statement of zxing. It is unknown if it is not supported in the future.

Because I need to scan the QR code and QR code at the same time in my project, I chose zbar decisively and started the painful journey.

First, go to the zbar official website to download its instance code and the latest. A library.

Http://zbar.sourceforge.net/iphone/

Compile the code of these instances first and perform real-machine testing. The results are really good. Then introduce it in the code, and the effect is also good.

 

However, when scanning the following QR code, Garbled text occurs.

(Is this graph made of https://chart.googleapis.com/chart? CHS = 150x150 & CHT = In QR & chlorophyll = & Choe = UTF-8)

The result is garbled, and zxing is a normal "medium" word.

Then scan the figure below,

(Is this graph made of https://chart.googleapis.com/chart? In fact, in addition to UTF-8 and shift_jis, there is also a ISO_8859-1,

See figure

The figure comes from the https://chart.googleapis.com/chart? CHS = 150x150 & CHT = QR & chlorophyll = Medium & Choe = ISO-8859-1, but this is not currently discussed in this article.

Scanning this image is a "medium" character, but zxing is garbled. (someone asked me to use zxing. I know zxing is also flawed, however, I have not found a suitable example for the moment. If someone asks me again next time, I will take the above picture back)

 

How can this problem be solved?

Later, I continued to speak on the official zbar Forum, Forum address: http://sourceforge.net/projects/zbar/forums/forum/664596 (here is the help branch of this forum, as well as developer and app branch, it is recommended to go to these places to ask questions, it is easier to get more people's attention)

However, the Forum moderators do not seem to be very concerned about users' questions. I have been tracking this issue for seven days and asked questions continuously in this forum, finally, someone returned to me, and an Indian returned to me (I was not very fond of the Indians before, but after that, I changed my opinion) this may be because of BOM (byteorder mark), and then the addresses of the above two figures are given.

Http://code.google.com/intl/zh-CN/apis/chart/infographics/docs/overview.html

And http://code.google.com/intl/zh-CN/apis/chart/infographics/docs/qr_codes.html

I have a general understanding of this reason. Combined with the reply on the zbar forum, I know that it should be because when zbar is scanning, I don't know whether these charts use UTF-8 or shitf-JIS generation, so it will automatically judge, sometimes can judge the right, sometimes will judge wrong, when an error is identified, we can see garbled characters.

This can also be explained. For garbled characters, if the input is "China" or "country", there will be no garbled characters. At that time, this problem had been entangled for a long time.

There are two solutions: one is to solve the problem from the source, that is, the generated QR code needs to be generated in shift_jis mode, and zbar does not need to be changed and can be directly used.

The other method is that the generated code remains unchanged (this is the case, because you cannot ask the customer to generate according to your format, usually the customer will use the more commonly used UTF-8 to generate ), modify the zbar source code to deal with, forcibly tell zbar, let it use UTF-8 to solve the QR code.

In addition, this problem can also refer to the http://code.google.com/p/zxing/issues/detail? Id = 103 (the reply below seems authoritative and feels like that .)

 

Therefore, we will modify the zbar source code below.

First download the latest source code from http://zbar.sourceforge.net/download.html.

Then I found BOM in code zbar/qrcode/qrdectxt. C and read this. c file. The basic idea should be to use it at the same time.

/* This is the encoding the standard says is thedefault .*/

Latin1_cd = iconv_open ("UTF-8", "ISO8859-1 ");

/* But this one is often used, as well .*/

Sjis_cd = iconv_open ("UTF-8", "sjis ");

/* This is a trivial conversion just to check validitywithout extra code .*/

Utf8_cd = iconv_open ("UTF-8", "UTF-8 ");

 

Next

Enc_list [0] = sjis_cd;

Enc_list [1] = latin1_cd;

Enc_list [2] = utf8_cd;

Next we will decode all the three cases, and finally select a zbar and return it to the caller as appropriate. If zbar is wrong, garbled characters will appear, therefore, you only need to interfere with the selection order.

 

Finally, compile terminal to generate a new libzbar. A and use it directly (another article will show you how to compile in Terminal)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.