Hi and welcome back to Section 22, where we take a look at barcode and QR generation as well as reading.
So it's a pretty fun and useful chapter depending on your application.
So let's go ahead and open that notebook.
So let's firstly load an important libraries and actually before I even see we've been putting all libraries.
Let's take a look at the libraries we're installing.
We're installing something called Python Barcode Area, specifying images here and the brackets QR code
Lib Zeba, which is a very powerful barcode and QR code reading library as well as possible.
So we have to install all of these here.
So let's run this.
It may take a little while to install because it's four different packages that we're installing right
now.
So let's wait for this to finish.
Should, shouldn't take that long.
There we go.
So it took twenty six seconds to complete.
So that's not too bad.
So now we can use our barcode and QR code reading and decoding libraries.
So the first one we're going to take a look at is barcode generation.
So barcodes, as you know, barcodes are just line representations of symbol of what it's coded information
that we can decode and basically be a text or digits or any sort of information relative to store barcodes.
Or we we can store information effectively.
So it's type of like coding system.
So you can see this is the barcode every generated here.
So let's just run this website and you can put any number you want here.
This is an entity.
So that's 15 digit number, I believe.
So you can store this number here.
It can.
You can create any number you want here, and it generates the barcode representing that number.
I can see the backwards, depending on the thickness of the line represents that represents some bits
of information gaps as well.
Thin Line So it's a coding system, as I said, for including information here.
And the reason we use barcodes in the real world is because we have this little infrared scanners,
which you see in groceries everywhere there was able to read barcodes.
They're quite effective at decoding that information quickly.
So it's a very useful way to store information that that that is tied to the data.
So now let's take a look at QR codes.
So QR codes are a bit different.
They're abbreviated to short for quick response.
Good.
And it's sort of like a matrix like barcodes, a two dimensional barcode that was developed in the automotive
industry in Japan.
And there are different types of QR codes, lots of different epic QR codes, as you can see with barcodes,
or lots of different types of barcodes as well, and specify the type you want to include by using the
function here would have one, whichever one you're looting.
So your codes follows similar suit.
However, there's a standard generic type of QR code that we all use.
So it doesn't.
There's not as much variety of QR codes.
However, there are configurations we can do in QR codes that affect the area, coding in it or decoding.
There's some redundant information or coded information of checksums.
I'm not sure if you know a checksums are because you're taught to make undergrad computer science and
engineering, but in a way you can sum up information to see if that sum is corresponds to the correct
sum in parts of information.
That's a we of error checking your information.
So using the input your QR code library that we import here, we're declaring this here.
We're creating this object here, which is the vision error correction.
You can take a look at this problem to see it.
This is what these parameters stand for.
Error correction.
This means that only seven percent of errors can be corrected.
But if we use each hire correction, you can correct about 30 percent of errors, which makes it quite
resilient.
So you can read it for angles, for lighting.
So it's probably better to encode your QR codes with that once information can fit.
Because just remember, every time you increase the error correction, you reduce the amount of information
that you can store in your QR code.
So to make the QR code all you do, it's quite simple.
Once you create this object, when you define the parameters here, you just add data.
This is the string data we want to put up in the fog.
We just added QR added to cure or make rapid 50 go through.
And then we just make the image here as well.
And then we save the images using pill collaborative model image processing library, which is similar
to open TV, but not as in-depth, but it has some quite some very useful functions in pill.
So it's a good library to use, and this is how we just read, then displayed a QR code at the end here.
So let's run this quite quick generate.
And you can see this is of a QR code we generated here.
So that's it for generating QR codes.
What about decoding them, though?
So to decode Akira, could this just decoded what we we included before?
It gives us the output here, which is openness.
In order to do that, you just open the image.
You use the decoded function from Bob Paisley, Boss Lab.
We know we're going to use to read or decode our QR codes.
And it's quite simple in this how the results you are created a result to specifying what type of data
you want to decode, which is UTF eight.
And it just gives us the outputs.
It's quite simple to use.
Now let's test this decoder on a different image, an image that is a real image like this.
So and you see, we have a robust function here, robust bit of good.
That's because of what we're doing with this code is that we're plotting the bounding box that we extract
from the decode function.
So they could call it backwards, but it's really the QR codes of achieving the change of codes.
Sure.
So we look over codes here.
We see it's live music for no good excuse not to function.
Get two rectangles.
Print the there are tango bounding box polygon here just for information.
That's what this is here, so we can take a look at it.
Then we draw the bounding box here using the open TV poly lines function, and then we just extract
the text, which you've seen before.
Get the text type so we can actually format it properly in the image because we need to do that for
open TV to put the text in the string of the text as a string into the image, and then we just generate
the file image.
In the end, looks barcode data isn't defined.
Let's take a look and see what that is.
That should be ball context here.
And Barbara Typekit, so let's run this function again.
Get the output.
There we go.
So you can see we drew a bounding box exactly because around the image, because if you were to use
their normal bounding box, we would have to use it would just be a box to us.
We have been completely in gaps that are good.
So by using lines, we actually get the lines, the exact angle that lines, that includes the QR code.
We put the website.
So it's is written.
I suppose that's an image QR code image.
I found the Google images that I'm using here.
And this tells us where the QR code is, obviously.
So let's take a look at reading barcodes now.
So let's load a barcode image here and now.
Let's use the same possible function to almost the exact same court here, except slightly different
to read the barcode and plot the barcode data.
So again, I have the data
don't have the TypeScript and variable names correct?
So let's take a look at the output now, and you can see Ta DA said, read, read this barcode, you
didn't read this barcode here.
Maybe we can inspected food to see why.
Actually, no, it's the same different barcode twice.
So this is the output right here.
So that's pretty cool.
So you can see now we can read barcodes in real life images as well as your codes.
So that's it for this lesson will now move on to YOLO, which is an object detector state of the art
object detector.
We're going to look at using the Eurovision treat this Eurovision five now Eurovision five and your
vision for almost the same.
Since it's a visionary, it's still quite good, and we can use a pre-trained model directly in open
TV, and it's quite effective, quite fast and quite easy to use.
So stay tuned for that lesson.
Thank you.