我正在使用cv :: cuda :: Convolution编写高斯卷积函数,并使用不同的参数调用该函数以获得不同的卷积结果以用于其他处理。但是,使用第一个参数的结果,我在三次调用中都得到了相同的结果。
以下是高斯函数。
void Gauss_conv(const cv::cuda::GpuMat& src,
cv::cuda::GpuMat& conv,
int gauss_size,
bool convert_to_8bit = true)
{
cv::Mat gauss_kernel;
cv::cuda::GpuMat gf_src, gf_gauss, gf_conv;
std::vector <cv::cuda::GpuMat> gfv_src, gfv_gauss, gfv_conv;
src.convertTo(gf_src, CV_32FC3);
//Split the source image on the GPU
cv::cuda::split(gf_src, gfv_conv);
cv::cuda::split(gf_src, gfv_src);
//Prepare the input image for Gauss filtering
cv::cuda::copyMakeBorder(gf_src, gf_gauss, 0.5 * gauss_size,
0.5 * gauss_size, 0.5 * gauss_size, 0.5 * gauss_size,
cv::BORDER_REPLICATE);
cv::cuda::split(gf_gauss, gfv_gauss);
//Create the Gauss kernel and upload it to the GPU
cv::Ptr < cv::cuda::Convolution> c1 = cv::cuda::createConvolution();
cv::mulTransposed(cv::getGaussianKernel(gauss_size, -1, CV_32FC1),
gauss_kernel, false);
gf_gauss.upload(gauss_kernel);
//Apply Gaussian blur to all channels independently, also compute subtraction image
for (int i = 0; i < src.channels(); i++)
{
c1->convolve(gfv_gauss[i], gf_gauss, gfv_conv[i], true);
}
cv::cuda::merge(gfv_conv, conv);
}
//in main function
cv::Mat srcFloat;
src.convertTo(srcFloat, CV_32FC3);
cv::cuda::GpuMat gpu_src_uchar(src);
cv::cuda::GpuMat gpu_src_float(srcFloat);
cv::cuda::GpuMat conv1, conv2, conv3;
Gauss_conv(gpu_src_uchar, conv1, 131, true); //131
Gauss_conv(gpu_src_uchar, conv2, 531, true); //531
Gauss_conv(gpu_src_uchar, conv3, 1631, true); //1631
我想在主函数中得到三个不同的卷积结果。但是我对主函数中的所有卷积得到了相同的结果(第一个卷积结果)。