为什么CV :: Cuda :: CV ::重新映射是错误的吗?

发布于 2025-02-12 08:27:57 字数 1508 浏览 0 评论 0原文

我使用cv :: cuda :: remap而不是cv :: remap利用CUDA加速度来加快视频不合格。该程序的两个版本均可正常运行,但是,虽然相机矩阵,失真系数,MAP1和MAP2来自cv :: initundististortrectifymap()都是相同的,但CPU的未呈现结果图像版本cv :: remap是正确的,如下:

但是CUDA版本cv :: cuda :: remap导致问题:

“

CPU版本的代码段如下:

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::Mat mat;
gpuMat.download(mat);
cv::remap(mat, mat, m_map1, m_map2, cv::INTER_LINEAR);
gpuMat.upload(mat);

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::cuda::remap(gpuMat, gpuMat, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

GPU版本 他们,dpframe是类型cudeviceptrm_map1m_map2是由cv :: initundististortortectifymap计算的/code>,m_gpumap1m_gpumap2是类型cv :: cuda :: gpumat通过上传m_map1m_map2获得。

cv :: remapcv :: cuda :: remap是相同的算法,为什么它们的结果不同?我尝试了两个版本的OpENCV 455和460,并且两种版本都不起作用。

我被困在这里,不知道该如何前进。任何建议都非常感谢。谢谢。

I use cv::cuda::remap instead of cv::remap to take advantage of CUDA acceleration to speed up video undistortion. Both versions of the program can run normally, but, while the camera matrix, distortion coefficients, map1 and map2 which come from cv::initUndistortRectifyMap() are all the same, the undistorted result image of the CPU version cv::remap is correct as follow:

enter image description here

but the CUDA version cv::cuda::remap results in a problem:

enter image description here

The code snippet for the CPU version is as follows:

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::Mat mat;
gpuMat.download(mat);
cv::remap(mat, mat, m_map1, m_map2, cv::INTER_LINEAR);
gpuMat.upload(mat);

GPU version:

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::cuda::remap(gpuMat, gpuMat, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

Among them, dpFrame is of type CUdeviceptr, m_map1 and m_map2 are calculated by cv::initUndistortRectifyMap, m_gpuMap1 and m_gpuMap2 are of type cv::cuda::GpuMat obtained by uploading m_map1 and m_map2 to GPU.

cv::remap and cv::cuda::remap are the same algorithm, why are their results different? I tried both versions of OpenCV 455 and 460, and neither works.

I'm stuck here and don't know how to go forward. Any suggestions are really appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2025-02-19 08:27:57

Okey,我还尝试了您的代码并获得了类似的结果。经过几次测试,我最终得到了正确的结果。

我的代码只需翻转重新映射的图像。这是您输入的代码结果:

代码

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::cuda::remap(gpuMat, gpuMat, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

输入

”在此处输入图像描述

输出

然后我只添加一个新的声明cv :: cuda :: gpumat,然后将其放入ressize函数的输出中。这是代码。

    cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
    cv::cuda::GpuMat gpuMat2;
    cv::cuda::remap(gpuMat, gpuMat2, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

    gpuMat2.download(mat);

新输出

“

我对为什么的问题没有明确的答案。由于我们处理GPU,因此最好定义不同类型的输入和输出ressize的输出。

Okey, I also tried your code and got the similar results. I ended up with getting a correct result after a few tests.

My code simply flips an image with remap. Here is your code result to my input:

Code

cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
cv::cuda::remap(gpuMat, gpuMat, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

Input

enter image description here

Output

enter image description here

Then I just add a new declaration of cv::cuda::GpuMat and put it to output of resize function. Here is the code.

    cv::cuda::GpuMat gpuMat(m_height, m_width, CV_8UC4, (void *)dpFrame);
    cv::cuda::GpuMat gpuMat2;
    cv::cuda::remap(gpuMat, gpuMat2, m_gpuMap1, m_gpuMap2, cv::INTER_LINEAR);

    gpuMat2.download(mat);

New Output

enter image description here

I dont have a clear answer to the question why. Since we deal with gpu, it seems better to define different types for input and output of resize

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文