Skip to content

Commit a65e48e

Browse files
Add c_mpos module with quirc
1 parent fc12d9e commit a65e48e

File tree

17 files changed

+3462
-0
lines changed

17 files changed

+3462
-0
lines changed

c_mpos/esp32-quirc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(SRC_DIRS "lib" "openmv"
2+
INCLUDE_DIRS "lib" ".")
3+
4+
target_compile_options(${COMPONENT_LIB} PRIVATE -Ofast)

c_mpos/esp32-quirc/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.

c_mpos/esp32-quirc/Makefile

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 != pkg-config --cflags sdl
19+
SDL_LIBS != pkg-config --libs sdl
20+
21+
LIB_VERSION = 1.0
22+
23+
CFLAGS ?= -O3 -Wall -fPIC
24+
QUIRC_CFLAGS = -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+
DEMO_OBJ = \
31+
demo/camera.o \
32+
demo/mjpeg.o \
33+
demo/convert.o \
34+
demo/dthash.o \
35+
demo/demoutil.o
36+
37+
all: libquirc.so qrtest inspect quirc-demo quirc-scanner
38+
39+
qrtest: tests/dbgutil.o tests/qrtest.o libquirc.a
40+
$(CC) -o $@ tests/dbgutil.o tests/qrtest.o libquirc.a $(LDFLAGS) -lm -ljpeg -lpng
41+
42+
inspect: tests/dbgutil.o tests/inspect.o libquirc.a
43+
$(CC) -o $@ tests/dbgutil.o tests/inspect.o libquirc.a $(LDFLAGS) -lm -ljpeg -lpng $(SDL_LIBS) -lSDL_gfx
44+
45+
quirc-demo: $(DEMO_OBJ) demo/demo.o libquirc.a
46+
$(CC) -o $@ $(DEMO_OBJ) demo/demo.o libquirc.a $(LDFLAGS) -lm -ljpeg $(SDL_LIBS) -lSDL_gfx
47+
48+
quirc-scanner: $(DEMO_OBJ) demo/scanner.o libquirc.a
49+
$(CC) -o $@ $(DEMO_OBJ) demo/scanner.o libquirc.a $(LDFLAGS) -lm -ljpeg
50+
51+
libquirc.a: $(LIB_OBJ)
52+
rm -f $@
53+
ar cru $@ $(LIB_OBJ)
54+
ranlib $@
55+
56+
.PHONY: libquirc.so
57+
libquirc.so: libquirc.so.$(LIB_VERSION)
58+
59+
libquirc.so.$(LIB_VERSION): $(LIB_OBJ)
60+
$(CC) -shared -o $@ $(LIB_OBJ) $(LDFLAGS) -lm
61+
62+
.c.o:
63+
$(CC) $(QUIRC_CFLAGS) -o $@ -c $<
64+
65+
install: libquirc.a libquirc.so.$(LIB_VERSION) quirc-demo quirc-scanner
66+
install -o root -g root -m 0644 lib/quirc.h $(DESTDIR)$(PREFIX)/include
67+
install -o root -g root -m 0644 libquirc.a $(DESTDIR)$(PREFIX)/lib
68+
install -o root -g root -m 0755 libquirc.so.$(LIB_VERSION) \
69+
$(DESTDIR)$(PREFIX)/lib
70+
install -o root -g root -m 0755 quirc-demo $(DESTDIR)$(PREFIX)/bin
71+
install -o root -g root -m 0755 quirc-scanner $(DESTDIR)$(PREFIX)/bin
72+
73+
uninstall:
74+
rm -f $(DESTDIR)$(PREFIX)/include/quirc.h
75+
rm -f $(DESTDIR)$(PREFIX)/lib/libquirc.so.$(LIB_VERSION)
76+
rm -f $(DESTDIR)$(PREFIX)/lib/libquirc.a
77+
rm -f $(DESTDIR)$(PREFIX)/bin/quirc-demo
78+
rm -f $(DESTDIR)$(PREFIX)/bin/quirc-scanner
79+
80+
clean:
81+
rm -f */*.o
82+
rm -f */*.lo
83+
rm -f libquirc.a
84+
rm -f libquirc.so.$(LIB_VERSION)
85+
rm -f qrtest
86+
rm -f inspect
87+
rm -f quirc-demo
88+
rm -f quirc-scanner

c_mpos/esp32-quirc/lib/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.

c_mpos/esp32-quirc/lib/README.md

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

0 commit comments

Comments
 (0)