Adjust the rotation of car plate

asked 2013-10-26 14:14:11 -0500

stereomatching gravatar image

updated 2013-10-26 15:31:33 -0500

In the ch5 of "mastering openCV with practical computer vision projects", the author adjust the rotation of the plate as follow

void detectRegions::rotatedRect(cv::Mat const &input, cv::RotatedRect const &minRect)
{
    // rotated rectangle drawing
    cv::Point2f rect_points[4];
    minRect.points(rect_points);
    for( int j = 0; j != 4; ++j){
        cv::line( result, rect_points[j], rect_points[(j+1)%4], cv::Scalar(0, 0, 255), 1, 8 );
    }

    //Get rotation matrix
    float const aspect = static_cast<float>(minRect.size.width) / 
                         static_cast<float>(minRect.size.height);
    float const angle = aspect < 1 ? minRect.angle + 90 : minRect.angle;        

    cv::Mat const rotmat = cv::getRotationMatrix2D(minRect.center, angle, 1);

    //Create and rotate image
    cv::warpAffine(input, imgRotated, rotmat, input.size(), CV_INTER_CUBIC);    
}

The author use the height and width to determine the angle of the rotation matrix, but I don't know the reason behind of it.What I know is the consequence of how to make the car plate back to horizontal(-90)

  1. when width >= height(aspect >= 1), we need to apply clockwise rotation on the image
  2. when height < width(aspect < 1), we need to apply counter-clockwise rotation on the image

How could the width and the height of the car plate show us we should do clockwise rotation or counter-clockwise rotation?

edit retag flag offensive close merge delete