600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > HObject unsigned char的相互转换

HObject unsigned char的相互转换

时间:2021-10-24 13:02:20

相关推荐

HObject unsigned char的相互转换

**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();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。