Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting coordinates for perspective transform using mousecallback()

I tried the following code for perspective transform

#include "opencv2/opencv.hpp"   
using namespace cv;

int main() 
{
    Mat ocv = imread("tennis.jpg");

    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);

    Mat result;
    cv::warpPerspective(ocv, result, rot, Size(220,220));

    imshow("result",result);
    waitKey();
    return 0;
}

I tried to get the coordinates of the source object for transform with mousecallback() but i cant able to achieve it Please tell me the logic to get four co-ordinate points using mousecallback function?

Getting coordinates for perspective transform using mousecallback()

I tried the following code for perspective transform

 #include "opencv2/opencv.hpp"   
#include<iostream>

using namespace cv;
 using namespace std;

int ival(int x, int y);

void coordinate(int event, int x, int y, int flags, void* temp)
{
    int check;
     if  ( event == EVENT_LBUTTONDOWN && flags==EVENT_FLAG_CTRLKEY)
     {
         check=ival(x,y);
         if(check=0)
             return;
     }
}


vector<Point2f> P,Q;
int main() 
{
    Mat ocv = imread("tennis.jpg");

    vector<Point2f> P,Q;
    P.push_back(Point2f(163,101));
imread("E:\\Tennis.jpg");
    namedWindow("Input");
    imshow("input",ocv);
    setMouseCallback("Input", coordinate,NULL );


    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);

    Mat result;
    cv::warpPerspective(ocv, result, rot, Size(220,220));

    imshow("result",result);
    waitKey();
    return 0;
}

I tried to get the coordinates of the source object for transform with mousecallback() but i cant able to achieve it Please tell me the logic to get four co-ordinate points using mousecallback function?