It is snowing like crazy outside and my
baby Yoda wants me to write a code in
Python
where I can generate a QR code and read
it. And that too in less than 10 lines
let's begin. QR code is basically quick
response coude. so for example
if I have a video link let's say this
bitcoin mining video
I want to send it to someone and if that
person doesn't want to type the whole
thing
I can generate a QR code for this link
so if you go to online QR code generator
like this
and if you copy paste this it will
generate this code
see? So it generates code for pretty much
anything. So you can type random things
and it will generate a code and now once
you have a QR code for this video link
what you can do is now you can scan this
QR code in your phone
iPhone whatever Android phone and it
will show you
the link of that video so see now when I
click on that video
it will take me there so the module we
are going to use
is called QR code so you need to install
it so you can just copy this command
pip install QR code
go to Python editor and in the terminal
paste this command, okay? pip install you
can install this from your command
prompt as well
once the module is installed you import
it so import
QR code and it's very straightforward
you will say
QR code dot make and here you supply the
string
that you want to encode in QR code so in
our case
i'm going to put the link of
my bitcoin mining code. see i wrote a
bitcoin mining code in like 15 lines of
python code. so that's
the link i'm going to paste here
and the result will be the image. okay
so result is image and that image
I can save so i'm going to just save it
in a
bitcoin dot jpg
okay you can see my current folder is
empty right now it doesn't have an image
when I run this it will have this image
which is the
barcode for my bitcoin so if I scan this
barcode you can try it by the way
scan it using your phone so open your
phone camera
just show this image to your camera and
it will take you to this particular link
so you see like how convenient this is
like just three line of code you
generated a bitcoin
mining codes
the video is a short link you can pretty
much supply
any data actually it doesn't have to be
url
any data you want to encode for example
my little baby Yoda who loves is
eating blue biscuits so he ate 20
biscuits today
so i'm going to encode that into
same QR code, okay. I will just call it
yoda dot jpg
when you run it you find another image
in the same folder you see
yoda.jpg these two barcodes are
different by the way see
they are different but it's a unique
code
that you can later on read as well so
let's try the reading part so for
reading part you need to install
opencv module okay so
this is how you install opencv so pip
install opencv python
so pip install opencv python again here
okay in the terminal
and once that is installed you will be
able to do
import cv2 and then
you can generate you are from cv2
you are code detector there is a class
called
qr code detector and that has method
called
detect and decode. detect and decode okay?
detect and decode what
let's say my baby Yoda image so you can
just say cv2 dot
i am read so this is how you read the
image in opencv
and i will say Yoda.jpg okay
and as a result i get three values back
so if you look at the documentation
say i get three return values okay
return value point straight
QR code so i'll just copy paste i'm lazy
i'll just copy paste okay and
i'll just call it val whatever and
i'm not going to worry about these two
methods the
the first one these two parameters... sorry
the first one
is your actual encoded string so when
you
print that.. see let me run it. so when you
print that
it will say baby yoda 8 20 biscuits
today
so what we did is we decoded a string
into a QR
into an image of QR code and same image
see here yoda.jpg i'm reading decoding
it back
and i get my original string back i just
showed you
very simple use case if you look at the
documentation
of qr code module you can do advanced
things like
you can use QR code class and you can
specify version error correction and so
on so you just just you can just
explore it but I just showed you a very
very simple use case
I want you to try this on different
strings and different type of data
and use your phone to scan it and you'll
be amazed
to see the results hmm baby yoda are you
happy with that
looks like he is so if you want
me to write such a cool application in
less than 10-15 lines of python code
then please provide
a suggestion in the video comment below
we have done some code before where we
can write
you know bitcoin mining code in Python
less than 15 lines
instagram you know google translations
and so on
the playlist is in the video description
below. He likes it
so just check it out and if you have any
other suggestion for the new videos
new baby yoda demands please post in a
comment below
thank you