Skip to content

Commit a3142bc

Browse files
committed
Initial commit: version 1.0.
0 parents  commit a3142bc

26 files changed

+5265
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.o
2+
*.lo
3+
quirc-demo
4+
quirc-scanner
5+
qrtest
6+
inspect
7+
libquirc.a
8+
libquirc.so
9+
.*.swp
10+
*~

LICENSE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
quirc -- QR-code recognition library
2+
Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
3+
4+
Permission to use, copy, modify, and/or distribute this software for
5+
any purpose with or without fee is hereby granted, provided that the
6+
above copyright notice and this permission notice appear in all
7+
copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12+
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13+
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14+
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16+
PERFORMANCE OF THIS SOFTWARE.

Makefile

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# quirc -- QR-code recognition library
2+
# Copyright (C) 2010-2012 Daniel Beer <dlbeer@gmail.com>
3+
#
4+
# Permission to use, copy, modify, and/or distribute this software for any
5+
# purpose with or without fee is hereby granted, provided that the above
6+
# copyright notice and this permission notice appear in all copies.
7+
#
8+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
16+
CC ?= gcc
17+
PREFIX ?= /usr/local
18+
SDL_CFLAGS := $(shell pkg-config --cflags sdl)
19+
SDL_LIBS := $(shell pkg-config --libs sdl)
20+
21+
LIB_VERSION = 1.0
22+
LIB_SONAME = libquirc.so.1
23+
24+
QUIRC_CFLAGS = -O3 -Wall -Ilib $(CFLAGS) $(SDL_CFLAGS)
25+
LIB_OBJ = \
26+
lib/decode.o \
27+
lib/identify.o \
28+
lib/quirc.o \
29+
lib/version_db.o
30+
LIB_SOBJ = $(subst .o,.lo,$(LIB_OBJ))
31+
DEMO_OBJ = \
32+
demo/camera.o \
33+
demo/mjpeg.o \
34+
demo/convert.o \
35+
demo/dthash.o \
36+
demo/demoutil.o
37+
38+
all: libquirc.so qrtest inspect quirc-demo quirc-scanner
39+
40+
qrtest: tests/dbgutil.o tests/qrtest.o libquirc.a
41+
$(CC) -o $@ $^ -lm -ljpeg
42+
43+
inspect: tests/dbgutil.o tests/inspect.o libquirc.a
44+
$(CC) -o $@ $^ -lm -ljpeg $(SDL_LIBS) -lSDL_gfx
45+
46+
quirc-demo: $(DEMO_OBJ) demo/demo.o libquirc.a
47+
$(CC) -o $@ $^ -lm -ljpeg $(SDL_LIBS) -lSDL_gfx
48+
49+
quirc-scanner: $(DEMO_OBJ) demo/scanner.o libquirc.a
50+
$(CC) -o $@ $^ -lm -ljpeg
51+
52+
libquirc.a: $(LIB_OBJ)
53+
rm -f $@
54+
ar cru $@ $^
55+
ranlib $@
56+
57+
libquirc.so: $(LIB_SOBJ)
58+
$(CC) -shared -Wl,-soname=$(LIB_SONAME) -o $@ $^ -lm
59+
60+
%.o: %.c
61+
$(CC) $(QUIRC_CFLAGS) -o $*.o -c $*.c
62+
63+
%.lo: %.c
64+
$(CC) -fPIC $(QUIRC_CFLAGS) -o $*.lo -c $*.c
65+
66+
install: libquirc.a libquirc.so quirc-demo quirc-scanner
67+
install -o root -g root -m 0644 lib/quirc.h $(DESTDIR)$(PREFIX)/include
68+
install -o root -g root -m 0644 libquirc.a $(DESTDIR)$(PREFIX)/lib
69+
install -o root -g root -m 0755 libquirc.so \
70+
$(DESTDIR)$(PREFIX)/lib/libquirc.so.$(LIB_VERSION)
71+
ln -sf libquirc.so.$(LIB_VERSION) $(DESTDIR)$(PREFIX)/lib/$(LIB_SONAME)
72+
ln -sf libquirc.so.$(LIB_VERSION) $(DESTDIR)$(PREFIX)/lib/libquirc.so
73+
install -o root -g root -m 0755 quirc-demo $(DESTDIR)$(PREFIX)/bin
74+
install -o root -g root -m 0755 quirc-scanner $(DESTDIR)$(PREFIX)/bin
75+
76+
uninstall:
77+
rm -f $(DESTDIR)$(PREFIX)/include/quirc.h
78+
rm -f $(DESTDIR)$(PREFIX)/lib/libquirc.so.$(LIB_VERSION)
79+
rm -f $(DESTDIR)$(PREFIX)/lib/$(LIB_SONAME)
80+
rm -f $(DESTDIR)$(PREFIX)/lib/libquirc.so
81+
rm -f $(DESTDIR)$(PREFIX)/lib/libquirc.a
82+
rm -f $(DESTDIR)$(PREFIX)/bin/quirc-demo
83+
rm -f $(DESTDIR)$(PREFIX)/bin/quirc-scanner
84+
85+
clean:
86+
rm -f */*.o
87+
rm -f */*.lo
88+
rm -f libquirc.a
89+
rm -f libquirc.so
90+
rm -f qrtest
91+
rm -f inspect
92+
rm -f quirc-demo
93+
rm -f quirc-scanner

