OpenCV 标量和矩阵相乘
我试图找到使用 opencv 2.0 cv::Mat
类添加、减去标量值的最简单方法。
大多数现有函数仅允许矩阵-矩阵和矩阵-标量运算。
我正在寻找标量矩阵运算。
我目前正在通过创建具有相同标量值的临时矩阵并执行所需的算术运算来完成此操作。下面的例子..
Mat M(Size(100,100), CV_8U);
Mat temp = Mat::ones(100, 100, CV_8U)*255;
M = temp-M;
但我认为应该有更好/更简单的方法来做到这一点。
有什么建议吗?
I am trying to find the easiest way to add, subtract a scalar value with a opencv 2.0 cv::Mat
class.
Most of the existing function allows only matrix-matrix and matrix-scalar operations.
I am looking for a scalar-matrix operations.
I am doing it currently by creating a temporary matrix with the same scalar value and doing required arithmetic operation. Example below..
Mat M(Size(100,100), CV_8U); Mat temp = Mat::ones(100, 100, CV_8U)*255; M = temp-M;
But I think there should be better/easier ways to do it.
Any suggestions ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能从 int 或 double 初始化 Mat 表达式。解决方案是使用 cv::Scalar,即使对于单通道矩阵:
请参阅 http://docs.opencv.org/modules/core/doc/basic_structs.html#matrixexpressions 获取可能的 Mat 表达式的列表。
You cannot initialize a Mat expression from an int or double. The solution is to use cv::Scalar, even for single channel Matrices:
See http://docs.opencv.org/modules/core/doc/basic_structures.html#matrixexpressions for a list of possible Mat expressions.
也许这是 2.1 的一个功能,或者是 2.1 和当前主干版本之间的某个功能,但这对我来说效果很好:
通道来自:
所以,请确保只使用标量表达式,至少在 2.1/当前 SVN 分支中;如果您在 2.0 中尝试上述操作会发生什么?
Maybe this is a feature of 2.1 or somewhere between 2.1 and current trunk version, but this works fine for me:
channels is coming from:
So, sure just use a scalar expression, at least in 2.1 / current SVN branch; what happens if you try the above in 2.0 ?