OpenCV warpperspective

后端 未结 9 2340
孤城傲影
孤城傲影 2020-12-01 05:45

For some reason whenever I use OpenCV\'s warpPerspective() function, the final warped image does not contain everything in the original image. The left part of the image see

9条回答
  •  天命终不由人
    2020-12-01 06:05

    this is my solution

    since third parameter in "warpPerspective()" is a transformation matrix,

    we can make a transformation matrix , which moves the image backward first ,then rotates the image,finally moves the image forward .

    In my case,I have a image with height of 160 px and width of 160 px. I want to rotate the image around [80,80] instead of around [0,0]

    first,moves the image backward (that means T1)

    then rotates the image (that means R)

    finally moves the image forward (that means T2)

    void rotateImage(Mat &src_img,int degree)
    {
    float radian=(degree/180.0)*M_PI;
    Mat R(3,3,CV_32FC1,Scalar(0));
    R.at(0,0)=cos(radian);R.at(0,1)=-sin(radian);
    R.at(1,0)=sin(radian);R.at(1,1)=cos(radian);
    R.at(2,2)=1;
    Mat T1(3,3,CV_32FC1,Scalar(0));
    T1.at(0,2)=-80;
    T1.at(1,2)=-80;
    T1.at(0,0)=1;
    T1.at(1,1)=1;
    T1.at(2,2)=1;
    Mat T2(3,3,CV_32FC1,Scalar(0));
    T2.at(0,2)=80;
    T2.at(1,2)=80;
    T2.at(0,0)=1;
    T2.at(1,1)=1;
    T2.at(2,2)=1;
    
    std::cerr<

提交回复
热议问题