public void MatToHObject(Mat imgMat, out HObject imgHOject)
{
int ImageWidth = imgMat.Width;
int ImageHeight = imgMat.Height;
int channel = imgMat.Channels();
long size = ImageWidth * ImageHeight * channel;
int col_byte_num = ImageWidth * channel;
byte[] rgbValues = new byte[size];
unsafe
{
for (int i = 0; i < ImageHeight; i++)
{
IntPtr c = imgMat.Ptr(i);
// 一行一行将mat 像素复制到byte[]
Marshal.Copy(c, rgbValues, i * col_byte_num, col_byte_num);
}
void* p;
IntPtr ptr;
fixed (byte* pc = rgbValues)
{
p = (void*)pc;
ptr = new IntPtr(p);
}
if (channel == 1)
{
HOperatorSet.GenImage1(out imgHOject, "byte", ImageWidth, ImageHeight, ptr);
}
else
{
HOperatorSet.GenImageInterleaved(out imgHOject, ptr, "bgr", ImageWidth, ImageHeight, 0, "byte", 0, 0, 0, 0, -1, 0);
}
}
}