Code Monkey home page Code Monkey logo

quirc's Introduction

Quirc

QR codes are a type of high-density matrix barcodes, and quirc is a library for extracting and decoding them from images. It has several features which make it a good choice for this purpose:

  • It is fast enough to be used with realtime video: extracting and decoding from VGA frame takes about 50 ms on a modern x86 core.

  • It has a robust and tolerant recognition algorithm. It can correctly recognise and decode QR codes which are rotated and/or oblique to the camera. It can also distinguish and decode multiple codes within the same image.

  • It is easy to use, with a simple API described in a single commented header file (see below for an overview).

  • It is small and easily embeddable, with no dependencies other than standard C functions.

  • It has a very small memory footprint: one byte per image pixel, plus a few kB per decoder object.

  • It uses no global mutable state, and is safe to use in a multithreaded application.

  • BSD-licensed, with almost no restrictions regarding use and/or modification.

The distribution comes with, in addition to the library, several test programs. While the core library is very portable, these programs have some additional dependencies as documented below.

quirc-demo

This is an real-time demo which requires a camera and a graphical display. The video stream is displayed on screen as it's received, and any QR codes recognised are highlighted in the image, with the decoded information both displayed on the image and printed on stdout.

This requires: libjpeg, libpng, SDL, V4L2

quirc-demo-opencv

A demo similar to quirc-demo. But this version uses OpenCV instead of other libraries.

This requires: OpenCV

quirc-scanner

This program turns your camera into a barcode scanner. It's almost the same as the demo application, but it doesn't display the video stream, and thus doesn't require a graphical display.

This requires: libjpeg, V4L2

qrtest

This test is used to evaluate the performance of library. Given a directory tree containing a bunch of JPEG images, it will attempt to locate and decode QR codes in each image. Speed and success statistics are collected and printed on stdout.

This requires: libjpeg, libpng

inspect

This test is used for debugging. Given a single JPEG image, it will display a diagram showing the internal state of the decoder as well as printing additional information on stdout.

This requires: libjpeg, libpng, SDL

inspect-opencv

A test similar to inspect. But this version uses OpenCV instead of other libraries.

This requires: libjpeg, libpng, OpenCV

Build-time requirements

make

While we are trying to keep our makefiles portable, it might be incompatible with some versions of make.

GNU make

Version 4.x and later works. We recommend to use it.

Version prior to 4.0 doesn't work because it doesn't support !=.

Note: macOS's default version of make is GNU make 3.81 as of writing this.

BSD make

It also works. You might need to specify the -r make option because some of the default macros like CFLAGS from sys.mk can cause unintended effects.

Installation

To build the library and associated demos/tests, type make.

Several options can be adjusted at compile time by passing additional arguments to make. See Compile-time options section below for details.

Type make install to install the library, header file and camera demos.

You can specify one or several of the following targets if you don't want, or are unable to build everything:

  • libquirc.a
  • libquirc.so
  • qrtest
  • inspect
  • inspect-opencv
  • quirc-scanner
  • quirc-demo
  • quirc-demo-opencv

Library use

All of the library's functionality is exposed through a single header file, which you should include:

#include <quirc.h>

To decode images, you'll need to instantiate a struct quirc object, which is done with the quirc_new function. Later, when you no longer need to decode anything, you should release the allocated memory with quirc_destroy:

struct quirc *qr;

qr = quirc_new();
if (!qr) {
    perror("Failed to allocate memory");
    abort();
}

/* ... */

quirc_destroy(qr);

Having obtained a decoder object, you need to set the image size that you'll be working with, which is done using quirc_resize:

if (quirc_resize(qr, 640, 480) < 0) {
    perror("Failed to allocate video memory");
    abort();
}

quirc_resize and quirc_new are the only library functions which allocate memory. If you plan to process a series of frames (or a video stream), you probably want to allocate and size a single decoder and hold onto it to process each frame.

Processing frames is done in two stages. The first stage is an image-recognition stage called identification, which takes a grayscale image and searches for QR codes. Using quirc_begin and quirc_end, you can feed a grayscale image directly into the buffer that quirc uses for image processing:

uint8_t *image;
int w, h;

image = quirc_begin(qr, &w, &h);

/* Fill out the image buffer here.
 * image is a pointer to a w*h bytes.
 * One byte per pixel, w pixels per line, h lines in the buffer.
 */

quirc_end(qr);

Note that quirc_begin simply returns a pointer to a previously allocated buffer. The buffer will contain uninitialized data. After the call to quirc_end, the decoder holds a list of detected QR codes which can be queried via quirc_count and quirc_extract.

At this point, the second stage of processing occurs -- decoding. This is done via the call to quirc_decode, which is not associated with a decoder object.

int num_codes;
int i;

/* We've previously fed an image to the decoder via
* quirc_begin/quirc_end.
*/

num_codes = quirc_count(qr);
for (i = 0; i < num_codes; i++) {
    struct quirc_code code;
    struct quirc_data data;
    quirc_decode_error_t err;

    quirc_extract(qr, i, &code);

    /* Decoding stage */
    err = quirc_decode(&code, &data);
    if (err)
        printf("DECODE FAILED: %s\n", quirc_strerror(err));
    else
        printf("Data: %s\n", data.payload);
}

