Ask Your Question
0

warpPerspective Transform Matrix type ?

asked 2016-05-20 02:37:39 -0600

navonn gravatar image

I am using opencv on C++. I am quite new at Opencv, and I think that my problem should be easy to solve ... thank you for your help. I don't understand what should be the data type of the transformation matrix in warpPerspective and how it works. I have a 3 x 3 matrix (of type Eigen::MatrixXf) H, and I manually build a cv::Mat H2 equal to H, so that I could execute that transformation on an image, as follows :

warpPerspective(src , newImg , H2 , Size (5*H1 , 5*W)  ) ;

As I have not succeeded to build H2 correctly, I do it and check it step by step, as follows :

Mat H2(3,3, CV_64F);
    for (int g=0;g<3;g++) for (int g1=0; g1<3; g1++) H2.at<float>(g,g1)=  float(H(g,g1)) ;

    cout <<endl<< "Matrix H2 (OpenCV) : "<<endl;
    cout<< H2<<endl;
    cout <<endl<< "Matrix H2 (OpenCV) Element by element: "<<endl;
    for (int t=0; t<3; t++)
    {
        for (int s=0; s<3; s++)
        {
            cout<<"Element "<<t<<" , "<<s<<endl;
            cout<< H2.at<Vec3f>(t,s)<<endl;
        }
        cout<<endl;
    }
    cout <<endl<< "Matrix H (Eigen) : "<<endl;
    cout << H<<endl;

But when I print I get in H2 something that seems to be a 3x3x3 tensor, with column 0 for H2 equal to H. As shown in the attached screenshot. C:\fakepath\Capture du 2016-05-20 09:31:51.png

Thank you for your help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-20 08:55:48 -0600

LBerger gravatar image

updated 2016-05-20 09:00:20 -0600

Mat H2(3,3, CV_64F); mean you have a matrix of double. Then you must use H2.at<double>(g,g1) (and not float)

If you want a matrix of float you must use Mat H2(3,3, CV_32F)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-20 02:37:39 -0600

Seen: 831 times

Last updated: May 20 '16