QR Reader/Decoder Lib?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
MindJuice
Posts: 12
Joined: Tue Apr 14, 2020 6:09 am

QR Reader/Decoder Lib?

Post by MindJuice » Tue Apr 14, 2020 6:14 am

I just started out with MP a week or so ago.

Are there any QR code decoder libraries like zbar or quirc that I can upip install?

I haven't found anything in my searching so far.

If not, is there a good guide on how to take an existing Python/C module and adapt it for MP?

Thanks!

User avatar
jimmo
Posts: 2263
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: QR Reader/Decoder Lib?

Post by jimmo » Tue Apr 14, 2020 6:42 am

I can imagine that QR decoding could be very slow in Python, so writing it in C probably makes sense (especially if you have an existing library).

Interestingly, the reverse (creation of QR codes) was one of the very first examples of the new "dynamic native modules" feature. Matt gave a talk about it here: https://www.youtube.com/watch?v=437CZBnK8vI I think the code is here: https://github.com/mattytrentini/microp ... modules/qr

Docs for the feature are here: http://docs.micropython.org/en/latest/d ... atmod.html
MindJuice wrote:
Tue Apr 14, 2020 6:14 am
If not, is there a good guide on how to take an existing Python/C module and adapt it for MP?
I'm not sure if by Python/C you mean a "CPython module implemented in C" (not really, the API is totally different), or just "any Python or C module" (the former should be fairly straightfowards, the latter see above).

MindJuice
Posts: 12
Joined: Tue Apr 14, 2020 6:09 am

Re: QR Reader/Decoder Lib?

Post by MindJuice » Tue Apr 14, 2020 7:19 am

Thanks for the response.

When I wrote "PythonC/C", I meant something like this: https://pypi.org/project/quirc/ or this: https://pypi.org/project/zbar-py/

Which as you suggest are a C libraries with a Python wrapper.

I actually watched that video you linked the other day, but it's not clear to me if I can take something like the above Python-wrapped C code and just put it into the right spot in the MP hierarchy and have it compile or whether I need to write a completely different wrapper.

And if the latter, where does each of the files need to go so that they are compiled properly and available to import from other code.

Thanks.

User avatar
jimmo
Posts: 2263
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: QR Reader/Decoder Lib?

Post by jimmo » Tue Apr 14, 2020 7:37 am

MindJuice wrote:
Tue Apr 14, 2020 7:19 am
I actually watched that video you linked the other day, but it's not clear to me if I can take something like the above Python-wrapped C code and just put it into the right spot in the MP hierarchy and have it compile or whether I need to write a completely different wrapper.
Nope, the CPython API bindings are totally different to MicroPython.

You'll need to write the MicroPython bindings.
MindJuice wrote:
Tue Apr 14, 2020 7:19 am
And if the latter, where does each of the files need to go so that they are compiled properly and available to import from other code.
Start with the example in http://docs.micropython.org/en/latest/d ... atmod.html and see if you can compile very basic .mpy file.
You just need to clone the main micropython repo and set MPY_DIR to the path where you cloned it in that Makefile.


The other option of course is that you can just build it directly into the main firmware. i.e. start with https://github.com/micropython/micropython and compile it for whichever board you're using, then look at the instructions here http://docs.micropython.org/en/latest/d ... dules.html for how to write a custom module that's compiled into the firmware.

MindJuice
Posts: 12
Joined: Tue Apr 14, 2020 6:09 am

Re: QR Reader/Decoder Lib?

Post by MindJuice » Tue Apr 14, 2020 6:30 pm

Thanks. I'll take a look at those links tonight.

User avatar
dhylands
Posts: 3656
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: QR Reader/Decoder Lib?

Post by dhylands » Tue Apr 14, 2020 7:04 pm

OpenMV has a copy of quirc in it:
https://github.com/openmv/openmv/blob/m ... g/qrcode.c

and has some micropython interfaces as well:
https://github.com/openmv/openmv/blob/m ... 5324-L5492

MindJuice
Posts: 12
Joined: Tue Apr 14, 2020 6:09 am

Re: QR Reader/Decoder Lib?

Post by MindJuice » Wed Apr 15, 2020 7:33 am

Thanks! This definitely looks worth a go.

I just have to figure out how to extract the relevant bits into my project.

MindJuice
Posts: 12
Joined: Tue Apr 14, 2020 6:09 am

Re: QR Reader/Decoder Lib?

Post by MindJuice » Mon Apr 20, 2020 7:20 am

I ended up using in the quirc C code directly from their github repo and writing a fairly simple MP wrapper for it. Their example code is a really great starting point. https://github.com/dlbeer/quirc

I was able to test it with a sample image file today and it recognized the QR code! :D

This code will all be open source once it's done (~2-3 months), but for now, it's in a private repo.

If anyone wants it sooner, I can take some time to sanitize it for public consumption.

Cheers!

Guru
Posts: 2
Joined: Sun Dec 17, 2017 8:28 pm

Re: QR Reader/Decoder Lib?

Post by Guru » Wed Aug 26, 2020 9:27 am

Hi,
Were you to complete the project for verification of QR code using esp32-cam on micropython? if yes, i would be very much interested in testing out for one of my requirements.

Thanks

John12
Posts: 3
Joined: Thu Jun 10, 2021 8:41 pm

Re: QR Reader/Decoder Lib?

Post by John12 » Thu Jun 10, 2021 8:48 pm

MindJuice wrote:
Mon Apr 20, 2020 7:20 am
I ended up using in the quirc C code directly from their github repo and writing a fairly simple MP wrapper for it. Their example code is a really great starting point. https://github.com/dlbeer/quirc

I was able to test it with a sample image file today and it recognized the QR code! :D

This code will all be open source once it's done (~2-3 months), but for now, it's in a private repo.

If anyone wants it sooner, I can take some time to sanitize it for public consumption.

Cheers!
Hello,

Is your code available ? Thank you

Post Reply