cv2.cuda.reprojectImageTo3D(dispcu,Q) error : (-5:Bad argument)

Passing disp as a GpuMat does not work for me and causes the following error, that I’m not sure how to interpret:

error: OpenCV(4.5.4) /home/massimo/Downloads/opencv-4.5.4/modules/core/src/matrix_wrap.cpp:111: error: (-213:The function/feature is not implemented) You should explicitly call download method for cuda::GpuMat object in function 'getMat_'

Is it really not implemented in Python?

I’m using OpenCV 4.5.4 and the following minimal working example to understand how to use cv2.cuda.reprojectImageTo3D():

import numpy as np
import cv2

np_disparity = np.random.randint(0, 64, (128, 128), dtype=np.int16)
cu_disparity = cv2.cuda_GpuMat(np_disparity)
np_q = np.random.randint(0, 100, (4, 4)).astype(np.float32)
cu_q = cv2.cuda_GpuMat(4, 4, cv2.CV_32F)
cu_q = cv2.cuda.createContinuous(4, 4, cv2.CV_32FC1, cu_q)
cu_q.upload(np_q)

cu_xyz = cv2.cuda.reprojectImageTo3D(cu_disparity, cu_q)

I even tried to make cu_q continuous according to the specifications in the source code of cv::cuda::reprojectImageTo3D():

CV_Assert( disp.type() == CV_8U || disp.type() == CV_16S || disp.type() == CV_32S || disp.type() == CV_32F );
CV_Assert( Q.type() == CV_32F && Q.rows == 4 && Q.cols == 4 && Q.isContinuous() );
CV_Assert( dst_cn == 3 || dst_cn == 4 );

And also tried to pass all combinations of cu/np versions of disparity and q, but everything ends up in an error, either -5:Bad argument or -213:The function/feature is not implemented.

Any help would be much appreciated.
Thanks in advance!

1 Like