【问题标题】:Shuffle rows of image matrix using OpenCV使用 OpenCV 对图像矩阵的行进行洗牌
【发布时间】:2017-10-14 04:25:45
【问题描述】:

我有一个Mat 类型的"Features" 矩阵,有 20 行和 1 列,我在其中插入了值。

现在我想打乱矩阵的行。有什么方法可以洗牌或a guide on how to do this in Java吗?

int rows = 20;
int cols = 1;
int index = 0;
Mat Features = new Mat(rows, cols, CvType.CV_64F);

for (int i = 0; i < rows; i++) {
    if (i < 10)
        Features.put(i, 0, responseA[i]);
    if (i >= 10) {
        Features.put(i, 0, responseB[index]);
        index++;
    }
}

【问题讨论】:

    标签: java opencv opencv3.0


    【解决方案1】:

    不完全确定这是否可以编译,但我确实将 C++ 代码移植到了 Java。

    import org.opencv.core.Core; // randShuffle is located here.
    
    public static Mat shuffleRows(Mat matrix) {
        List<Integer> seeds = new ArrayList<Integer>();
        for (int cont = 0; cont < matrix.rows(); cont++) {
            seeds.add(cont);
        }
    
        Core.randShuffle(seeds);
    
        Mat output = new Mat();
        for (int cont = 0; cont < matrix.rows(); cont++) {
            output.push_back(matrix.row(seeds.get(cont)));
        }
        return output;
    }
    

    我相信您可以轻松调试它。我会尽快编译。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-28
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-02
      • 1970-01-01
      • 2015-12-02
      相关资源
      最近更新 更多