Repository: opencv
Issue: get unexpected results when using the cv::cuda::warpPerspective on Nvidia tx2
Labels: priority: low,category: gpu/cuda (contrib),incomplete

<!--
If you have a question rather than reporting a bug please go to http://answers.opencv.org where you get much faster responses.
If you need further assistance please read [How To Contribute](https://github.com/opencv/opencv/wiki/How_to_contribute).

Please:

* Read the documentation to test with the latest developer build.
* Check if other person has already created the same issue to avoid duplicates. You can comment on it if there already is an issue.
* Try to be as detailed as possible in your report.
* Report only one problem per created issue.


This is a template helping you to create an issue which can be processed as quickly as possible. This is the bug reporting section for the OpenCV library.
-->

##### System information (version)
<!-- Example
- OpenCV =>
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2015
-->

- OpenCV =>  3.4.1-dev
- Operating System / Platform => Linux tegra-ubuntu 4.4.38-tegra-leopard
- Compiler => g++5.4.0

##### Detailed description

I write a simple code to test , the results of perspective tranform from CPU and GPU are different. The gpu one is wrong.


```
#include <stdio.h>  
#include <string>
#include <opencv2/opencv.hpp>  
#include <opencv2/core.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudafilters.hpp>
#include <cuda_runtime.h>
#include <cuda_profiler_api.h>

using namespace cv;  
using namespace std;  
  
int main(int argc, char** argv)  
{  
  VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=1  ! video/x-raw, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink");
  //VideoCapture cap("fakesrc ! videoconvert ! appsink"); 
  if (!cap.isOpened())  
    {  
      cout << "Failed to open camera." << endl;  
      return -1;  
    }  
  
      Mat frame;  
  for(;;)  
    {  
      cap >> frame;  
    int width = 1080;
    int height = 1920;
//    cudaProfilerStart();    
    cv::cuda::GpuMat gpu_frame(frame);
    printf("GpuMat width: %d , height:%d\n", gpu_frame.cols, gpu_frame.rows);
    float w_ratio = 1.0 / 0.5;
    float h_ratio = 1.0 - 1.0 / 2;
    
    cv::Point2f src_p[4];
    cv::Point2f dst_p[4];

    src_p[0] = cv::Point2f(0.0f, 0.0f);
    src_p[1] = cv::Point2f(width-1.0, 0.0);
    src_p[2] = cv::Point2f(width*w_ratio, height*h_ratio);
    src_p[3] = cv::Point2f(width*(1-w_ratio), height*h_ratio);


    dst_p[0] = cv::Point2f(0.0f, 0.0f);
    dst_p[1] = cv::Point2f(width-1.0, 0.0);
    dst_p[2] = cv::Point2f(width*w_ratio, height*h_ratio);
    dst_p[3] = cv::Point2f(width*(1-w_ratio), height*h_ratio);

//    src_p[0] = cv::Point2f(height*h_ratio, width*w_ratio);
//    src_p[1] = cv::Point2f(0.0f, width);
//    src_p[2] = cv::Point2f(height*(1-h_ratio), width*w_ratio);
//    src_p[3] = cv::Point2f(height, width);
//
    dst_p[0] = cv::Point2f(0.0f, 0.0f);
    dst_p[1] = cv::Point2f(width-1, 0.0f);
    dst_p[2] = cv::Point2f(0.0f, height-1.0);
    dst_p[3] = cv::Point2f(width-1.0, height-1.0);
    cv::Mat trans_mat33 = cv::getPerspectiveTransform(src_p, dst_p);
//    cv::Mat trans_mat33(3, 3, CV_64F);
//    cv::cuda::GpuMat trans_mat33(3, 3, CV_64F);
//    cv::cuda::GpuMat dst_mat(1080, 1920, CV_8UC4);
//    for (int i=0;i<3;i++)
//        for (int j=0;j<3;j++)
//            trans_mat33.at<double>(i,j)=0.0;
//    std::cout << trans_mat33 << std::endl;

    //printf("%d\n", cv::Size(10, 20).width);
    printf("%s %s\n", argv[0], argv[1]);
    if (strcmp(argv[1],"1") == 0)
    {
    printf("GPU\n");
    cv::cuda::warpPerspective(gpu_frame, gpu_frame , trans_mat33, cv::Size(width, height));
    gpu_frame.download(frame);
    }
    else
    {
    printf("CPU\n");
     cv::warpPerspective(frame, frame, trans_mat33, cv::Size(width, height));
    }
 //   cudaProfilerStop();
    //cudaDeviceSynchronize();
      imshow("original", frame);  
      //waitKey(1);  
      if(waitKey(1) >= 0)  
      break;  
    }  
  return 0;  
  //cap.release();  
}

```

##### Steps to reproduce

`g++  cv_demo_gpu.cpp  `pkg-config --cflags --libs opencv` -lcudart -I/usr/local/cuda/targets/aarch64-linux/include -L/usr/local/cuda/targets/aarch64-linux/lib -o cv_gpu`