Let's take a step back and look at fine and none fine transforms again.
So imagine you have an image like this here where we have this is clearly not fine.
Transform off an original top down flat image here you can see the lines here.
They're not parallel anymore and they're actually going to join in some feature spot maybe some way
up here.
FLATOW So what it means is that if we have four points here we can actually use an open civic function
to actually watch this transfer this image here and get an image like this.
So clearly we can take a skewed image once we're aware of the four points of the corner and get back
to your original image.
So let's take a look at that implementing that in some code.
OK.
So let's look at implementing that perspective transform that we just saw.
So you remember we firstly need the coordinates of the four corners and the original image.
So that's what we actually have here.
These are the four points here.
We're basically combining it into points 3 here comprise of these four quadrants and then so it is that
these will be called points then we have points B which is do up which is output which is a point that
we let's go back to the image here.
These are the points that we want to define here.
So that's a typical for standard size.
We need to get the data so that it actually knows what to transform it to.
So what we do know we actually use these two points is two sets of points here with this open CV function
called Get perspective transform.
What this does it actually generates a matrix and this matrix here is is basically the transform that
basically transforms points to points B.
And then we use what perspective that function you may have seen previously to actually generate the
or to use this sort of matrix here and generate the output image to be called warped here.
And this is the final size of the image we want to see.
So as you can see it's actually lines up with this here.
These would have four coordinates of the output image that we wanted.
So let's run this good and voila we get the actual warped page here.
If you wanted to do something smarter you'd probably write an algorithm that gets to CONTO of this image
that automatically gets the locations of the corner points then feeds it in and then we run everything
automatically.
It's actually not too hard to build is actually a low some blogs online that actually do it for you.
So we've just seen how we generated Imitrex for none I transform.
But what about affine transform that should be simpler right.
And indeed it is you only need tree coordinates to actually generate the find transform.
So similarly we have points in B.
We are.
We actually use a different image here and there's a reason for that.
Also we use shortly.
So we have tree coordinates for points in b tree coordinates for Point B.
We use get affine transform as opposed to get perspective transform and we similarly implement those
transforms using Wolpoff when we just switched to see I would call them Andrews which is similar to
using the actual dimensions here.
We just take it directly from the image and let's run this code here.
So as you can see these are two
ships that we wish to transform.
So let's press any key and continue.
And this is the affine transform as you can see it as I find transform actually rotated the image slightly
didn't just scale anything but as you can see clearly all the lanes Montie and parallelism here.
So that's one of the main points of transforms.
So I hope you get a feel of using these functions here are actually quite handy and quite important
when doing more complicated stuff in open C-v.