Home > Enterprise >  opencv reverse perspective transformation?
opencv reverse perspective transformation?

Time:10-28

I start with the following image:

Using opencv I rotate 45° about the Y axis to get the following:

enter image description here

enter image description here

If I tried a little harder I could get it not to be cropped in the foreground.

Now my question: does opencv have the tools to do the reverse transformation? Could I take the second image and produce the first? (Not concerned about blurred pixels.) Please suggest a method.

CodePudding user response:

Yes, its possible. After 45° rotation, there are some regions below and above are missing(not seen). You only can not get those parts back.

By using enter image description here

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <fstream>

int main()
{

    cv::Mat begin = cv::imread("/ur/img/dir/input.jpg");
    cv::Mat output;
    cv::Point2f Poly2[4] = {
                  cv::Point2f(31,9),
                  cv::Point2f(342,51),
                  cv::Point2f(28,571),
                  cv::Point2f(345,525),   //points I got from looking in paint.


    };

    cv::Point2f Points[4] = {
                  cv::Point2f(0,0),
                  cv::Point2f(432,0),
                  cv::Point2f(0,576),       //The picture I want to transform to.
                  cv::Point2f(432,576),

    };



    cv::Mat Matrix = cv::getPerspectiveTransform( Poly2,Points);

    cv::warpPerspective(begin, output, Matrix, cv::Size(432, 576));

    cv::imshow("Input", begin);
    cv::imshow("Output", output);


    cv::imwrite("/home/yns/Downloads/tt2.jpg",output);
    cv::waitKey(0);


    return 0;
}

CodePudding user response:

Yes.

You already made a homography matrix to produce this picture, right?

Just invert it (H.inv()) or pass the WARP_INVERSE_MAP flag.

No need for all that other stuff.

  • Related