- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试用 C++ 创建此代码/我正在使用 openCV,但不必这样做。
wi = size(Gr, 2);
he = size(Gr, 1);
cropFactor = 0.10;
[x, y] = meshgrid( round(cropFactor * wi):round( (1-cropFactor)*wi ), round(cropFactor * he):round((1-cropFactor)*he) );
xy = sub2ind(size(Gr), y(:), x(:));
这是我目前的情况
int width = dst.cols;
int height = dst.rows;
double cropFactor = 0.10;
cv::Mat1i X,Y;
Utilities::Meshgrid(Utilities::MatlabRound(cropFactor * width), Utilities::MatlabRound((1 - cropFactor) * width), Utilities::MatlabRound(cropFactor * height), Utilities::MatlabRound((1-cropFactor) * height),X, Y);
Utilities::Sub2Ind(width, height, X, Y);
round() 函数
int Utilities::MatlabRound(double numberToRound)
{
return floor( numberToRound + 0.5);
}
这是我的 meshgrid() 函数,它按预期工作
void Utilities::Meshgrid(int startX, int endX, int startY, int endY, cv::Mat1i &X, cv::Mat1i & Y)
{
std::vector<int> vec_x, vec_y;
for (int i = startX; i <= endX; i++)
{
vec_x.push_back(i);
}
for (int i = startY; i <= endY; i++)
{
vec_y.push_back(i);
}
cv::Mat x = cv::Mat(vec_x);
cv::Mat y = cv::Mat(vec_y);
cv::repeat(x.reshape(1,1), y.total(), 1, X);
cv::repeat(y.reshape(1,1).t(), 1, x.total(), Y);
}
但是我无法理解什么是下标以及如何实现 Sub2Ind 函数
你能解释一下吗?
更新 我已经实现了 sub2ind 请看我的回答
最佳答案
我已经为二维矩阵实现了 sub2Ind它已经过测试并且工作正常
cv::Mat Utilities::Sub2Ind(int width, int height, cv::Mat X, cv::Mat Y)
{
/*sub2ind(size(a), rowsub, colsub)
sub2ind(size(a), 2 , 3 ) = 6
a = 1 2 3 ;
4 5 6
rowsub + colsub-1 * numberof rows in matrix*/
std::vector<int> index;
cv::transpose(Y,Y);
cv::MatConstIterator_<int> iterX = X.begin<int>(), it_endX = X.end<int>();
cv::MatConstIterator_<int> iterY = Y.begin<int>(), it_endY = Y.end<int>();
for (int j = 0; j < X.cols; ++j,++iterX)
{
//running on each col of y matrix
for (int i =0 ;i < Y.cols; ++i,++iterY )
{
int rowsub = *iterY;
int colsub = *iterX;
int res = rowsub + ((colsub-1)*height);
index.push_back(res);
}
int x = 5;
}
cv::Mat M(index) ;
return M;
}
关于c++ - sub2Ind matlab 到 c++/opencv 的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27881713/
函数返回一个包含float值的列表。如果我绘制此列表,我会发现一些 float 值等于 -1.#IND。我还检查了这些 -1.#IND 值的类型。它们也是float类型。但我如何理解这个 -1.#IN
这里很简单的问题:当我测试错误的数据输入时,我给出了一条错误消息,但是 -1.#IND 在它之后出现? 例如,我在应该是正数的地方输入了负数,结果出现“wrong input dummy-1.#IND
我正在尝试通过使用极坐标以及平均值和西格玛值生成两个标准正态变量 r1、r2 来生成随机变量。然而,当我运行我的代码时,我不断得到一个“-nan(ind)”作为我的输出。 我在这里做错了什么?代码如下
假设我正在评估 a/b,其中 a 和 b 都是浮点类型。 如果 b 为零,则答案为 -1.#IND。 是否有任何其他 b(和 a)值会给我 -1.#IND,或者正在检查非零 b 足以避免得到这个结果吗
我目前正在为二叉树编写 C++。整件事都写好了,但是,无论我想评估什么表达式,我都会让命令提示符告诉我 -1.#IND。关于解决此问题的任何想法,甚至这意味着什么? 提前致谢 代码: #include
我有一个 float 组,它存储一些由某些函数计算的值。但是,当我从数组中检索一个值时,有些值是 -1。#IND,这是一个浮点错误或我猜是某种错误。 所以这是我的小问题,我如何使用 if 语句来检查
我正在尝试获取which(..., arr.ind = TRUE)函数的结果,并删除不是第一个“彼此连接”的行。 示例: #example 1 example 2 example
我正在尝试将一个“大”因素转换为 R 中的一组指标(即虚拟、二进制、标志)变量: FLN <- data.frame(nnet::class.ind(FinelineNumber)) 其中 Finel
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在尝试编写一个 Scaler 类,该类采用具有分数的子测试。 Scaler 使用其子级分数类的缩放方法来重新缩放其值(例如 1/1 缩放 5 = 5/5 或 0/1 缩放 5 = 0/5)。 但是
我有一些代码可以让我绘制新月形状,并提取了要绘制的 excel 值。但是,代替某些数字的是 -1.#IND。首先,如果有人能解释这意味着什么,因为谷歌返回 0 个链接。其次,是否有办法阻止它发生。 我
我正在为 iPad 开发一个应用程序。该应用程序具有以下详细信息: 基础 SDK:4.2部署目标:3.2 该应用程序是一个游戏应用程序,有 10 轮。 在每一轮中,我加载 6 个 Controller
我已经提取了一些我想查看的元素的数组索引,如下所示: mat = matrix(0,10,10) arrInd = which(mat ==0,arr.ind = T) 然后我对该矩阵进行更多操作,最
我正在尝试插入一个 2D 角度,它在 99.9% 的时间内都有效。出于某种原因,我得到 -nan(ind) 某些值,例如: lastAngle = -0.0613451 currentAngle =
我喜欢使用 akeneo 中的自定义命令从数据库中获取一些产品。我正在使用 ProductRepositoryInterface public function read() { return
我对这个问题很困惑。我正在运行的代码是: double dotProduct = dot(A, B); std::cout ; } else if (value>=1.0) {
我有: double score = cvMatchContourTrees( CT1, CT2, CV_CONTOUR_TREES_MATCH_I1, 0.0 ); cout<
这是 VB.NET 中的一个奇怪的计算错误。我已将我的问题简化为以下内容。我可以写: Console.WriteLine(-0.78125 ^ 2.5) 并获得 -0.5394796609394436
问题的不相关理由 : 我在调用 Lua 时遇到错误 format : integer overflow attempting to store -1.#IND 变量的 type(n)真的是number
我已经尝试了检测奇数(NaN、QNaN 等)的所有常规技巧,但我似乎无法检测到 -1。#IND。任何帮助将不胜感激。 最佳答案 试试这个: http://www.johndcook.com/IEEE_
我是一名优秀的程序员,十分优秀!