Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

try with the c++ api, it's not very difficult:

Mat ocv = imread("tennis.jpg");
Mat image;
vector<Point2f> P,Q;
P.push_back(Point2f(163,101));
Q.push_back(Point2f(0,0));

P.push_back(Point2f(432,99));
Q.push_back(Point2f(200,0));

P.push_back(Point2f(563,395));
Q.push_back(Point2f(200,200));

P.push_back(Point2f(31,393));
Q.push_back(Point2f(0,200));

Mat rot = cv::getPerspectiveTransform(P,Q);
cerr << rot << endl;
Mat result;
cv::warpPerspective(ocv, result, rot, Size(220,220));
imshow("result",result);
waitKey();

try with the c++ api, it's not very difficult:

Mat ocv = imread("tennis.jpg");
Mat image;
vector<Point2f> P,Q;
P.push_back(Point2f(163,101));
Q.push_back(Point2f(0,0));
Q.push_back(Point2f(10,10));

P.push_back(Point2f(432,99));
Q.push_back(Point2f(200,0));
Q.push_back(Point2f(210,10));

P.push_back(Point2f(563,395));
Q.push_back(Point2f(200,200));
Q.push_back(Point2f(210,210));

P.push_back(Point2f(31,393));
Q.push_back(Point2f(0,200));
Q.push_back(Point2f(10,210));

Mat rot = cv::getPerspectiveTransform(P,Q);
cerr << rot << endl;
Mat result;
cv::warpPerspective(ocv, result, rot, Size(220,220));
imshow("result",result);
waitKey();

image description image description

try with the c++ api, it's not very difficult:

Mat ocv = imread("tennis.jpg");
Mat image;
vector<Point2f> P,Q;
P.push_back(Point2f(163,101));
Q.push_back(Point2f(10,10));
Q.push_back(Point2f(10,10)); // 10 pixel border on all sides

P.push_back(Point2f(432,99));
Q.push_back(Point2f(210,10));

P.push_back(Point2f(563,395));
Q.push_back(Point2f(210,210));

P.push_back(Point2f(31,393));
Q.push_back(Point2f(10,210));

Mat rot = cv::getPerspectiveTransform(P,Q);
cerr << rot << endl;
Mat result;
cv::warpPerspective(ocv, result, rot, Size(220,220));
imshow("result",result);
waitKey();

image description image description

try with the c++ api, it's not very difficult:

#include "opencv2/opencv.hpp"   
using namespace cv;
int main() {
    Mat ocv = imread("tennis.jpg");
 Mat image;
 vector<Point2f> P,Q;
 P.push_back(Point2f(163,101));
 Q.push_back(Point2f(10,10)); // 10 pixel border on all sides

 P.push_back(Point2f(432,99));
 Q.push_back(Point2f(210,10));

 P.push_back(Point2f(563,395));
 Q.push_back(Point2f(210,210));

 P.push_back(Point2f(31,393));
 Q.push_back(Point2f(10,210));

 Mat rot = cv::getPerspectiveTransform(P,Q);
 cerr << rot << endl;
 Mat result;
 cv::warpPerspective(ocv, result, rot, Size(220,220));
 imshow("result",result);
 waitKey();
    return 0;
}

image description image description

try with the c++ api, it's not very difficult:

#include "opencv2/opencv.hpp"   
using namespace cv;
 int main()  {
    Mat ocv = imread("tennis.jpg");
    Mat image;
     vector<Point2f> P,Q;
    P.push_back(Point2f(163,101));
    Q.push_back(Point2f(10,10)); // 10 pixel border on all sides

    P.push_back(Point2f(432,99));
    Q.push_back(Point2f(210,10));

    P.push_back(Point2f(563,395));
    Q.push_back(Point2f(210,210));

    P.push_back(Point2f(31,393));
    Q.push_back(Point2f(10,210));

    Mat rot = cv::getPerspectiveTransform(P,Q);
    cerr << rot << endl;
     Mat result;
    cv::warpPerspective(ocv, result, rot, Size(220,220));
     imshow("result",result);
    waitKey();
    return 0;
}

image description image description