據我所知cv::cuda::PtrStep
用於將GpuMat
數據直接傳遞給定製內核。我發現一個頻道訪問的例子here但是我的情況是2頻道墊(CV_32FC2
)。在這種情況下,我試圖實現複數絕對平方值,其中複數值編碼如下:實部是第一平面,虛部是給定的第二平面Mat
。GpuMat - 訪問定製內核中的2通道浮點數據
我想:
__global__ void testKernel(const cv::cuda::PtrStepSz<cv::Vec2f> input, cv::cuda::PtrStepf output)
{
int x = blockIdx.x * blockDim.x + threadIdx.x;
int y = blockIdx.y * blockDim.y + threadIdx.y;
if (x <= input.cols - 1 && y <= input.rows - 1 && y >= 0 && x >= 0)
{
float val_re = input(x, y)[0];
float val_im = input(x, y) [1];
output(x, y) = val_re * val_re + val_im * val_im;
}
}
但這會導致以下錯誤:
calling a __host__ function("cv::Vec<float, (int)2> ::operator []") from a __global__ function("gpuholo::testKernel") is not allowed
我明白了。 []
是__host__
限制功能,因爲它的cv::Vec2f
不是cv::cuda::Vec2f
(顯然不存在)。但我仍然很想訪問這些數據。
是否有其他機制訪問設備端的2通道數據,類似於Vec2f
?
我以爲解決辦法的分裂input
的形式導入兩款CV_32FC1
Mat
這麼內核看起來像:
__global__ void testKernel(const cv::cuda::PtrStepSzf re, const cv::cuda::PtrStepSzf im, cv::cuda::PtrStepf output)
但我不知道是否有一個「乾淨」的解決方案,Vec2f
像一個。
你可以用'float2',而不是'CV :: Vec2f'。另外'input(x,y)'應該是'input(y,x)',因爲第一個參數是行,第二個參數是列。 – dari