如何在 openCv 中将常数双精度值与 GpuMat 相乘

How to multiply a constant double value with GpuMat in openCv?

本文关键字:双精度 GpuMat 相乘 常数 openCv      更新时间:2023-10-16

我正在使用带有VS 2010的OpenCv 2.4.6库。我在mypenCv上编译了O Cuda 4.2.9这个带有笔记本电脑的库,它工作正常。现在我想将 1.5 乘以 cv::GpuMat .那么如何在VS 2010中使用OpenCv 2.4.6来做到这一点呢?对于cv::Mat来说很容易。喜欢的例子

cv::Mat mat =cv::imread("readImg.tiff",CV_LOAD_IMAGE_GRAYSCALE);
cv::GpuMat gpuMat(mat);cv::Mat newMat=mat*(1+0.5);

现在我如何在OpenCv中使用cv::gpu::GpuMat gpuMat进行此数学运算?

您可以使用

convertTo方法:

cv::GpuMat gpuMat(mat);
gpuMat.convertTo(gpuMat, gpuMat.type(), 1.5); // gpuMat = 1.5 * gpuMat

您可以使用 NVIDIA Performance Primitives (NPP)

//You need to include npp.h
float c[] = {0.25, 0.5, 0.75};
NppiSize ns;
ns.height = src.rows;
ns.width = src.cols;
//for CV_32FC3
nppiMulC_32f_C3R(src.ptr<Npp32f>(), static_cast<int>(src.step), c, dst.ptr<Npp32f>(), static_cast<int>(dst.step), ns);
in file: modules/cudaarithm/

include/opencv2/cudaarithm.hpp

/** @brief Computes a matrix-matrix or matrix-scalar per-element product.
@param src1 First source matrix or scalar.
@param src2 Second source matrix or scalar.
@param dst Destination matrix that has the same size and number of channels as the input array(s).
The depth is defined by dtype or src1 depth.
@param scale Optional scale factor.
@param dtype Optional depth of the output array.
@param stream Stream for the asynchronous version.
@sa multiply
 */
CV_EXPORTS void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());

SRC1/SRC2可以是矩阵或标量,这意味着:

cv::

cuda::multiply(cv::Scalar(1.5), gpuMat, gpuMat);