VisionLabs/torch-opencv

would like to fix the bug of cuda::calcHist function in src/cudaimgproc.cpp

Closed this issue · 1 comments

The original code:

extern "C"
struct TensorWrapper calcHistCuda(
        struct cutorchInfo info, struct TensorWrapper src, struct TensorWrapper hist)
{
    cuda::GpuMat retval = hist.toGpuMat();
    cuda::calcHist(src.toGpuMat(), retval, prepareStream(info));
    return TensorWrapper(retval, info.state);
}

I would like to follow the previous method in this commit to fix the non-float tensor into CudaByteTensor, and I also find that in this cuda::calcHist function, there has a problem about retval, function will give a right result after converting retval type into CV_32F:

extern "C"
struct TensorWrapper calcHistCuda(struct cutorchInfo info, 
        struct TensorWrapper src, struct TensorWrapper hist)
{
    cuda::GpuMat retval = hist.toGpuMat();
    cuda::GpuMat retvalMat;
    cuda::GpuMat srcMat = src.toGpuMat();
    cuda::GpuMat srcByteMat;
    srcMat.convertTo(srcByteMat, CV_8U);
    cuda::calcHist(srcByteMat, retval, prepareStream(info));
    retval.convertTo(retvalMat, CV_32F);    
    return TensorWrapper(retvalMat, info.state);
}

So have any ideas about these?

Hey, that's good! Thank you very much for contributing!

I hope some day we'll finally solve #160 and won't face such problems anymore...