quirc_code and quirc_data are flat structures which don't need to be initialized or freed after use.

In case you also need to support horizontally flipped QR-codes (mirrored images according to ISO 18004:2015, pages 6 and 62), you can make a second decode attempt with the flipped image data whenever you get an ECC failure:

    err = quirc_decode(&code, &data);
    if (err == QUIRC_ERROR_DATA_ECC) {
        quirc_flip(&code);
        err = quirc_decode(&code, &data);
    }

    if (err)
        printf("DECODE FAILED: %s\n", quirc_strerror(err));
    else
        printf("Data: %s\n", data.payload);

Compile-time options

The following compile-time options can be used to adjust the library to a particular use case.

Each option is a C preprocessor macro. To set an option, add it to CFLAGS using -DOPTION=VALUE syntax, for example:

make CFLAGS="-DQUIRC_MAX_REGIONS=65534"
  • QUIRC_MAX_REGIONS: If you need to decode "large" image files, set QUIRC_MAX_REGIONS=65534. Note that since this will increase the memory usage, it is discouraged for low resource devices (i.e. embedded).

  • QUIRC_FLOAT_TYPE: If defined, it sets the type name to use in floating point calculations. For example, on an embedded system with only a single precision FPU, set QUIRC_FLOAT_TYPE=float to improve performance.

  • QUIRC_USE_TGMATH: if defined, quirc will internally use <tgmath.h> header instead of <math.h>, ensuring that the math function calls use the same precision as the arguments. Define this option if you are setting QUIRC_FLOAT_TYPE=float and the compiler supports C99 or later language standard.

Copyright

Copyright (C) 2010-2012 Daniel Beer <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

quirc's People

Contributors

claudiofelber avatar czarkoff avatar dlbeer avatar igrr avatar jaaphaitsma avatar kaworu avatar mjbshaw avatar nuxeh avatar roger-wetzel avatar sushshring avatar yamt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quirc's Issues

sizeof() a dynamically allocated array is always 1?

It seems both q->image and q-> pixels are pointers to dynamically allocated arrays. The sizeof() operator have no way of knowing the actual size of the malloc array. This expression will always be true and the first branch will always taken, which makes the if statement useless.

if (sizeof(*q->image) == sizeof(*q->pixels)) {

Could not decode codes generated using qrcodejs

We are using qrcodejs to generate qr codes on our server, and the problem is that, the codes generated are not decoded properly.

Open the index.html from qrcodejs with Chrome or any browser, save the qr code to a file and inspect will tell you that "0 QR-codes found".

I did find out a workaround to this issue: adding a border to the generated code as follows:

    auto mat = cv::imread("qrcode.png", cv::IMREAD_GRAYSCALE);
    auto size = mat.size();
    cv::Mat vm(5, size.width, mat.type(), 255);
    cv::vconcat(vm, mat, mat);
    cv::vconcat(mat, vm, mat);
    size = mat.size();
    cv::Mat hm(size.height, 5, mat.type(), 255);
    cv::hconcat(hm, mat, mat);
    cv::hconcat(mat, hm, mat);

Then I'm able to decode the mat properly.

Any ideas why the border is mandatory for it to be decoded properly?

OTSU thresholding fails when QR code is computer generated values

If a QR code is computer generated and has purely 0x00 and 0xff values, the OTSU thresholding fails. This could be due to two things, fixing any of which seems to solve the issue:

  • In the otsu() method, the max check is incorrectly implemented at line 219 (identify.c).
if (variance > max) {
	threshold = i;
	max = variance;
}

The check should be variance >= max, specifically as per the wikipedia on otsu thresholding.

  • The second reason this fails is that the check at line 1083 (identify.c) *dest++ = (value < threshold) ? QUIRC_PIXEL_BLACK : QUIRC_PIXEL_WHITE; checks for a strictly less than value. This means that if the threshold is zero, the entire image appears white, which shouldn't be the case for an image that has no internal gray noise and is purely black and white (already thresholded).

The issue goes away after fixing the first bullet here and the threshold gets set to 0xfe, as should be. However, I don't know enough about the thresholding to give an educated answer about which is the correct method to solve this issue.

can't detect QR code for ROS camera image in Gazebo

I was using quirc lib in ROS simulation and everything goes smoothly excepts that it cannot detect any qr code I put in the gazebo simulation environment. I don't know if it's because the conversion between ROS sensor_msgs/Image topic and quirc image goes wrong or because the gazebo simulated image is not "real" enough. Any idea?
The gazebo image looks as follows:
Screenshot_20200425_221053

Detect mirrorred QR code

Not so much a bug report than a feature request.

Could 'inspect' be modified to attempt to mirror a reversed QR code & report it (as incompliant, it that is the case)?

Background:
In debugging an "unscannable" batch of QR codes this week (about a 50% success rate between physical and Android-based barcode scanners as well as online web decoders) - I attempted to use quirc "inspect" to try to get more info on the faulty code.

quirc returns an error (internally "QUIRC_ERROR_FORMAT_ECC") for the bad QR code, not much else - and some useful info on the "good" series. It turns out, as testing with an actual physical mirror shows, that our bad QR codes were printed mirrored; which I assume is an error and probably not compliant QR code (http://qrcode.meetheed.com/question2.php).

However, it appears that some QR decoding libraries attempt to mirror the image and retry the decoding; this also includes a few of the tested Android implementations I have tested, and at least 1 java library (I would have to check on Monday which).

The fact that multiple implementations accept and decode these mirrored QR codes, means that unfortunately these types of codes will probably continue to propagate (due to incomplete understanding of the spec, and bad/or quality control processes due, I suppose, to using incompliant devices for testing).
Perhaps there are also actual real-life situations where scanning a QR code through a mirror is useful (that, though, being outside the scope of this bugreport :-))

Tag a release?

I've got a patch to add quirc to Homebrew, but they really like to avoid having libraries that have no tagged releases.

Would it be possible to tag a release for quirc? Even if it's just a simple version string like 0.1 or 0.0.1.

grayscale framebuffer into uint8_t buffer

Hey sorry for this novice question but I think im just missing something obvious... Would be very happy with the some guidance 🥇

code getting framebuffer

camera_fb_t * fb = NULL;
  esp_err_t res = ESP_OK;

  fb = esp_camera_fb_get(); // framebuffer in grayscale

and feed it somehow to quirc?

int w, h;
    int i, count;
    uint8_t *buf = quirc_begin(qr, &w, &h);
    //
    //Feed 'fb' into 'buf' somehow?
    
    //
    quirc_end(qr);

I've looked through the code, source files etc, but as i'm a novice ive no clue how to merge or copy the two buffers.

from esp32 code:

//replace this with your own function
        display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);

