How could I implement my own warpPerspective function?

asked 2020-05-23 06:46:35 -0600

I tried to implement my own warpPerspective and findHomography function. I did managed to get the homography matrix, and I know this because if I do warpPerspective on my matrix, everything works fine. But when I try to apply the perspective by my own, I got the original image multiplied or everything blank and I can't seem to realise what I do wrong. This is my code for warp perspective:

for(int i = 0; i < height; i++){
    for(int j = 0; j < width; j++){
        cv::Mat A = cv::Mat::zeros(3, 1, homography.type());
        A.at<float>(0) = j;
        A.at<float>(1) = i;
        A.at<float>(2) = 1;

        cv::Mat tempMatrix = homography * A;

        float x = tempMatrix.at<float>(0)/tempMatrix.at<float>(2);
        float y = tempMatrix.at<float>(1)/tempMatrix.at<float>(2);

        perspectiveTransformation.at<uchar>(i, j) = image.at<uchar>(floor(y), floor(x));
    }
}
edit retag flag offensive close merge delete