README

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
Quirc
2+
=====
3+
4+
QR codes are a type of high-density matrix barcodes, and quirc is a
5+
library for extracting and decoding them from images. It has several
6+
features which make it a good choice for this purpose:
7+
8+
* It is fast enough to be used with realtime video: extracting and
9+
decoding from VGA frame takes about 50 ms on a modern x86 core.
10+
11+
* It has a robust and tolerant recognition algorithm. It can
12+
correctly recognise and decode QR codes which are rotated and/or
13+
oblique to the camera. It can also distinguish and decode multiple
14+
codes within the same image.
15+
16+
* It is easy to use, with a simple API described in a single
17+
commented header file (see below for an overview).
18+
19+
* It is small and easily embeddable, with no dependencies other than
20+
standard C functions.
21+
22+
* It has a very small memory footprint: one byte per image pixel,
23+
plus a few kB per decoder object.
24+
25+
* It uses no global mutable state, and is safe to use in a
26+
multithreaded application.
27+
28+
* BSD-licensed, with almost no restrictions regarding use and/or
29+
modification.
30+
31+
The distribution comes with, in addition to the library, several test
32+
programs. While the core library is very portable, these programs have
33+
some additional dependencies. All of them require libjpeg, and two
34+
(``quirc-demo`` and ``inspect``) require SDL. The camera demos use
35+
Linux-specific APIs:
36+
37+
``quirc-demo``
38+
39+
~ This is an real-time demo which requires a camera and a graphical
40+
display. The video stream is displayed on screen as it's received,
41+
and any QR codes recognised are highlighted in the image, with the
42+
decoded information both displayed on the image and printed on
43+
stdout.
44+
45+
``quirc-scanner``
46+
47+
~ This program turns your camera into a barcode scanner. It's almost
48+
the same as the ``demo`` application, but it doesn't display the
49+
video stream, and thus doesn't require a graphical display.
50+
51+
``qrtest``
52+
53+
~ This test is used to evaluate the performance of library. Given a
54+
directory tree containing a bunch of JPEG images, it will attempt
55+
to locate and decode QR codes in each image. Speed and success
56+
statistics are collected and printed on stdout.
57+
58+
``inspect``
59+
60+
~ This test is used for debugging. Given a single JPEG image, it
61+
will display a diagram showing the internal state of the decoder
62+
as well as printing additional information on stdout.
63+
64+
Installation
65+
------------
66+
67+
To build the library and associated demos/tests, type ``make``. Type
68+
``make install`` to install the library, header file and camera demos.
69+
70+
You can specify one or several of the following targets if you don't
71+
want, or are unable to build everything:
72+
73+
* libquirc.a
74+
* libquirc.so
75+
* qrtest
76+
* inspect
77+
* quirc-scanner
78+
* quirc-demo
79+
80+
Library use
81+
-----------
82+
83+
All of the library's functionality is exposed through a single header
84+
file, which you should include:
85+
86+
#include <quirc.h>
87+
88+
To decode images, you'll need to instantiate a ``struct quirc``
89+
object, which is done with the ``quirc_new`` function. Later, when you
90+
no longer need to decode anything, you should release the allocated
91+
memory with ``quirc_destroy``:
92+
93+
struct quirc *qr;
94+
95+
qr = quirc_new();
96+
if (!qr) {
97+
perror("Failed to allocate memory");
98+
abort();
99+
}
100+
101+
/* ... */
102+
103+
quirc_destroy(qr);
104+
105+
Having obtained a decoder object, you need to set the image size that
106+
you'll be working with, which is done using ``quirc_resize``:
107+
108+
if (quirc_resize(qr, 640, 480) < 0) {
109+
perror("Failed to allocate video memory");
110+
abort();
111+
}
112+
113+
``quirc_resize`` and ``quirc_new`` are the only library functions
114+
which allocate memory. If you plan to process a series of frames (or a
115+
video stream), you probably want to allocate and size a single decoder
116+
and hold onto it to process each frame.
117+
118+
Processing frames is done in two stages. The first stage is an
119+
image-recognition stage called identification, which takes a grayscale
120+
image and searches for QR codes. Using ``quirc_begin`` and
121+
``quirc_end``, you can feed a grayscale image directly into the buffer
122+
that ``quirc`` uses for image processing:
123+
124+
uint8_t *image;
125+
int w, h;
126+
127+
image = quirc_begin(qr, &w, &h);
128+
129+
/* Fill out the image buffer here.
130+
* image is a pointer to a w*h bytes.
131+
* One byte per pixel, w pixels per line, h lines in the buffer.
132+
*/
133+
134+
quirc_end(qr);
135+
136+
Note that ``quirc_begin`` simply returns a pointer to a previously
137+
allocated buffer. The buffer will contain uninitialized data. After
138+
the call to ``quirc_end``, the decoder holds a list of detected QR
139+
codes which can be queried via ``quirc_count`` and ``quirc_extract``.
140+
141+
At this point, the second stage of processing occurs -- decoding. This
142+
is done via the call to ``quirc_decode``, which is not associated with
143+
a decoder object.
144+
145+
int num_codes;
146+
int i;
147+
148+
/* We've previously fed an image to the decoder via
149+
* quirc_begin/quirc_end.
150+
*/
151+
152+
num_codes = quirc_count(qr);
153+
for (i = 0; i < num_codes; i++) {
154+
struct quirc_code code;
155+
struct quirc_data data;
156+
quirc_decode_error_t err;
157+
158+
quirc_extract(qr, i, &code);
159+
160+
/* Decoding stage */
161+
err = quirc_decode(&code, &data);
162+
if (err)
163+
printf("DECODE FAILED: %s\n", quirc_strerror(err));
164+
else
165+
printf("Data: %s\n", data.payload);
166+
}
167+
168+
``quirc_code`` and ``quirc_data`` are flat structures which don't need
169+
to be initialized or freed after use.
170+
171+
Copyright
172+
---------
173+
174+
Copyright (C) 2010-2012 Daniel Beer <<dlbeer@gmail.com>>
175+
176+
Permission to use, copy, modify, and/or distribute this software for
177+
any purpose with or without fee is hereby granted, provided that the
178+
above copyright notice and this permission notice appear in all
179+
copies.
180+
181+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
182+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
183+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
184+
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
185+
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
186+
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
187+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
188+
PERFORMANCE OF THIS SOFTWARE.

0 commit comments

Comments
 (0)