Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Runnig cv::warpPerspective on points

Hi !

I'm running the cv::warpPerspective() function on a image and what to get the position of the some points of result image the I get in the source image, here how far I came :

 int main (){
    cv::Point2f srcQuad[4],dstQuad[4];
    cv::Mat warpMatrix;
    cv::Mat src, dst,src2;
    src = cv::imread("card.jpg",1);
            srcQuad[0].x = 0; //src Top left
    srcQuad[0].y = 0;
    srcQuad[1].x = src.cols - 1; //src Top right
    srcQuad[1].y = 0;
    srcQuad[2].x = 0; //src Bottom left
    srcQuad[2].y = src.rows - 1;
    srcQuad[3].x = src.cols -1; //src Bot right
    srcQuad[3].y = src.rows - 1;
    dstQuad[0].x = src.cols*0.05; //dst Top left
    dstQuad[0].y = src.rows*0.33;
    dstQuad[1].x = src.cols*0.9; //dst Top right
    dstQuad[1].y = src.rows*0.25;
    dstQuad[2].x = src.cols*0.2; //dst Bottom left
    dstQuad[2].y = src.rows*0.7;
    dstQuad[3].x = src.cols*0.8; //dst Bot right
    dstQuad[3].y = src.rows*0.9;

    warpMatrix =cv::getPerspectiveTransform(srcQuad,dstQuad);

    cv::warpPerspective(src,dst,warpMatrix,src.size());
    cv::imshow("source", src);
    cv::imshow("destination", dst);
    cv::warpPerspective(dst,src2,warpMatrix,dst.size(),CV_WARP_INVERSE_MAP);
    cv::imshow("srouce 2 " , src2);
    cv::waitKey();
    return 0;

my problem is that if I select a point from dst how can get its coordinates in * src or src2 * since the cv::warpPerspective function doesn't take cv::Point as parameter ??

Runnig cv::warpPerspective on points

Hi !

I'm running the cv::warpPerspective() function on a image and what to get the position of the some points of result image the I get in the source image, here how far I came :

 int main (){
    cv::Point2f srcQuad[4],dstQuad[4];
    cv::Mat warpMatrix;
    cv::Mat inverseMatrix;
    cv::Mat src, dst,src2;
    src = cv::imread("card.jpg",1);
        cv::imread("blue.jpg",1);
    srcQuad[0].x = 0; //src Top left
    srcQuad[0].y = 0;
    srcQuad[1].x = src.cols - 1; //src Top right
    srcQuad[1].y = 0;
    srcQuad[2].x = 0; //src Bottom left
    srcQuad[2].y = src.rows - 1;
    srcQuad[3].x = src.cols -1; //src Bot right
    srcQuad[3].y = src.rows - 1;
    dstQuad[0].x = src.cols*0.05; //dst Top left
    dstQuad[0].y = src.rows*0.33;
    dstQuad[1].x = src.cols*0.9; //dst Top right
    dstQuad[1].y = src.rows*0.25;
    dstQuad[2].x = src.cols*0.2; //dst Bottom left
    dstQuad[2].y = src.rows*0.7;
    dstQuad[3].x = src.cols*0.8; //dst Bot right
    dstQuad[3].y = src.rows*0.9;
    std::vector<cv::Point2f> mySrcPoints;
    cv::Mat mydst;

    mySrcPoints.push_back(cvPoint(5,10));
    mySrcPoints.push_back(cvPoint(50,20));     
    cv::rectangle(
            src,
            cv::Point(5,10),
            cv::Point(20,30),
            cv::Scalar(255,255,255)
       );        
    warpMatrix =cv::getPerspectiveTransform(srcQuad,dstQuad);
     cv::warpPerspective(cv::Mat(mySrcPoints),mydst,warpMatrix,src.size(),CV_WARP_INVERSE_MAP);
    for( int r = 0 ; r < mydst.rows ; ++r )
{
    for( int c = 0 ; c < mydst.cols ; ++c )
    {
        if(mydst.at< float >( r, c )!=0)
         std::cout << "Point at " << r << "," << c << " is wrap at " << mydst.at< float >( r, c ) << std::endl;
    }
}

    //cv::imshow("my dst ", mydst);
    //cv::Point x = converting(poi,warpMatrix);
    //std::cout <<"Converting for the first time  \n "<<x<< std::endl;
    cv::invert(warpMatrix,inverseMatrix);
    //cv::Point y = converting(poi,inverseMatrix);
    //std::cout <<"Converting for the second time  \n "<<y<< std::endl;
    cv::warpPerspective(src,dst,warpMatrix,src.size());
    cv::imshow("source", src);
    cv::imshow("destination", dst);
    cv::warpPerspective(dst,src2,warpMatrix,dst.size(),CV_WARP_INVERSE_MAP);
    cv::imshow("srouce 2 " , ", src2);
    cv::waitKey();
    return 0;

my problem is that if I select a point from dst how can get its coordinates in * src or src2 * since the cv::warpPerspective function doesn't take cv::Point as parameter ??