HObject转成Bitmap类型时,经测试转换速度非常慢,因此可以拐个弯,先转成Mat,再从Mat转成Bitmap。
上代码:
public static Mat HImageToMat(HObject hobj)
{
try
{
Mat pImage;
HTuple htChannels;
HTuple cType = null;
HTuple width, height;
width = height = 0;
htChannels = null;
HOperatorSet.CountChannels(hobj, out htChannels);
if (htChannels.Length == 0)
{
return null;
}
if (htChannels[0].I == 1)
{
HTuple ptr;
HOperatorSet.GetImagePointer1(hobj, out ptr, out cType, out width, out height);
pImage = new Mat(new OpenCvSharp.Size(width, height), MatType.CV_8UC1, new Scalar(0));
int Width = width;
unsafe

本文介绍了一种将HObject高效转换为Bitmap的方法,通过先转为Mat格式再进行转换,显著提高了转换速度。文章提供了详细的代码实现,包括如何根据不同通道数处理图像数据,以及使用CopyMemory函数加速内存拷贝。
最低0.47元/天 解锁文章
436

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



