简体   繁体   English

使用Nvidia NPP调整图像大小时出现未记录的调整大小错误

[英]Undocumented resize error when using Nvidia NPP to resize image

I'm attempting to use the Nvidia performance primatives library to resize an image, but the nppiResize_8u_C3R function is throwing a NPP_RESIZE_FACTOR_ERROR that is not listed in the documentation as one of the error return codes for that function. 我正在尝试使用Nvidia性能基元库来调整图像大小,但是nppiResize_8u_C3R函数抛出了NPP_RESIZE_FACTOR_ERROR ,该文档中未列出该函数的错误返回码之一。 Here is my hopefully simple code: 这是我希望简单的代码:

#include <iostream>
#include <nppi.h>

int image_a_pitch;
NppiSize image_a_size = {.width = 960, .height = 540};
NppiRect image_a_roi = {.x = 0, .y = 0, .width = 960, .height = 540};
Npp8u* image_a = nppiMalloc_8u_C3(960, 540, &image_a_pitch);

int image_b_pitch;
NppiSize image_b_size = {.width = 960, .height = 540};
NppiRect image_b_roi = {.x = 0, .y = 0, .width = 960, .height = 540};
Npp8u* image_b = nppiMalloc_8u_C3(960, 540, &image_b_pitch);

NppStatus result = nppiResize_8u_C3R(image_a, image_a_pitch, image_a_size, image_a_roi, image_b, image_b_pitch, image_b_size, image_b_roi, NPPI_INTER_SUPER);

if (result != NPP_SUCCESS) {
    std::cerr << "Error executing Resize -- code: " << result << std::endl;
}

You might note I'm not actually resizing the image, and yes, that is true, but I'm attempting to create the simplest case for this error. 您可能会注意到我实际上并没有调整图像的大小,是的,这是正确的,但是我正在尝试为该错误创建最简单的情况。 From what I've been testing, it doesn't seem to matter what sizes I use for the images, I still get the same return error code, which does not seem to be a valid error code for that function, but rather an error code for the depreciated nppiResizeSqrPixel_8u_C3R . 从我一直测试的结果来看,我使用的图像大小似乎并不重要,我仍然会得到相同的返回错误代码,这似乎不是该函数的有效错误代码,而是一个错误折旧的nppiResizeSqrPixel_8u_C3R代码。

I'd definitely appreciate some help pointing out whatever error I'm doing in setting up the library calls that is causing this error. 我非常感谢您提供一些帮助,指出我在设置引起此错误的库调用时遇到的任何错误。

Looking at the jpegNPP CUDA sample code, I observe this sequence: 查看jpegNPP CUDA示例代码,我观察到以下顺序:

    NppiInterpolationMode eInterploationMode = NPPI_INTER_SUPER;

    if (nScaleFactor >= 1.f)
        eInterploationMode = NPPI_INTER_LANCZOS;

    NPP_CHECK_NPP(nppiResize_8u_C1R(..., eInterploationMode));
}

When I switch your interpolation mode from NPPI_INTER_SUPER to NPPI_INTER_LANCZOS in your example, the error goes away for me (CUDA 9.1, linux). 在您的示例中,当我将插值模式从NPPI_INTER_SUPERNPPI_INTER_LANCZOS时,该错误对我来说消失了(CUDA 9.1,Linux)。 I suspect there is some undocumented (AFAICT) requirement in NPP library for this function, that the NPPI_INTER_SUPER interpolation mode not be used when the resize scale factor is 1.0 or greater (yours is 1.0, it is the ratio of the sourceROI/destROI). 我怀疑此功能在NPP库中有一些未记录的(AFAICT)要求,当调整大小比例因子为1.0或更大(您的值为1.0,它是sourceROI / destROI之比)时,不使用NPPI_INTER_SUPER插值模式。

I suggest you study the usage in that sample code, and put a similar mechanism in place in your code. 我建议您研究该示例代码中的用法,并在代码中采用类似的机制。

I've already put in a request to have the CUDA documentation updated with appropriate information. 我已经提出要求使用适当的信息更新CUDA文档。 I don't have any further details. 我没有更多细节。 You're welcome to file your own bug at http://developer.nvidia.com 欢迎您在http://developer.nvidia.com上提交您自己的错误。

update: I've confirmed with the CUDA team that a documentation update for this is planned in a future CUDA release. 更新:我已与CUDA团队确认,计划在将来的CUDA版本中对此文档进行更新。 In a nutshell, the requirement to use NPPI_INTER_SUPER is that you must be doing downscaling. 简而言之,使用NPPI_INTER_SUPER的要求是您必须进行缩减。 That is, the ratio of X source ROI dimension divided by the X destination ROI dimension must be greater than 1.0. 也就是说,X源ROI尺寸与X目标ROI尺寸之比必须大于1.0。 Likewise the ratio of the Y source ROI dimension divided by the Y destination ROI dimension must be greater than 1.0. 同样,Y源ROI尺寸与Y目标ROI尺寸之比必须大于1.0。 If either of these conditions are not met, the NPPI_INTER_SUPER interpolation mode cannot be used. 如果不满足这些条件之一,则无法使用NPPI_INTER_SUPER插值模式。 For example, the NPPI_INTER_LANCZOS mode can be used instead. 例如,可以改为使用NPPI_INTER_LANCZOS模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM