gpt4 book ai didi

python-3.x - Opencv cuda python重新映射错误cv.cuda.remap(raw,mapx,mapy,cv.INTER_CUBIC,borderMode = cv.COLOR_RGB2GRAY)

转载 作者:行者123 更新时间:2023-12-02 16:28:12 27 4
gpt4 key购买 nike

我已经安装了opencv'4.2.0 dev',已经从https://jamesbowley.co.uk/accelerate-opencv-4-2-0-build-with-cuda-and-python-bindings/构建了一个软件包(https://jamesbowley.co.uk/downloads/).I'正在尝试使用cv2.cuda.remap,但是它抛出如下错误

cv.cuda.remap(raw, mapx, mapy, cv.INTER_CUBIC, borderMode=cv.COLOR_RGB2GRAY)
TypeError: Expected Ptr<cv::UMat> for argument 'src'

我的代码
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)

最佳答案

我得到了答案!!!

更新的代码:

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)

然后,您应该可以使用
cuDst = cv.cuda_GpuMat(cuMat.size(),cuMat.type())
cv.cuda.remap(cuMat,cuMapX,cuMapY,dst=cuDst,interpolation=cv.INTER_LINEAR)

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

关于python-3.x - Opencv cuda python重新映射错误cv.cuda.remap(raw,mapx,mapy,cv.INTER_CUBIC,borderMode = cv.COLOR_RGB2GRAY),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59948913/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com