HObject,unsigned char的相互转换

本文详细介绍了如何在计算机视觉中进行HObject(图像对象)与unsignedchar*(图像字节数据)之间的转换。包括单通道图像和三通道图像的转换步骤,涉及到GenImage系列函数以及GetImagePointer函数的使用,对于图像处理和分析工作具有指导意义。
摘要由CSDN通过智能技术生成
**HObject,unsigned char的相互转换**

一、unsigned char*转HObject
unsigned char* pFrameBuf;
HObject ho_Image;

1)单通道图像转换
GenImage1(&ho_Image,“byte“ , Width,Height,(Hlong)pFrameBuf);
2)三通道图像转换
GenImageInterleaved(&ho_Image,(Hlong)pFrameBuf,“rgb”, Width,Height, 0,“byte”,0,0,0,0,-1,0);
注意参数3 “rgb”,此参数为图像数据的存储格式,根据实际情况调整比如一些图像存储格式为“bgr”,那第3个参数就改为“bgr”。
如果图像有3个图像通道指针:
unsigned char* strR;
unsigned char* strG;
unsigned char* strB;
GenImage3(&ho_Image,“byte”, Width,Height,(Hlong)strR,(Hlong)strG,(Hlong)strB);

一、HObject转unsigned char
1)单通道图像
GetImagePointer1(ho_Image,&Pointer, &Type,& Width, &Height)
pFrameBuf=(unsigned char* )Pointer[0].L();
2)3通道图像
3通道图像转为一个图像指针

void rgb3_to_uchar1(HObject ho_Image,unsigned char*  pFrameBuf)
 {
	  HObject  ho_ImageAffineTrans, ho_ImageRed, ho_ImageGreen,ho_ImageInterleaved;
	  HObject  ho_ImageBlue, ho_RegionGrid, ho_RegionMoved, ho_RegionClipped;
	  HTuple  hv_PointerRed, hv_PointerGreen, hv_PointerBlue;
	  HTuple  hv_Type, hv_Width, hv_Height, hv_HomMat2DIdentity;
	  HTuple  hv_HomMat2DScale;
	  HTuple  hv_Pointer, hv_TypeRGB;
	   GetImagePointer3(ho_Image, &hv_PointerRed, &hv_PointerGreen, &hv_PointerBlue, 
	    &hv_Type, &hv_Width, &hv_Height);
	  GenImageConst(&ho_ImageInterleaved, "byte", hv_Width*3, hv_Height);
	  HomMat2dIdentity(&hv_HomMat2DIdentity);
	  HomMat2dScale(hv_HomMat2DIdentity, 1, 3, 0, 0, &hv_HomMat2DScale);
	  AffineTransImageSize(ho_Image, &ho_ImageAffineTrans, hv_HomMat2DScale, "constant", 
	      hv_Width*3, hv_Height);
	  Decompose3(ho_ImageAffineTrans, &ho_ImageRed, &ho_ImageGreen, &ho_ImageBlue);
	  GenGridRegion(&ho_RegionGrid, 2*hv_Height, 3, "lines", hv_Width*3, hv_Height+1);
	  MoveRegion(ho_RegionGrid, &ho_RegionMoved, -1, 0);
	  ClipRegion(ho_RegionMoved, &ho_RegionClipped, 0, 0, hv_Height-1, (3*hv_Width)-1);
	  ReduceDomain(ho_ImageRed, ho_RegionClipped, &ho_ImageRed);
	  MoveRegion(ho_RegionGrid, &ho_RegionMoved, -1, 1);
	  ClipRegion(ho_RegionMoved, &ho_RegionClipped, 0, 0, hv_Height-1, (3*hv_Width)-1);
	  ReduceDomain(ho_ImageGreen, ho_RegionClipped, &ho_ImageGreen);
	  MoveRegion(ho_RegionGrid, &ho_RegionMoved, -1, 2);
	  ClipRegion(ho_RegionMoved, &ho_RegionClipped, 0, 0, hv_Height-1, (3*hv_Width)-1);
	  ReduceDomain(ho_ImageBlue, ho_RegionClipped, &ho_ImageBlue);
	  OverpaintGray(ho_ImageInterleaved, ho_ImageRed);
	  OverpaintGray(ho_ImageInterleaved, ho_ImageGreen);
	  OverpaintGray(ho_ImageInterleaved, ho_ImageBlue);
	  
	  GetImagePointer1(ho_ImageInterleaved, &hv_Pointer, &hv_TypeRGB, &hv_Width, &hv_Height);
	  //注意,此时ho_ImageInterleaved的宽度为实际图像宽度的3倍,所以在构造图像时使用的宽度和高度参数应该是hv_Width/3和hv_Height。
	  pFrameBuf=(unsigned char*)hv_Pointer[0].L();
}

3通道图像转为三个图像指针

GetImagePointer3(ho_Image, PointerRed, PointerGreen, PointerBlue, Type, Width, Height);
unsigned char* strR=(unsigned char* )PointerRed[0].L();
unsigned char* strG=(unsigned char* )PointerGreen[0].L();
unsigned char* strB=(unsigned char* )PointerBlue[0].L();

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值