cuda_GpuMat.upload() error doesn't make sense

I’m trying to understand how to use streams with OpenCV and CUDA. I’m really stumped by this error.

My Code:

import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda

import numpy as np

gpu_frame = cv2.cuda_GpuMat((960, 960), cv2.CV_32FC1)
stream = cuda.Stream()

frame = np.random(960,960)
gpu_frame.upload(frame, stream)

Gives the error:

cv2.error: OpenCV(4.6.0-dev) :-1: error: (-5:Bad argument) in function 'upload'
> Overload resolution failed:
>  - cuda_GpuMat.upload() takes at most 1 argument (2 given)
>  - cuda_GpuMat.upload() takes at most 1 argument (2 given)
>  - cuda_GpuMat.upload() takes at most 1 argument (2 given)
>  - Expected Ptr<cv::cuda::Stream> for argument 'stream'
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'arr'
>  - Expected Ptr<cv::cuda::Stream> for argument 'stream'

The documentation says that cuda_GpuMat.upload() can take two arguments, array and stream. The error message says the same thing. Why am I getting the error?

I would guess it is because you are using a CUDA stream object created by pycuda not OpenCV. If I use a cuda stream created as:

stream = cv2.cuda.Stream()

I don’t have any issues.

1 Like

Yep, that was it. Thanks!