Make error: missing separator

With Centos 3.10.0-693.17.1.el7.x86_64 and GNU Make 3.82, make error
Makefile:18: *** missing separator. Stop.
but with Mac os and GNU Make 3.81, there is no such error.
Line 18 is SDL_CFLAGS != pkg-config --cflags sdl

Can anyone help me? Thanks

Decoding problems with large images

When decoding large images (for example fullscreen screenshots), sometimes no qr codes are found at all or not all codes are found.

Attached is an example, where only one code is found.
image13

How to improve performance

issue

  • I ported the code to STM32 and esp32,it takes 2 seconds to identify, and the internal operation is basically floating-point operation,so How to improve performance

TKS

not detecting qrcode

hi, this image have 3 copies of the same qrcode, the 2 big (doubled) ones it does detect, the "normal" one it does not... i know it does not detect because theres a few non square blocks but it should detect anyway

425_920

QR code V40 (binary data) not decoded

Hi,
I 'm using QR codes to encode binary data (in this case a small .rar file).
The joined file is a picture generated by pyqrencode , not taken from a phone/cam.
quirc cannot find any QR code in it. ZXing online decoder is working OK.
Could it be related to the binary data ?
qrcode_v40__rar_file

[Question] Interested in CMake?

Hello, first off thanks for quirc :)

I am working in a somewhat unique build environment. I will pushing a cmake branch to my fork soon, and I would like to know if you are interested by it? A build system is usually a very subjective and personal subject, I fully understand if you do not want a PR for this.

Reasons I needed cmake include compiling on windows. Cmake automagically generates VS projects. VS2015 doesn't support C99 and C11, but they have added the LLVM toolchain. So by issuing cmake .. -G "Visual Studio 14 2015 Win64" -T "LLVM-vs2014" you can generate a Visual Studio project that compiles fine. I now have a windows lib (yay!).

If you are at all interested, I could spend the time to add cmake installation steps, so other users could use the builtin find_package(quirc) cmake function.

Good day

How to get detected codewords before error correction?

Hi,
I'm working on code-words error correction algorithm as part of my thesis. I need to show a demo but didn't find any good pure python qrcode reader and my understanding with C is limited. I just want to quickly know how to get detected code words. Can somebody point me in this library to get detected codewords, preferably as an array, before feeding them for error correction.
Thanks!

QR codes (with sample minimal demo programme) that segfault during decode; reproducibly.

Below are some images of a binary QR code that segfault deep in quirclib during a decode.

A trivial 'test.c' utility decode-c.txt is used for this test.

Fairly easy to reeproduce by doing:

openssl rand 400 > rnd.raw
qrencode -l H -8 -s 8 -r rnd.raw -o qr.png
decode qr.raw > rnd.raw.2 && openssl sha256 rnd.raw.*

a few times (1 in 10 or so fails). Below QR codes segfault on OSX, Linux and FreeBSD; SHA256 of the raw binary shown next to each.

qr 160c8cc11f06d0bd11519c53a5f62ec15cd98cf5dc763dfff5e07a13d1e2797c

qr 75daa67b1aa3ebc67570d8c82ac712bd43eb450a83aeced21ee5236ee261628b

qr 95d1ce7eee8f24f7b4892747c287be3b2825899f84b817e6c0c0e88ee9de5384

Compiling issue with c program utilizing quirc library?

For compiling c code which utilizing function defined in "dbgutil.h".Like
void dump_data(const struct quirc_data *data);
void dump_cells(const struct quirc_code *code);
int load_jpeg(struct quirc *q, const char *filename);
int check_if_png(const char *filename);
int load_png(struct quirc *q, const char *filename);

I have to include dbgutil.c file in my compiling process.Like

gcc test.c dbgutil.c -o test -lquirc -lpng -ljpeg (compiling test.c code)

