nppiRGBToHSV_8u_C3R_Ctx vs opencv COLOR_BGR2HSV

I made a demo to achieve rgb to hsv, through npp; Compared with opencv’s rgb to hsv, we found some differences in the data, but no reason was found. Could you give me technical support?

nvidia@localhost:~/xxw/df_gtest/df_src_test$ head -n 1 /etc/nv_tegra_release

R32 (release), REVISION: 4.3, GCID: 21589087, BOARD: t186ref, EABI: aarch64, DATE: Fri Jun 26 04:34:27 UTC 2020

nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 255 255 255
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[255 255 255 255 255 255 255 255 255 255 255 255 ]
opencv bgr2hsv[0 0 255 0 0 255 0 0 255 0 0 255 ]
npp rgb2hsv[0 0 255 0 0 255 0 0 255 0 0 255 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 255 255 0
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[0 255 255 0 255 255 0 255 255 0 255 255 ]
opencv bgr2hsv[90 255 255 90 255 255 90 255 255 90 255 255 ]
npp rgb2hsv[127 255 255 127 255 255 127 255 255 127 255 255 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 255 0 0
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[0 0 255 0 0 255 0 0 255 0 0 255 ]
opencv bgr2hsv[120 255 255 120 255 255 120 255 255 120 255 255 ]
npp rgb2hsv[170 255 255 170 255 255 170 255 255 170 255 255 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 0 255 255
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[255 255 0 255 255 0 255 255 0 255 255 0 ]
opencv bgr2hsv[30 255 255 30 255 255 30 255 255 30 255 255 ]
npp rgb2hsv[42 255 255 42 255 255 42 255 255 42 255 255 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 0 255 0
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[0 255 0 0 255 0 0 255 0 0 255 0 ]
opencv bgr2hsv[60 255 255 60 255 255 60 255 255 60 255 255 ]
npp rgb2hsv[85 255 255 85 255 255 85 255 255 85 255 255 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 200 200 200
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[200 200 200 200 200 200 200 200 200 200 200 200 ]
opencv bgr2hsv[0 0 200 0 0 200 0 0 200 0 0 200 ]
npp rgb2hsv[0 0 200 0 0 200 0 0 200 0 0 200 ]
loop over
nvidia@localhost:~/xxw/df_gtest/df_src_test$ ./test 100 100 100
init npp
init cuda src&dst,src cols:1920,rows:1080
memcpy src
rgb src[100 100 100 100 100 100 100 100 100 100 100 100 ]
opencv bgr2hsv[0 0 100 0 0 100 0 0 100 0 0 100 ]
npp rgb2hsv[0 0 100 0 0 100 0 0 100 0 0 100 ]
loop over

void rgb2hsv(hl_par *par)
{
NppStatus nppStatus=NPP_SUCCESS;
nppStatus = nppiRGBToHSV_8u_C3R_Ctx(par->psrc, par->src_step, par->pdst, par->dst_step, par->roi, par->nppctx);
if(nppStatus!=NPP_SUCCESS)
{
std::cout<<“nppiRGBToHSV_8u_C3R_Ctx failed”<<std::endl;
abort();
}
if(par->bCpu)
{
checkCudaErrors(cudaMemcpyAsync(par->dst.data, par->pdst, par->dst_size, cudaMemcpyDeviceToHost, par->nppctx.hStream));
checkCudaErrors(cudaStreamSynchronize(par->nppctx.hStream));
}
}

nvidia@localhost:~/xxw/df_gtest/df_src_test$ /usr/local/cuda-10.2/bin/nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_21:14:42_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

The algorithm principle look the same

Hi,

npp and OpenCV implement the algorithm in a different ways.
It’s possible to have some differences in values.

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.