Search code examples
c++imageopencvcoordinate-transformationskew

OpenCV: Skewing an Image based on Triangular Selection


I'm trying to use OpenCV 2.0 to take three points, which essentially make up a triangle, in an image. What I'm trying to do with these three points is use them as a reference for skewing. What I'm trying to achieve is best explained with the following image:

enter image description here

  Before                                             After

I am guaranteed to have my image in the format above, so I know that the only point that I need to actively pay attention to is the point at which the 90 degree angle is formed.

In short, I'm just trying to skew my image in relation to the position of the point at which the 90 degree angle is formed.

Is there any way that I can do this in OpenCV? (Preferably in C++)


Solution

  • Well, I have never work with such type of transformation but I can somehow help you.

    After some googling I found similar question to yours on StackOverflow:

    Skewing an image using Perspective Transforms

    Jacob has a great answer to that question. It seems that from all that types of transformations (rotation, shearing, translation and scaling) only shearing can help you (see image below):

    shearing image

    And the transformation matrix is next:

    enter image description here

    To do such type of transformation in OpenCV there's function cv::warpPerspective - so just try it.

    Hope it helps.