otherwise it throwing error related to these functions defined in dbgutil.h file.

Is these function is not part of libquirc.so librray?

Possible to pass existing buffer into quirc?

I got quirc running on a small embedded target quite easily (nice job on the example code!), but at the moment I am only able to scan smaller QR codes because I don't have enough memory to allocate two copies of the image buffer.

My data is already in the same format that quirc requires, and looking at the code it seems like it would be easy to pass an extra (optional) parameter to quirc_resize(q,w,h,data) and use that buffer instead of calling malloc(). The onus is then on the caller to make sure the w, h, data match up, and to not call quirc_resize() again or to call it with a data parameter again, and be responsible for freeing the old one.

Does this seem like something you'd consider adding (or accept a PR for)?

Thanks!

Coverity complaining about improper use of negative value

This issue is really a false positive in the Coverity static analyzer, but proposing the following patch to make it happy:

diff --git a/functional/libquirc/lib/identify.c b/functional/libquirc/lib/identify.c
index 3651ff2..8d4a511 100644
--- a/functional/libquirc/lib/identify.c
+++ b/functional/libquirc/lib/identify.c
@@ -1011,7 +1011,7 @@ static void test_neighbours(struct quirc *q, int i,
                        }
                }

-       if (best_h < 0)
+       if (best_h < 0 || best_v < 0)
                return;

        record_qr_grid(q, best_h, i, best_v);

It complains that best_v could possibly be passed to record_qr_grid while negative, where it will be used as an index into an array. Looking at how test_neighbours is called, I think that is not correct, but I think the fix is not too intrusive, so I hope it's acceptable to you.

Native Android Support

I want to use this decoder in my android app. How to compile it in android studio?
Do you have any support for java or android?

Trouble using / installing quirc

Hello,

I'm new to C and I want to use quirc both as a command line utility and in my own projects. I'm on macOS Sierra. I've taken the following steps to attempt to run it

$ git clone https://github.com/dlbeer/quirc
$ brew install jpeg
$ make install

This results in

demo/camera.c:29:10: fatal error: 'linux/videodev2.h' file not found
#include <linux/videodev2.h>
         ^
1 error generated.
make: *** [demo/camera.o] Error 1

which is expected since the README says that the camera demo is only supported on Linux.

I'm not sure where to proceed from here. I tried creating

lib/test.c
#include "quirc.h"

$ gcc test.c

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Apologies in advance for such basic questions but I am unable to find resources that teach how to use "non standard" C libraries in my projects.

Failing to detect a QR code in a certain angle

I am utilizing libquirc for decoding QR codes from a smartphone's screen with a camera. The library has been working really well so far. However, I just discovered that there is a case where having the phone in a very specific orientation causes the library to find the QR code corner markers in invalid locations, and then fails to read the data with an ECC failure. An example image where the decoding fails is shown below:

qr_fail_no_imei

The interesting part is, that if I rotate the image 90 degrees clockwise, the QR code is detected correctly. Also, if I photoshop away the text that is visible in the phone's display, the detection is successful.

qr_fail_no_text

Any ideas on how to fix or work around this?

[Question]A memory leak?

Hi,
Thanks for your library first, it helps me a lot.

In normal case, this library should work on below steps,

  1. quirc_new()
  2. quirc_resize()
  3. quirc_begin(), quirc_end()
  4. quirc_count, LOOP [quirc_extract(), quirc_decode()]
  5. Goto 3 or 6
  6. quirc_destroy()

Is it right?

When first time call quirc_resize(), it will allocates a memory for q->pixels.
But in quirc_end() -> pixels_setup(), it has a chance be replace with q->image without release.

(q->pixels = (quirc_pixel_t *)q->image;)

I think that may cause a memory leak, but I am not sure, so I come to here and try to report it to you.

Anyway, thanks for your project.

Remove C99 features: vla for Visual Studio and for loop initial declarations for gcc < 5

In function otsu in identify.c file:

  • unsigned int histogram[HISTOGRAM_SIZE] is a vla for Visual Studio, so it can't compile.
  • there are two 'for loop with initial declarations'. It fails to compile with gcc 4.9 in Debug mode if -std=c99 is not explicitly added to the command line.

This simple patch fix these issues:

--- a/lib/identify.c
+++ b/lib/identify.c
@@ -180,7 +180,7 @@ static uint8_t otsu(const struct quirc *q)
 	int numPixels = q->w * q->h;
 
 	// Calculate histogram
-	const int HISTOGRAM_SIZE = 256;
+	#define HISTOGRAM_SIZE 256
 	unsigned int histogram[HISTOGRAM_SIZE];
 	memset(histogram, 0, (HISTOGRAM_SIZE) * sizeof(unsigned int));
 	uint8_t* ptr = q->image;
@@ -192,7 +192,8 @@ static uint8_t otsu(const struct quirc *q)
 
 	// Calculate weighted sum of histogram values
 	int sum = 0;
-	for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
+	int i;
+	for (i = 0; i < HISTOGRAM_SIZE; ++i) {
 		sum += i * histogram[i];
 	}
 
@@ -201,7 +202,7 @@ static uint8_t otsu(const struct quirc *q)
 	int q1 = 0;
 	double max = 0;
 	uint8_t threshold = 0;
