329
|
1 |
<stránka
|
|
2 |
xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
|
|
3 |
xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
|
|
4 |
|
|
5 |
<nadpis>Reading barcodes and QR</nadpis>
|
|
6 |
<perex>recognize barcodes (including QR) in image files or streams</perex>
|
|
7 |
<m:pořadí-příkladu>05400</m:pořadí-příkladu>
|
|
8 |
|
|
9 |
<text xmlns="http://www.w3.org/1999/xhtml">
|
|
10 |
|
|
11 |
<p>
|
|
12 |
Either ubiquitous 1D barcodes (procudct labels, ISBN in form of EAN-13 etc.) or 2D barcodes (QR containing hyperlinks, vCards etc.)
|
|
13 |
encode numbers, texts or other data into images that can be printed and scanned or photographed later.
|
|
14 |
Since <m:a href="release-v0.18">v0.18</m:a>, <m:name/> can interact with this technology.
|
|
15 |
</p>
|
|
16 |
|
|
17 |
<p>
|
|
18 |
The <code>relpipe-in-barcode</code> tool reads image data from the standard input, so we can feed a file containing a barcode into it or we can generate one on-the-fly.
|
|
19 |
We can also use <code>tee</code> command to store generated image data in a file.
|
|
20 |
</p>
|
|
21 |
<m:pre jazyk="shell"><![CDATA[echo -n "Big Fun" | qrencode -o - | tee qr.png | relpipe-in-barcode | relpipe-out-tabular]]></m:pre>
|
|
22 |
|
|
23 |
<p>This pipeline generates this relation:</p>
|
|
24 |
<m:pre jazyk="text"><![CDATA[symbol:
|
|
25 |
╭──────────────┬───────────────┬────────────────┬─────────────┬─────────────┬─────────────────┬──────────────────╮
|
|
26 |
│ id (integer) │ type (string) │ value (string) │ x (integer) │ y (integer) │ width (integer) │ height (integer) │
|
|
27 |
├──────────────┼───────────────┼────────────────┼─────────────┼─────────────┼─────────────────┼──────────────────┤
|
|
28 |
│ 0 │ QR-Code │ Big Fun │ 12 │ 12 │ 63 │ 63 │
|
|
29 |
╰──────────────┴───────────────┴────────────────┴─────────────┴─────────────┴─────────────────┴──────────────────╯
|
|
30 |
Record count: 1]]></m:pre>
|
|
31 |
|
|
32 |
<p>
|
|
33 |
There might be multiple barcodes (symbols) in the image file and we obtain also their sizes and positions.
|
|
34 |
We may read a <a href="img/barcode-qr-IMG_5758.jpeg">photo</a>:
|
|
35 |
</p>
|
|
36 |
|
|
37 |
<m:pre jazyk="shell"><![CDATA[cat barcode-qr-IMG_5758.jpeg | relpipe-in-barcode | relpipe-out-tabular]]></m:pre>
|
|
38 |
|
|
39 |
<p>and get plenty of symbols:</p>
|
|
40 |
<m:pre jazyk="text" src="examples/barcode-qr-IMG_5758.txt"/>
|
|
41 |
|
|
42 |
<p>
|
|
43 |
There is also (a bit experimental) example of barcode <m:a href="release-v0.15">streamlet</m:a> that is called from <code>relpipe-in-filesystem</code>
|
|
44 |
and works with several files at once (can even run in parallel, like any other streamlet):
|
|
45 |
</p>
|
|
46 |
<m:pre jazyk="shell"><![CDATA[find -print0 | relpipe-in-filesystem --parallel 8 --file name --streamlet barcode-reader | …]]></m:pre>
|
|
47 |
|
|
48 |
|
|
49 |
<p>
|
|
50 |
When we are generating QR codes and use Unicode characters (e.g. the <code>→</code> arrow):
|
|
51 |
</p>
|
|
52 |
<m:pre jazyk="shell"><![CDATA[echo -n "extreme→impression" | qrencode -o - | relpipe-in-barcode | relpipe-out-csv]]></m:pre>
|
|
53 |
|
|
54 |
<p>we may get unexpected result:</p>
|
|
55 |
<m:pre jazyk="text"><![CDATA["id","type","value","x","y","width","height"
|
|
56 |
"0","QR-Code","extreme竊段mpression","12","12","74","74"]]></m:pre>
|
|
57 |
|
|
58 |
|
|
59 |
<p>
|
|
60 |
QR codes use the ISO 8859-1 encoding as default and readers usually do some heuristics to guess actual encoding.
|
|
61 |
Sometimes it works, sometimes not.
|
|
62 |
In this particular case, the reader accidentally thought that the encoding was SJIS.
|
|
63 |
So we can <i>fix</i> it by adding <code>| iconv -t SJIS</code> at the end of the pipeline.
|
|
64 |
</p>
|
|
65 |
|
|
66 |
<p>
|
|
67 |
But this is just a workaround.
|
|
68 |
We rather want to add UTF-8 BOM or ECI (Extended Channel Interpretations) to make the reader use the same encoding as we did (UTF-8):
|
|
69 |
</p>
|
|
70 |
|
|
71 |
<m:pre jazyk="shell"><![CDATA[echo -ne "\xEF\xBB\xBFextreme→impression" | qrencode -o - | relpipe-in-barcode | relpipe-out-csv]]></m:pre>
|
|
72 |
|
|
73 |
<p>and get desired result:</p>
|
|
74 |
<m:pre jazyk="text"><![CDATA["id","type","value","x","y","width","height"
|
|
75 |
"0","QR-Code","extreme→impression","12","12","74","74"]]></m:pre>
|
|
76 |
|
|
77 |
<p>
|
|
78 |
Because the <code>relpipe-in-barcode</code> tool and the <code>barcode-reader</code> streamlet produce data in machine readable form,
|
|
79 |
we can use them not only for manual ah-hoc reading but also in scripts or batch processing –
|
|
80 |
e.g. extract payment information from invoices or contact information from scanned business cards, catalogize books or read package labels.
|
|
81 |
</p>
|
|
82 |
|
|
83 |
|
|
84 |
</text>
|
|
85 |
|
|
86 |
</stránka>
|