public void MatToHObject(Mat imgMat, out HImage ho_outImg)
{
HObject ho_image = new HObject();
HOperatorSet.GenEmptyObj(out ho_image);
ho_image.Dispose();
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 ho_image,"byte", ImageWidth, ImageHeight, ptr);
}
else
{
HOperatorSet.GenImageInterleaved(out ho_image, ptr, "bgr", ImageWidth, ImageHeight, 0, "byte", 0, 0, 0, 0, -1, 0);
}
ho_outImg = new HImage(ho_image);
}
}
1967

被折叠的 条评论
为什么被折叠?