-	for (int i = 0; i < HISTOGRAM_SIZE; ++i) {
+	for (i = 0; i < HISTOGRAM_SIZE; ++i) {
 		// Weighted background
 		q1 += histogram[i];
 		if (q1 == 0)

how to extract luma channel from a 4:2:0 YUV image?

Hi
I'm working on porting the quirc library on embedded system, and try to refer the quirc-scanner example to scan qrcode.
However my device support the video format is YUV420 ,
Is it suitable for scanning qrcode ? and how to extract luma channel from yuv420 image?
I 'm not have much experience on qrcode scan , but if any suggestions would be helpful.

Thanks.
Nick

Quirc for video files?

Hi, I'm looking for a program that is capable of finding qr codes within a video file. Can Quirc do this?

Thanks.

QR code standards/variants supported?

For software selection purposes, can you be a little bit more specific in the README.md about what QR code standards/variants the library is supposed to support?

JPEG with invalid SOS parameters triggers double-free flaw

Compiled with afl-clang-fast on Debian 8 x64. Triggered with 5174ba7.

./inspect test000.jpeg

quirc inspection program
Copyright (C) 2010-2012 Daniel Beer <[email protected]>
Library version: 1.0

JPEG error: Invalid SOS parameters for sequential JPEGJPEG error: Unsupported marker type 0x30=================================================================
==32096==ERROR: AddressSanitizer: attempting double-free on 0x61600000f980 in thread T0:
    #0 0x4a0d9b in free (/root/quirc/inspect+0x4a0d9b)
    #1 0x7f0e97f65734 in fclose /build/glibc-KShDyh/glibc-2.19/libio/iofclose.c:85
    #2 0x4bf587 in load_jpeg /root/quirc/tests/dbgutil.c:160:2
    #3 0x4c1487 in main /root/quirc/tests/inspect.c:243:12
    #4 0x7f0e97f1db44 in __libc_start_main /build/glibc-KShDyh/glibc-2.19/csu/libc-start.c:287
    #5 0x4be69c in _start (/root/quirc/inspect+0x4be69c)

0x61600000f980 is located 0 bytes inside of 568-byte region [0x61600000f980,0x61600000fbb8)
freed by thread T0 here:
==32096==AddressSanitizer CHECK failed: /tmp/buildd/llvm-toolchain-3.5-3.5/projects/compiler-rt/lib/asan/asan_allocator2.cc:203 "((id)) != (0)" (0x0, 0x0)
    #0 0x4a8473 in __asan::AsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/root/quirc/inspect+0x4a8473)
    #1 0x4aeec1 in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/root/quirc/inspect+0x4aeec1)
    #2 0x43a519 in __asan::AsanChunkView::GetFreeStack(__sanitizer::StackTrace*) (/root/quirc/inspect+0x43a519)
    #3 0x4a44dd in __asan::DescribeHeapAddress(unsigned long, unsigned long) (/root/quirc/inspect+0x4a44dd)
    #4 0x4a4d9a in __asan::ReportDoubleFree(unsigned long, __sanitizer::StackTrace*) (/root/quirc/inspect+0x4a4d9a)
    #5 0x43ce8d in __asan::ReportInvalidFree(void*, unsigned char, __sanitizer::StackTrace*) (/root/quirc/inspect+0x43ce8d)
    #6 0x43b845 in __asan::Deallocate(void*, __sanitizer::StackTrace*, __asan::AllocType) (/root/quirc/inspect+0x43b845)
    #7 0x4a0e5c in free (/root/quirc/inspect+0x4a0e5c)
    #8 0x7f0e97f65734 in fclose /build/glibc-KShDyh/glibc-2.19/libio/iofclose.c:85
    #9 0x4bf587 in load_jpeg /root/quirc/tests/dbgutil.c:160:2
    #10 0x4c1487 in main /root/quirc/tests/inspect.c:243:12
    #11 0x7f0e97f1db44 in __libc_start_main /build/glibc-KShDyh/glibc-2.19/csu/libc-start.c:287
    #12 0x4be69c in _start (/root/quirc/inspect+0x4be69c)

Crashes on quirc_end

Hello, I am trying to use this library on a ESP32 (with esp32-camera), but quirc_end seems to not work properly.

Some specs:

Platform: ESP32 (esp-idf)
quirc version: june 30 master
(but also tried an older version with same results)
Using 320x240 grayscale images

My code

[ .... code that creates 'fb' with 'fb->buf' being image data, and uses quirc resize ]
int buf_w, buf_h;
image = quirc_begin(q, &buf_w, &buf_h);
// Fill image buffer
assert fb->len == buf_w * buf_h
memcpy(image, fb->buf, fb->len);
// End
printf("quirc_end\n");
quirc_end(q);

printf("quirc_count\n");
int id_count = quirc_count(q);
[ .... rest, but never reached ]

The code crashes somewhere is quirc_end in the 'finder_scan' part of it.
(which I know because I edited (the middle of) it like this:

pixels_setup(q, threshold);
printf("Pixel setup finished\n");
for (i = 0; i < q->h; i++)
	finder_scan(q, i);
printf("Finder Scan finished\n");

Output

Running this code does not work, but surprisingly has 2 possible crashes:

Either:

[ startup and other output ]
quirc_end
Pixel setup finished
??╔╔f79ba24b1b7a80baad9b3f8917a3b7d4aef4185de9f8cf9ef7c4eedaf23aa610╔??╔lC?PY??╔3ffcd9dcPY??╔3ffb0140lC?PY??╔4008789dPY??╔3ffb0200lC?PY??╔40087ae5PY??╔3ffb0220lC?PY??╔40084d0dPY??╔
3ffb0240lC?PY??╔40084e41PY??╔3ffb0270lC?PY??╔400da452PY??╔3ffb0290lC?PY??╔400d584dPY??╔3ffb0550lC?PY??╔400d57e8PY??╔3ffb05a0lC?PY??╔4008a6cePY??╔3ffb05d0lC?PY??╔4008ae9dPY?
?╔3ffb0600lC?PY??╔4008b75bPY??╔3ffb0620lC?PY??╔4008c64dPY??╔3ffb0640lC?PY??╔4008466aPY??╔3ffb0650lC?PY??╔400e603dPY??╔3ffb2090lC?PY??╔400e6cf4PY??╔3ffb20e0lC?PY??╔400d56b9PY
??╔3ffb2100lC?PY??╔400d54e8PY??╔3ffb5380lC?PY??╔400d1200PY??╔3ffb53a0lC?PY??╔4008b66dPY??╔3ffb53c0╔╔Rebootin╔
[ ESP32 reboots ]

Or:

[ startup and other output ]
quirc_end
Pixel setup finished
h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
)& 1 reg*h@?i 1p?? ╔h@?i 1p?? ╔h@?i 1p?? ╔h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
)& 1 reg*h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
)& 1 reg*h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
[ ... last line keeps repeating about 500 times ]
)& 1 reg*h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
)& 1 reg*h@?i 1p?? ╔assertion "%s" failed: file "%s", line %d%s%s
)& 1 reg*╔h@?i 1p?? ╔╔╔╔P ?P ?P ?P ?P ?P ?P ?@p ? ?@?|? 1p?? ╔@p ? ?@?|? 1p?? ╔
[ ESP32 stops giving output (but does not restart or anything) ]

