gpt4 book ai didi

java - Android 上的 OpenCV : Efficient way to get a byte[] array from many mats

转载 作者:太空宇宙 更新时间:2023-11-04 14:47:41 25 4
gpt4 key购买 nike

我有一个 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) 函数,以避免所有这些小补丁的分配。

最佳答案

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

关于java - Android 上的 OpenCV : Efficient way to get a byte[] array from many mats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24204744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com