OpenCV GPU invalid configuration argument in function 'call'

Hello everyone!

I have installed OpenCV 3.4.2 from sources with CUDA and Python bindings support on my TX2.
I am trying to learn how to use the GPU from OpenCV in C++ with some simple transformations on the live stream from the onboard camera.

Right now I was trying to resize a GpuMat and got an exception:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.2) /home/nvidia/src/opencv-3.4.2/modules/cudawarping/src/cuda/ error: (-217:Gpu API call) invalid configuration argument in function 'call'

Aborted (core dumped)

Process returned 134 (0x86)

Has anyone encountered this problem before?


Opencv resize has two ways for specifying resize factors.
First one is the cv::Size dsize, second one is the pair of factors fx and fy.
I’d suggest to use cv::Size only. Here is a sample of code doing capture with CSI onboard camera using gstreamer (you need an opencv build with gstreamer support).

#include <iostream>
#include <time.h>

#include <opencv2/opencv.hpp>
#include <opencv2/video.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/cudawarping.hpp>

static inline unsigned long int GetTimeNs()
	struct timespec curTime;
	timespec_get(&curTime, TIME_UTC);
	return  curTime.tv_sec * 1e9 + curTime.tv_nsec;

//#define USE_OPENGL 1

int main()
	//printf("%s\n", cv::getBuildInformation().c_str()); 
	//setenv("GST_DEBUG", "*:3", 0); 
	const char* gst = "nvcamerasrc  ! video/x-raw(memory:NVMM), format=I420, width=640, height=480, framerate=30/1 ! "
					  "nvvidconv    ! video/x-raw, format=BGRx, width=640, height=480, framerate=30/1 ! "
					  "videoconvert ! video/x-raw, format=BGR,  width=640, height=480, framerate=30/1 ! "
	cv::VideoCapture cap(gst);
   	if(!cap.isOpened()) {
		std::cout<<"Failed to open camera."<<std::endl;
		return (-1);

	cv::Mat frame_in, frame_out;
	cv::cuda::GpuMat g_frame_in, g_frame_out;
   	if (! {
		std::cout<<"Capture read error"<<std::endl;
		return (-2);

#ifndef USE_OPENGL
	cv::namedWindow("MyCamera", cv::WINDOW_AUTOSIZE);
   	cv::namedWindow("MyResizedCamera", cv::WINDOW_AUTOSIZE);
#else /* USE_OPENGL */
	cv::namedWindow("MyCamera", cv::WINDOW_AUTOSIZE | cv::WINDOW_OPENGL);
	cv::namedWindow("MyResizedCamera", cv::WINDOW_AUTOSIZE | cv::WINDOW_OPENGL);
#endif /* USE_OPENGL */

	unsigned long int endClk = GetTimeNs();
	unsigned long int startClk, imshowClk, waitKeyClk;
	unsigned int frameCount = 0;
	unsigned int lastPos = cap.get(cv::CAP_PROP_POS_MSEC);
	unsigned int newPos, interval;
	unsigned int prevTraceLen = 0;

   		if (! {
			std::cout<<"Capture read error"<<std::endl;
		else  {
			startClk = GetTimeNs();
			clock_t captureLen = startClk - endClk;

 			newPos = cap.get(cv::CAP_PROP_POS_MSEC);
			interval = newPos - lastPos;
			lastPos = newPos;

			// Start Host2Device copy + CUDA Process
			cv::Size newSize( g_frame_in.size().width / 2 , g_frame_in.size().height / 2 );
			cv::cuda::resize(g_frame_in, g_frame_out, newSize, 0, 0, cv::INTER_AREA);;
			// End CUDA Process + Device2Host Process

			imshowClk = GetTimeNs();
			clock_t processLen = imshowClk - startClk;

#ifndef USE_OPENGL
			cv::imshow("MyCamera", frame_in);
			cv::imshow("MyResizedCamera", frame_out);
#else /* USE_OPENGL */
			cv::imshow("MyCamera", g_frame_in);
			cv::imshow("MyResizedCamera", g_frame_out);
#endif /* USE_OPENGL */

			waitKeyClk = GetTimeNs();
			clock_t imshowLen = waitKeyClk - imshowClk;
			if (cv::waitKey(1) == 27) // If ESC key has been pressed then exit

			endClk = GetTimeNs();
			clock_t waitKeyLen = endClk - waitKeyClk;

			clock_t loopLen = endClk - startClk;
			printf("#%04d: pos_interval=%d, cap=%f, proc=%f, show=%f, waitKey=%f, loop=%f, prevTrace=%f\n",
				frameCount, interval, captureLen/1.e6, processLen/1.e6, imshowLen/1.e6, waitKeyLen/1.e6, 
				loopLen/1.e6, prevTraceLen/1e6);
			prevTraceLen = GetTimeNs() - endClk;
			endClk += prevTraceLen;


	return 0;