How could I implement my own warpPerspective function?

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

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());<float>(0) = j;<float>(1) = i;<float>(2) = 1;

        cv::Mat tempMatrix = homography * A;

        float x =<float>(0)/<float>(2);
        float y =<float>(1)/<float>(2);<uchar>(i, j) =<uchar>(floor(y), floor(x));
edit retag flag offensive close merge delete