[英]Efficient way to convert a String (representing HEX) to a byte array? Android
[英]OpenCV on Android: Efficient way to get a byte[] array from many mats
我有一个席子列表,我需要将它们转换为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
获得原始字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.