Cuda ORB GpuMat assertion failed

asked 2020-04-30 08:59:08 -0500

adept gravatar image

updated 2020-04-30 09:28:43 -0500

My Opncv python code running ok on CPU, now I would like use it with cuda acceleration. Being fairly new to Opencv and Cuda I would like to ask fro some help. I am using a Jetson Nano just like MicTie in this post. Trying to run the same code but getting an error when trying to detect the keypoints.

import cv2

MAX_FEATURES = 100
GOOD_MATCH_PERCENT = 0.15
# load images into numpy
npMat1 = cv2.imread("archive/apple.jpg")
npMat2 =cv2.imread("archive/apple.jpg")
# upload into Cuda
cuMat1 = cv2.cuda_GpuMat()
cuMat2 = cv2.cuda_GpuMat()
cuMat1.upload(npMat1)
cuMat2.upload(npMat2)
# convert to Gray
cuMat1g = cv2.cuda.cvtColor(cuMat1, cv2.COLOR_RGB2GRAY)
cuMat2g = cv2.cuda.cvtColor(cuMat2, cv2.COLOR_RGB2GRAY)

# ORB
corb = cv2.cuda_ORB.create(MAX_FEATURES)
_kps1, _descs1 = corb.detectAndComputeAsync(cuMat1g, None)
_kps2, _descs2 = corb.detectAndComputeAsync(cuMat2g, None)

The error I get is:

   _kps1, _descs1 = corb.detectAndComputeAsync(cuMat1g, None)
    cv2.error: OpenCV(4.2.0) /tmp/build_opencv/opencv/modules/core/src/cuda_gpu_mat.cpp:155: error: 
(-215:Assertion failed) 

0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'GpuMat'

I have not much of an idea what goes wrong, any idea what I do wrong in the code above?

Thanks

edit retag flag offensive close merge delete

Comments

Which version of OpenCV are you using? I would check that the python test code works on your system?

    npMat1 = self.get_sample("samples/data/right01.jpg")
    npMat2 = self.get_sample("samples/data/right02.jpg")

    cuMat1 = cv.cuda_GpuMat()
    cuMat2 = cv.cuda_GpuMat()
    cuMat1.upload(npMat1)
    cuMat2.upload(npMat2)

    cuMat1 = cv.cuda.cvtColor(cuMat1, cv.COLOR_RGB2GRAY)
    cuMat2 = cv.cuda.cvtColor(cuMat2, cv.COLOR_RGB2GRAY)

    orb = cv.cuda_ORB.create()
    _kps1, descs1 = orb.detectAndComputeAsync(cuMat1, None)
    _kps2, descs2 = orb.detectAndComputeAsync(cuMat2, None)
cudawarped gravatar imagecudawarped ( 2020-04-30 12:02:44 -0500 )edit

Remove self. is not defined.

supra56 gravatar imagesupra56 ( 2020-04-30 12:13:58 -0500 )edit

The code above is taken directly from the python tests which you can run with

python "<PATH_TO_OPENCV_CONTRIB>\modules\cudafeatures2d\misc\python\test\test_cudafeatures2d.py" --repo <PATH_TO_OPENCV>

Alternatively you can use the code above directly, the sample images are located in https://github.com/opencv/opencv/tree... you can therefore replace self.get_sample("samples/data/right01.jpg") with cv.imread("<PATH_TO_OPENCV>/samples/data/right01.jpg").

cudawarped gravatar imagecudawarped ( 2020-04-30 12:22:36 -0500 )edit

Thanks for the good questions and guidance. Both the test code and one I tried seems to run OK when used with the sample images (right01.jpg, right02.jpg), so I checked what the difference is between these and the ones I used. It is the size of the image. I tried to use 200x200 pix image. So I reduced the "nlevels" parameter from default value 8 to 7 and it then seems to run OK.

Now my question is: Why would the standard ORB detector work with the default values and cuda_ORB not?

adept gravatar imageadept ( 2020-04-30 16:58:43 -0500 )edit

While Researching on this issue I came across this bug report. It seems as if this problem was present for a while. Any recommendation on how to correct my code to overcome this problem?

adept gravatar imageadept ( 2020-05-01 05:32:52 -0500 )edit