Notice how "Pixel setup finished" is always outputted, while "Finder Scan finished" is not.

I would greatly appreciate any help

quirc can't decode a qrcode

Hello,
I'm implementing a small qrcode parser function based on this function but I can't parse on of the test image I have.
The first image is correctly parsed, but the second it's not.

test1

test2

$ qrtest ../test1.png
quirc test program
Copyright (C) 2010-2012 Daniel Beer <[email protected]>
Library version: 1.0

                                          Time (ms)       Count
  Filename                         Load    ID Total    ID   Dec
-------------------------------------------------------------------------------
  test1.png                     :     1     3     4     1     1

$ qrtest ../test2.png
quirc test program
Copyright (C) 2010-2012 Daniel Beer <[email protected]>
Library version: 1.0

                                          Time (ms)       Count
  Filename                         Load    ID Total    ID   Dec
-------------------------------------------------------------------------------
  test2.png                     :     0     1     1     0     0

I have tried with zbarimg and both are correctly parsed, so it doesn't seem to be an issue with the 2nd image.

I tried on Fedora 27 x64, using latest master.

num_codes returns 0

Hello, I've tried to use the code provided just like in the readme file to test the application.
here's my main

`struct quirc *qr;
qr = quirc_new();
if (!qr) {
cout << "Failed to allocate memory" << endl;
abort();
}

Mat frame = imread("A.jpg");

namedWindow("Display window", WINDOW_AUTOSIZE);
//imshow("Display window", frame);
//waitKey(0);

if (quirc_resize(qr, frame.cols, frame.rows) < 0) {
	cout << "Failed to allocate video memory" << endl;
	abort();
}

uint8_t *image;
int w, h;

image = quirc_begin(qr, &w, &h);

quirc_end(qr);

int num_codes=0;
int i=0;

num_codes = quirc_count(qr);
for (i = 0; i < num_codes; i++) {
	struct quirc_code code;
	struct quirc_data data;
	quirc_decode_error_t err;

	quirc_extract(qr, i, &code);

	/* Decoding stage */
	err = quirc_decode(&code, &data);
	if (err)
		cout << "DECODE FAILED: " << quirc_strerror(err) << endl;
	else
		cout << "Data: " << data.payload << endl;
}

quirc_destroy(qr);
return 0;`

the num_codes is returning a zero for a valid QR image, did I implement anything wrong?

bug_memory_copy:quirc_flip

describe

  • prototype
void quirc_flip(struct quirc_code *code)
{
	struct quirc_code flipped = {0};
	unsigned int offset = 0;
	for (int y = 0; y < code->size; y++) {
		for (int x = 0; x < code->size; x++) {
			if (grid_bit(code, y, x)) {
				flipped.cell_bitmap[offset >> 3u] |= (1u << (offset & 7u));
			}
			offset++;
		}
	}
	memcpy(&code->cell_bitmap, &flipped.cell_bitmap, sizeof(flipped.cell_bitmap));
}

memcpy(&code->cell_bitmap, &flipped.cell_bitmap, sizeof(flipped.cell_bitmap));

  • There is illegal access
memcpy(code->cell_bitmap, flipped.cell_bitmap, sizeof(flipped.cell_bitmap));

Possible problem in thresholding

