opencv c++ with cuda

I followed this https://github.com/JetsonHacksNano/buildOpenCV to build opencv 4.2 on jetson nano with CUDA support
Then I tried This code to capture from raspberry pi v2.1 camera

#include <opencv2/opencv.hpp>
#include <opencv2/core/cuda.hpp>
#include <algorithm>
#include <chrono>
#include <iostream>
using namespace std;
using namespace std::chrono;
std::string gstreamer_pipeline (int capture_width, int capture_height, int display_width, int display_height, int framerate, int flip_method) {
    return "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)" + std::to_string(capture_width) + ", height=(int)" +
           std::to_string(capture_height) + ", format=(string)NV12, framerate=(fraction)" + std::to_string(framerate) +
           "/1 ! nvvidconv flip-method=" + std::to_string(flip_method) + " ! video/x-raw, width=(int)" + std::to_string(display_width) + ", height=(int)" +
           std::to_string(display_height) + ", format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";
}

int main()
{
    int capture_width = 3264 ;
    int capture_height = 2464 ;
    int display_width = 3264 ;
    int display_height = 2464 ;
    int framerate = 30 ;
    int flip_method = 0 ;

    std::string pipeline = gstreamer_pipeline(capture_width,
	capture_height,
	display_width,
	display_height,
	framerate,
	flip_method);
    std::cout << "Using pipeline: \n\t" << pipeline << "\n";
    cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
    if(!cap.isOpened()) {
	std::cout<<"Failed to open camera."<<std::endl;
	return (-1);
    }
    cv::Size new_size(1080,720);//the dst image size,e.g.100x100
    cv::cuda::GpuMat dst;//dst imag
    cv::namedWindow("CSI Camera", cv::WINDOW_AUTOSIZE);
    cv::cuda::GpuMat img;

    std::cout << "Hit ESC to exit" << "\n" ;
    while(true)
    {
	auto start = high_resolution_clock::now(); 
    	if (!cap.read(img)) {
		std::cout<<"Capture read error"<<std::endl;
		break;
	}
        cv::resize(img,dst,new_s);//resize image
	cv::imshow("CSI Camera",dst);
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<milliseconds>(stop - start); 
    	float time = duration.count() / 1000.0;
	float fps = 1.0 / time; 
	cout << "FPS: "<<fps<< endl;
	int keycode = cv::waitKey(30) & 0xff ; 
        if (keycode == 27) break ;
    }

    cap.release();
    cv::destroyAllWindows() ;
    return 0;
}

Using GpuMat gives this error: “OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /home/nvidia/build_opencv/opencv/modules/core/include/opencv2/core/private.cuda.hpp, line 107
terminate called after throwing an instance of ‘cv::Exception’
what(): /home/nvidia/build_opencv/opencv/modules/core/include/opencv2/core/private.cuda.hpp:107: error: (-216) The library is compiled without CUDA support in function throw_no_cuda”
with cv::Mat every thing goes right but the frame rate is 18 FPS, I need Higher fps for my app
is there is any way to accelerate the capturing process using cuda ?

Hi,
There are samples of utilizing cv::gpuMat in gstreamer and tegra_multimedia_api:
https://devtalk.nvidia.com/default/topic/1066465/jetson-nano/nano-not-using-gpu-with-gstreamer-python-slow-fps-dropped-frames/post/5403975/#5403975
https://devtalk.nvidia.com/default/topic/1047563/jetson-tx2/libargus-eglstream-to-nvivafilter/post/5403210/#5403210
FYR.