【发布时间】:2021-01-12 09:54:12
【问题描述】:
我有一个 CCD 驱动程序,它返回 IntPtr 给我。我使用 Marshal.Copy 到字节数组(bytearray_Image),bytearray_Image 中的每个元素存储 8bit R/G/B 值,序列为 byte[0] = R 值,byte[1] = G 值,byte[2] = B价值……等等。我已使用以下代码 sn-p 成功转换为 3 Channels Mat:
var src = new Mat(rows: nHeight, cols: nWidth, type: MatType.CV_8UC3); var indexer = src.GetGenericIndexer();
int x = 0;
int y = 0;
for (int z = 0; z < (bytearray_Image.Length - 3); z += 3)
{
byte blue = bytearray_Image[(z + 2)];
byte green = bytearray_Image[(z + 1)];
byte red = bytearray_Image[(z + 0)];
Vec3b newValue = new Vec3b(blue, green, red);
indexer[y, x] = newValue;
x += 1;
if (x == nWidth)
{
x = 0;
y += 1;
}
}
由于图像非常大,这种方法转换图像似乎太慢了。有什么方法可以有效地进行这种转换吗?
【问题讨论】:
标签: c# opencvsharp