Hi,

I've been testing quirc using a number of ways of degrading QR codes to see how it performs.

I found this case, where i think there might be an issue with the thresholding:

Works:

image

Fails:

image

The central grey areas have the same contrast, i think this could be a problem with the big difference in contrast in the white border making the row averaging unreliable.

Any ideas how to improve this?

Ed

QUIRC_ERROR_DATA_ECC on each Image

when ever i feed an image to the quirc decoder it return an QUIRC_ERROR_DATA_ECC Error i have checked the bar-codes and they are readable.

can you help me what i am messing? I have followed the implementation as described in the read me file

DECODE FAILED: ECC failure

I am decoding qr code using quirc library and getting this message.DECODE FAILED: ECC failure what does that mean.The same qr-code I am able to decode using another library.

Out of bounds read in quirc_strerror

There's a off-by one error which can cause quirc_strerror to do an out of bounds read, changing the <= to < in the test should fix the issue:

diff --git a/functional/libquirc/lib/quirc.c b/functional/libquirc/lib/quirc.c
index 9abbc6c..e0ffef4 100644
--- a/functional/libquirc/lib/quirc.c
+++ b/functional/libquirc/lib/quirc.c
@@ -74,7 +74,7 @@ static const char *const error_table[] = {

 const char *quirc_strerror(quirc_decode_error_t err)
 {
-    if (err >= 0 && err <= sizeof(error_table) / sizeof(error_table[0]))
+    if (err >= 0 && err < sizeof(error_table) / sizeof(error_table[0]))
         return error_table[err];

     return "Unknown error";

QR code ECC failure

I have an example of a QR code which Quirc is not able do decode. It can locate it within the image but fails later with an ECC error when decoding the data. I checked the code with the Quirc inspect tool and the pixels appear to have been read correctly. I wonder if the problem is related to the small overlayed image in the center (it's required by the Swiss QR bill standard). Other QR code readers such as ZXing or the built-in QR code reader on iOS are able to decode the image correctly. boofcv on the other hand also fails to decode the QR code data.

The QR-code example image has been intentionally removed.

ECC failure and Format data ECC failure issues from QR images captured from WiFi Camera

Iam using the quirctest application to decode the QR codes coming in snapshot images from a wifi camera. Iam using a image resolution of 1920 x 1080. Iam running the application on a X86_64 machine. Application seems to detect the presence of QR code in the image but unable to decode it.

quirc test program
Copyright (C) 2010-2012 Daniel Beer <[email protected]>
Library version: 1.0

                                          Time (ms)       Count
  Filename                         Load    ID Total    ID   Dec
-------------------------------------------------------------------------------
/media/narayana/Hari/images:
  0.jpeg                        :    36    10    46     0     0
  1.jpeg                        :    15     9    24     0     0
  2.jpeg                        :    15     9    24     0     0
  3.jpeg                        :    15     9    24     0     0
  4.jpeg                        :    15    12    27     0     0
  5.jpeg                        :    16    10    26     0     0
  6.jpeg                        :    18    11    29     0     0
QR code decode failed due to ECC failure
  7.jpeg                        :    15    15    30     1     0
  8.jpeg                        :    16    11    27     0     0
  9.jpeg                        :    16    11    27     0     0
  10.jpeg                       :    16    11    27     0     0
  11.jpeg                       :    16    11    27     0     0
  12.jpeg                       :    15    10    25     0     0
  13.jpeg                       :    22    10    32     0     0
  14.jpeg                       :    15    11    26     0     0
  15.jpeg                       :    16    11    27     0     0
  16.jpeg                       :    18    12    30     0     0
  17.jpeg                       :    16    11    27     0     0
  18.jpeg                       :    13    11    24     0     0
  19.jpeg                       :    16    13    29     0     0
QR code decode failed due to Format data ECC failure
  20.jpeg                       :    17    22    39     1     0
QR code decode failed due to Format data ECC failure
  21.jpeg                       :    20    14    34     1     0
QR code decode failed due to Format data ECC failure
  22.jpeg                       :    20    14    34     1     0
QR code decode failed due to ECC failure
  23.jpeg                       :    21    16    37     1     0
QR code decode failed due to Format data ECC failure
  24.jpeg                       :    22    18    40     1     0
QR code decode failed due to Format data ECC failure
  25.jpeg                       :    22    21    43     1     0
QR code decode failed due to Format data ECC failure
  26.jpeg                       :    23    24    48     1     0
QR code decode failed due to Format data ECC failure
  27.jpeg                       :    19    23    42     1     0
QR code decode failed due to Format data ECC failure
  28.jpeg                       :    22    21    43     1     0
QR code decode failed due to Format data ECC failure
  29.jpeg                       :    20    14    34     1     0
QR code decode failed due to Format data ECC failure
  30.jpeg                       :    18    18    36     1     0
  31.jpeg                       :    20    18    38     0     0
  32.jpeg                       :    27    12    39     0     0
QR code decode failed due to ECC failure
  33.jpeg                       :    18    14    32     1     0
QR code decode failed due to Format data ECC failure
  34.jpeg                       :    17    14    31     1     0
  35.jpeg                       :    19    11    30     0     0
QR code decode failed due to Format data ECC failure
  36.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  37.jpeg                       :    17    14    31     1     0
QR code decode failed due to Format data ECC failure
  38.jpeg                       :    25    14    39     1     0
QR code decode failed due to Format data ECC failure
  39.jpeg                       :    23    14    37     1     0
QR code decode failed due to Format data ECC failure
  40.jpeg                       :    22    13    35     1     0
QR code decode failed due to ECC failure
  41.jpeg                       :    23    16    40     1     0
QR code decode failed due to ECC failure
  42.jpeg                       :    17    15    32     1     0
QR code decode failed due to ECC failure
  43.jpeg                       :    18    14    32     1     0
QR code decode failed due to ECC failure
  44.jpeg                       :    18    14    33     1     0
QR code decode failed due to ECC failure
  45.jpeg                       :    16    15    31     1     0
QR code decode failed due to ECC failure
  46.jpeg                       :    18    14    32     1     0
QR code decode failed due to ECC failure
  47.jpeg                       :    17    15    32     1     0
QR code decode failed due to Format data ECC failure
  48.jpeg                       :    17    15    32     1     0
QR code decode failed due to ECC failure
  49.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  50.jpeg                       :    17    14    32     1     0
QR code decode failed due to Format data ECC failure
  51.jpeg                       :    17    14    32     1     0
QR code decode failed due to Format data ECC failure
  52.jpeg                       :    17    14    32     1     0
QR code decode failed due to ECC failure
  53.jpeg                       :    17    15    32     1     0
QR code decode failed due to ECC failure
  54.jpeg                       :    18    15    33     1     0
QR code decode failed due to Format data ECC failure
  55.jpeg                       :    17    15    32     1     0
  56.jpeg                       :    18    12    30     0     0
  57.jpeg                       :    17    12    29     0     0
  58.jpeg                       :    18    12    30     0     0
QR code decode failed due to Format data ECC failure
  59.jpeg                       :    17    16    33     1     0
  60.jpeg                       :    18    13    31     0     0
  61.jpeg                       :    17    12    29     0     0
QR code decode failed due to Format data ECC failure
  62.jpeg                       :    18    15    33     1     0
  63.jpeg                       :    18    13    31     0     0
  64.jpeg                       :    18    13    31     0     0
  65.jpeg                       :    16    12    28     0     0
  66.jpeg                       :    18    13    31     0     0
  67.jpeg                       :    17    13    30     0     0
  68.jpeg                       :    17    13    30     0     0
  69.jpeg                       :    19    12    31     0     0
  70.jpeg                       :    19    12    31     0     0
  71.jpeg                       :    22    13    35     0     0
QR code decode failed due to Format data ECC failure
  72.jpeg                       :    16    14    30     1     0
QR code decode failed due to ECC failure
  73.jpeg                       :    18    14    32     1     0
QR code decode failed due to Format data ECC failure
  74.jpeg                       :    16    15    31     1     0
QR code decode failed due to ECC failure
  75.jpeg                       :    16    15    31     1     0
QR code decode failed due to ECC failure
  76.jpeg                       :    16    14    31     1     0
QR code decode failed due to ECC failure
  77.jpeg                       :    16    14    30     1     0
QR code decode failed due to ECC failure
  78.jpeg                       :    17    14    31     1     0
QR code decode failed due to Format data ECC failure
  79.jpeg                       :    16    14    30     1     0
QR code decode failed due to ECC failure
  80.jpeg                       :    17    14    31     1     0
QR code decode failed due to Format data ECC failure
  81.jpeg                       :    16    14    30     1     0
  82.jpeg                       :    17    11    28     0     0
QR code decode failed due to ECC failure
  83.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  84.jpeg                       :    17    15    32     1     0
QR code decode failed due to ECC failure
  85.jpeg                       :    17    14    32     1     0
QR code decode failed due to ECC failure
  86.jpeg                       :    16    15    31     1     0
QR code decode failed due to Format data ECC failure
  87.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  88.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  89.jpeg                       :    16    15    31     1     0
QR code decode failed due to Format data ECC failure
  90.jpeg                       :    16    15    31     1     0
QR code decode failed due to Format data ECC failure
  91.jpeg                       :    16    16    32     1     0
QR code decode failed due to ECC failure
  92.jpeg                       :    16    15    31     1     0
QR code decode failed due to ECC failure
  93.jpeg                       :    17    14    31     1     0
QR code decode failed due to Format data ECC failure
  94.jpeg                       :    17    14    31     1     0
QR code decode failed due to ECC failure
  95.jpeg                       :    18    14    33     1     0
QR code decode failed due to ECC failure
  96.jpeg                       :    16    15    31     1     0
QR code decode failed due to Format data ECC failure
  97.jpeg                       :    17    14    32     1     0
QR code decode failed due to ECC failure
  98.jpeg                       :    16    15    31     1     0
JPEG error: Premature end of JPEG file
QR code decode failed due to ECC failure
  99.jpeg                       :    13    18    31     1     0
-------------------------------------------------------------------------------
images: 100 files, 63 codes, 0 decoded (63 failures), 0% success rate
Total time [load: 1780, identify: 1390, total: 3180]
Average time [load: 17, identify: 13, total: 31]

Iam attaching one of the image i used for testing.
I need help in getting the application to scan the QR code.
I want to know what is wrong and what needs to be improved.
30

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.