1 | initial version |
The license plate in the image is not only rotated but also skewed.
The skewing transformation matrix has the following form
[ 1 sy 0 ]
[ sx 1 0 ]
In your case, sy=-0.3
, sx=0
(approximative value). You have to transform the rotated image with this matrix, or multiply the rotation and the skewing matrix and use warpAffine with the combined matrix.
To get a robust solution, I suggest to detect the four corners of the license plate and determine directly the affine transformation matrix using the findHomography function.
2 | No.2 Revision |
The license plate in the image is not only rotated but also skewed.
The skewing transformation matrix has the following form
[ 1 sy 0 ]
[ sx 1 0 ]
In your case, sy=-0.3
, sx=0
(approximative value). You have to transform the rotated image with this matrix, or multiply the rotation and the skewing matrix and use warpAffine with the combined matrix.
To get a robust solution, I suggest to detect the four corners of the license plate and determine directly the affine transformation matrix using the findHomography function.
[Update] The unskewing operation should be something like (untested code):
Mat skew_mat = Mat::eye(2,3,CV_64F);skew_mat.at<double>(0,1)=-0.3;skew_mat.at<double>(1,0)=0;
Mat skewed;
warpAffine(rotated, skewed, skew_mat, rotated.size());
For the second idea, there are a lots of tutorials on the web: e.g. this one: http://stackoverflow.com/questions/22519545/automatic-perspective-correction-opencv