Android上的OpenCV:从许多垫子中获取byte []数组的有效方法

时间:2014-06-13 11:56:24

标签: java android opencv mat

我有一个垫子列表,我需要将它们转换为byte []数组。问题是这种产生的高开销。 arraycopy部分工作正常,所以不要担心。我的问题是,如果存在比这更好的方法:

  // These array comes allocated an filled with data
  byte[] patches; // Big array to store all patches
  int offsets[];  // Array with positions to copy

  for(int i = 0; i < matList.size(); i++) 
  {
        // Create a little array of mat size and get the data
        int size = matList.get(i).rows() * matList.get(i).cols();
        byte[] patch = new byte[size];      
        matList.get(i).get(0, 0, patch);
        // Copy this little array to the big array
        System.arraycopy(patch, 0, patches, offsets[i], patch.length);
  }

如果我没弄错,在Java中,我无法通过带有偏移的大补丁数组的引用传递给 mat.get(0,0,array)函数,以避免分配所有这些小补丁。

1 个答案:

答案 0 :(得分:0)

如果您的所有Mat具有相同的宽度,那么您可以尝试使用Core.vconcat方法将它们连接到单个Mat对象。然后,您将能够使用单个get获取原始字节。

相关问题