- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的 Android OpenCV 项目中有一个二维数组类型 Mat
,我需要按照与 MATLAB sortrows
函数相同的方式对数组进行排序。我发现 Core.sort()
函数采用 Sort_Every_Row
等标志。这似乎是我想要的,但是当我使用这种方法时,我得到的输出结果与我从 MATLAB 得到的结果不同。
是否有任何其他功能或任何其他方法可以进行这种排序?我必须从头开始编写方法吗?
下面是我用来对数组 FeatureMatirx 进行排序的行:
Core.sort(FeatureMatrix, FeatureMatrix, Core.SORT_EVERY_ROW);
编辑:让我用一个简单的例子来解释:
Mat test = new Mat(4,3, CvType.CV_64FC1);
test.put(0, 0, 1);
test.put(0, 1, 2);
test.put(0, 2, 3);
test.put(1, 0, 1);
test.put(1, 1, 1);
test.put(1, 2, 1);
test.put(2, 0, 2);
test.put(2, 1, 1);
test.put(2, 2, 3);
test.put(3, 0, 1);
test.put(3, 1, 2);
test.put(3, 2, 1);
Core.sort(test, test,Core.SORT_EVERY_ROW + Core.SORT_ASCENDING);
for (int k = 0; k < test.rows(); k++) {
Log.i("Test", test.get(k, 0)[0] + " " + test.get(k, 1)[0]+ " " +test.get(k, 2)[0]);
}
上面例子的结果是这样的:
03-05 21:32:01.893: I/Test(1323): 1.0 2.0 3.0
03-05 21:32:01.893: I/Test(1323): 1.0 1.0 1.0
03-05 21:32:01.893: I/Test(1323): 1.0 2.0 3.0
03-05 21:32:01.893: I/Test(1323): 1.0 1.0 2.0
但 matlab 中的排序结果如下:
1 1 1
1 2 1
1 2 3
2 1 3
最佳答案
来自documentation :
The function sort sorts each matrix row or each matrix column in ascending or descending order. So you should pass two operation flags to get desired behaviour.
因此,您还需要传递一个排序顺序标志。由于 MATLAB 的 sortrows
按升序排序,传递适当的标志:
Core.sort(FeatureMatrix, FeatureMatrix, Core.SORT_EVERY_ROW + Core.SORT_ASCENDING);
关于android - Opencv 函数等于 matlab sortrows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207679/
我如何为某些排序列使用自定义(即非标准)排序顺序对表的行进行排序? 例如,下面的显示显示了 sortrows 的输出,具有所有排序列的标准排序顺序: >> sortrows(A, {'TrafficL
我的 Android OpenCV 项目中有一个二维数组类型 Mat,我需要按照与 MATLAB sortrows 函数相同的方式对数组进行排序。我发现 Core.sort() 函数采用 Sort_E
我有数据(数字 M x N,n > 2)到达时按第一列排序,然后按第二列排序。有谁知道一种有效的算法可以将数据转换为按第二列然后是第一列排序?显然,sortrows(data,[2,1]) 可以解决问
我是一名优秀的程序员,十分优秀!