Ask Your Question
0

Opencv cuda python remap error cv.cuda.remap(raw, mapx, mapy, cv.INTER_CUBIC, borderMode=cv.COLOR_RGB2GRAY)

asked 2020-01-28 07:04:28 -0600

Imran B gravatar image

updated 2020-01-28 07:37:04 -0600

supra56 gravatar image

I have installed opencv '4.2.0 dev' ,an already built package from https://jamesbowley.co.uk/accelerate-... (https://jamesbowley.co.uk/downloads/)... trying to use cv2.cuda.remap but it's throwing error as below:

cv.cuda.remap(raw, mapx, mapy, cv.INTER_CUBIC, borderMode=cv.COLOR_RGB2GRAY)

TypeError: Expected Ptr<cv::umat> for argument 'src' my code:

import numpy

import cv2 as cv

import numpy as np

npTmp = np.random.random((1024, 1024)).astype(np.float32)

npMat1 = np.stack([npTmp,npTmp],axis=2)

raw= cv.cuda_GpuMat()

raw.upload(npMat1)

a=np.array()

mapx = numpy.ndarray(shape=(640, 480, 1),
                           dtype='float32')

mapy = numpy.ndarray(shape=(640, 480, 1),
                           dtype='float32')

cv.cuda.remap(raw,a, mapx, mapy, cv.INTER_CUBIC, borderMode=cv.COLOR_RGB2GRAY)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2020-01-28 08:35:42 -0600

updated 2020-01-28 08:36:33 -0600

I think you may have a typo, the function signature, help(cv.cuda.remap) shown below, is the same as the one in your question

remap(...)
    remap(src, xmap, ymap, interpolation[, dst[, borderMode[, borderValue[, stream]]]]) -> dst
    .   @brief Applies a generic geometrical transformation to an image.
    .   
    .   @Param src Source image.
    .   @Param dst Destination image with the size the same as xmap and the type the same as src .
    .   @Param xmap X values. Only CV_32FC1 type is supported.
    .   @Param ymap Y values. Only CV_32FC1 type is supported.
    .   @Param interpolation Interpolation method (see resize ). INTER_NEAREST , INTER_LINEAR and
    .   INTER_CUBIC are supported for now.
    .   @Param borderMode Pixel extrapolation method (see borderInterpolate ). BORDER_REFLECT101 ,
    .   BORDER_REPLICATE , BORDER_CONSTANT , BORDER_REFLECT and BORDER_WRAP are supported for now.
    .   @Param borderValue Value used in case of a constant border. By default, it is 0.
    .   @Param stream Stream for the asynchronous version.
    .   
    .   The function transforms the source image using the specified map:
    .   
    .   \f[\texttt{dst} (x,y) =  \texttt{src} (xmap(x,y), ymap(x,y))\f]
    .   
    .   Values of pixels with non-integer coordinates are computed using the bilinear interpolation.
    .   
    .   @sa remap

however in the full code sample you are passing a as the second parameter and an invalid borderMode cv.COLOR_RGB2GRAY==7?

cv.cuda.remap(raw,a, mapx, mapy, cv.INTER_CUBIC, borderMode=cv.COLOR_RGB2GRAY)
edit flag offensive delete link more

Comments

I am still getting the same error, any help will be appreciated.

TypeError: Expected Ptrcv::UMat for argument 'src'

Updated code

import numpy
import cv2 as cv
import numpy as np
image = cv.imread("Remap.png")
ooo = cv.UMat()
raw= cv.cuda_GpuMat()
raw.upload(image)
raw = cv.cuda.resize(raw, (1024,1024), interpolation = cv.INTER_AREA)
mapx = numpy.ndarray(shape=(1024, 1024, 1),
                           dtype='float32')

mapy = numpy.ndarray(shape=(1024, 1024, 1),
                           dtype='float32') 

x = cv.cuda.remap(src=raw, dst=out, xmap=mapx, ymap=mapy,interpolation=cv.INTER_LINEAR)
Imran B gravatar imageImran B ( 2020-01-29 00:30:40 -0600 )edit
1

All the array inputs to cv.cuda.remap should be GpuMat(), try the following toy initialization

sz = (1024,1024,3)
npMat = (np.random.random(sz)*255).astype(np.uint8)
cuMat = cv.cuda_GpuMat(npMat)
npMapX = np.random.rand(sz[0],sz[1]).astype('float32')
npMapY = np.random.rand(sz[0],sz[1]).astype('float32')

cuMapX = cv.cuda_GpuMat(npMapX)
cuMapY = cv.cuda_GpuMat(npMapY)

you should then be able to remap with either

cuDst = cv.cuda_GpuMat(cuMat.size(),cuMat.type())
cv.cuda.remap(cuMat,cuMapX,cuMapY,dst=cuDst,interpolation=cv.INTER_LINEAR)

or

cuDst = cv.cuda.remap(cuMat,cuMapX,cuMapY, interpolation=cv.INTER_LINEAR)

I can't comment on the accuracy, but if there is a problem it is likely to be caused by the underlying c++ function

cudawarped gravatar imagecudawarped ( 2020-01-29 04:11:12 -0600 )edit

Thanks for your help !! It's working

Imran B gravatar imageImran B ( 2020-01-29 07:38:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-28 07:04:28 -0600

Seen: 2,109 times

Last updated: Jan 28 '20