如何在 openCv 中将常数双精度值与 GpuMat 相乘
How to multiply a constant double value with GpuMat in openCv?
我正在使用带有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);
相关文章:
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 正在将csv文件读取为双精度矢量
- 我可以信任表示整数的浮点或双精度来保持精度吗
- 如何在C++中的同一函数中使用字符串和双精度
- 特征::矩阵<双精度,1,3> 结构类型函数中的返回类型函数
- 检查是否以特定精度给出双精度
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- C 字符串返回字符串的整数/双精度/长整型值
- 为什么将双精度转换为 int 似乎在第 16 位数字之后将其四舍五入?
- 如何使双精度值的 C++ 和 C# 中的结果相同
- 使用浮点数和双精度数的非常小数字的数学
- 使用 Xcode 将双精度存储在数组C++中
- 在 C++ 中将双精度变量写入二进制文件
- 如何从字符串转换为双精度*
- 为什么我的数组双精度函数不起作用?
- 高精度双精度的 Sprintf 格式化问题
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 将指针数组分配给双精度
- C++如何将字符串逐行转换为双精度
- 如何在 openCv 中将常数双精度值与 GpuMat 相乘