- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想对两个 opencv CV_32S 矩阵(A 和 B)执行逐元素除法。
当 B 不为 0 时,我希望 C = A/B,否则为 0。
但我不确定是否理解 opencv 文档:
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#divide
它说:
When src2(I) is zero, dst(I) will also be zero. Different channels of multi-channel arrays are processed independently.
Note Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.
saturate() 有什么作用?我可以安全地将 divide(A,B,C) 与 CV_32S 矩阵一起使用吗? divide() 与/运算符有何不同?
===== 测试后编辑 =====
我的测试表明/运算符完全符合我的要求:当 B != 0 时 C = A/B,否则为 0。
最佳答案
因此,operator/
和cv::divide
实际上应该是一样的,除了运算符将返回一个矩阵表达式,其计算被延迟。最后,operator/
也会调用 cv::divide
,如 e 所示。 G。对于一个简单的案例 here .特别是结果应该是相等的。
尽管如此,结果还是令人惊讶。使用两个整数矩阵进行除法,结果就像在浮点运算中完成的一样,后跟 round to nearest integer。更喜欢偶数(另见 nearbyint()
)。例如,使用两个 6x6 整数矩阵,您将得到
0/0 == 0 1/0 == 0 2/0 == 0 3/0 == 0 4/0 == 0 5/0 == 0
0/1 == 0 1/1 == 1 2/1 == 2 3/1 == 3 4/1 == 4 5/1 == 5
0/2 == 0 1/2 == 0 2/2 == 1 3/2 == 2 4/2 == 2 5/2 == 2
0/3 == 0 1/3 == 0 2/3 == 1 3/3 == 1 4/3 == 1 5/3 == 2
0/4 == 0 1/4 == 0 2/4 == 0 3/4 == 1 4/4 == 1 5/4 == 1
0/5 == 0 1/5 == 0 2/5 == 0 3/5 == 1 4/5 == 1 5/5 == 1
注意 (正如您在文档中所述),但也要注意 (四舍五入)和同时 (平分平局)。
注意:两个浮点类型矩阵没有定义任何特殊行为,而是在除以零的情况下计算为 -inf、nan 或 inf。当您除以两个浮点矩阵但请求整数结果时,这甚至成立。在这种情况下,-inf、nan 和 inf 将转换为最小值,这可能是一个错误(或者只是 OpenCV 未定义)。
整数除法代码div.cpp
(用g++ -std=c++11 div.cpp -o div -lopencv_core
编译):
#include <opencv2/opencv.hpp>
#include <iostream>
#include <cstdint>
int main() {
cv::Mat i1(6,6,CV_32S);
cv::Mat i2(6,6,CV_32S);
for (int y = 0; y < i1.rows; ++y) {
for (int x = 0; x < i1.cols; ++x) {
i1.at<int32_t>(y, x) = x;
i2.at<int32_t>(y, x) = y;
}
}
cv::Mat q;
cv::divide(i1, i2, q);
// q = i1 / i2;
for (int y = 0; y < q.rows; ++y) {
for (int x = 0; x < q.cols; ++x)
std::cout << x << "/" << y << " == " << q.at<int32_t>(y, x) << "\t";
std::cout << std::endl;
}
return 0;
}
关于c++ - 在opencv中划分两个矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20975420/
我在理解指针时遇到一些问题 我有矩阵,然后我使用它将其分成小块 tiles_num = n /tile; // Allocate blocked matrix Ah = (REAL **) mall
我有一个制表符分隔的文件,看起来像这样: foo 0 4 boo 3 2 blah 4 0 flah 1 1 我正在尝试计算每行两列之间的 log2。我的问题是除以零 我试过的是这样的: cat fi
在返回最终结果之前,我使用 BigDecimal 进行了几次计算。我的计算包含两个部分。我知道我应该在调用 divide() 时定义缩放和舍入模式。但是,由于我使用的是货币,所以我想尽可能长时间地保持
我正在尝试将两个数字 50 和 5 相除。这是我的代码: function Divide(Num1, Num2: Integer): Integer; asm MOV EAX, Num1
我对 R 和映射非常陌生,我想创建某些数据的映射。我有一组名为“D.Montreal”的数据,它显示了 2010 年访问蒙特利尔的加拿大人口普查部门的访客。我想使用这些数据创建一张 map ,以显示有
我需要制作一个条形图,将数据分为多个 bin。 我的数据如下所示: 1.0 5 1.2 4 2.4 1 4.3 6 5.2 10 然后在X轴上我想有时间的值,比如:[1-4)、[4-5)等(取决于cs
我正在尝试使用一个后台 worker ,它为字典中的每个键将内容保存到文件中。 ACon 是一个个人类,它在其中调用字典内容的保存函数。 private void bwSaver_DoWork(
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
我想将一些矩阵加载到我的程序中,然后我想将它分成更小的 block 。我想要的确切内容可以在下面的图片中看到: http://postimg.org/image/aki19hjx9/ba463111/
我有一个 anchor ,我将其注入(inject)到 jqGrid 格式化程序中的 HTML 中,如下所示: var number = rowObject.number; var plateNumb
我在传单标记上使用弹出窗口,并使用背景作为固定大小的图像。每当标记放置在 map 的一 Angular ,然后我单击标记以显示弹出窗口时,它会稍微移动整个 map 几分之一秒,然后弹出消息会超出 ma
我有一些代码,例如: good = [x for x in mylist if x in goodvals] bad = [x for x in mylist if x not in goodvals
我想将我的窗口 (wpf) 分成三列:左列必须是 DockPanel(我认为 StackPanel 在 Canvas), 右栏应该是另一个 DockPanel 包含一个 listbox 并且在中间我需
我有按国家/地区划分城市列表的代码: query('SELECT `city`, `country` FROM `cities` ORDER BY `id` ASC'); $cities->execu
我已经划分了我的Bootstrap网格列如下。 A B1 B1.1
我正在开发一个 asp.net 项目,但我还没有很长的 web.config 文件(超过 400 行)。但是有了这个 nhibernate log4net 和 urlrewrites。它越来越大。有没
我正在尝试使用 NSArrayController 和 cocoa 绑定(bind)创建分段的 NSTableView。我正在寻找类似的方法,例如 iOS 中的 NSFetchedResultsCon
早上好,下午好,还是晚上好, 在查看关闭“抑制 JIT 优化 (...)”选项的调试构建的汇编代码后,我注意到以下奇怪的行为(bitCount 是 ulong): int BitQ
我正在尝试根据 Firebase 数据库中的键对 Tableview 数据进行分段。 我能够根据键 (itemPreset) 正确划分所有内容。 我在将可重用单元分配到其部分时遇到问题。 单元格不断重
我最近升级到 Lodash 3.10.1我注意到了一些奇怪的事情。 假设我有一个数字数组,我想得到数组中的最大值然后减半: var series = [ 6, 8, 2 ]; var highestT
我是一名优秀的程序员,十分优秀!