//转Halcon图像
HObject ImageDataPtr2HObject(CCameraDS& CameraDS, BYTE* imageDataPtr)
{
HObject image;
if (8 == CameraDS.GetBitCount()) //灰度图
{
//造一个灰度图
GenImage1(
&image,
"byte",
CameraDS.GetWidth(),
CameraDS.GetHeight(),
Hlong(imageDataPtr)
);
}
else
{
BYTE* RChannel = NULL, * GChannel = NULL, * BChannel = NULL;
int Width, Height;
Width = CameraDS.GetWidth();
Height = CameraDS.GetHeight();
RChannel = new BYTE[Width * Height];
GChannel = new BYTE[Width * Height];
BChannel = new BYTE[Width * Height];
//4字节对齐
int LineByte = (Width * CameraDS.GetBitCount() + 31) / 32 * 4;
for (int i = 0; i < Height; i++) //图像的高---行
{
for (int j = 0; j < Width; j++) //图像的宽---列
{
//图像效果上下左右镜像 顺序读取时
/*memcpy(BChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 0, 1);
memcpy(GChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 1, 1);
memcpy(RChannel + Width * i + j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/
//使上下翻转
memcpy(BChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 0, 1);
memcpy(GChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 1, 1);
memcpy(RChannel + Width * (Height - 1 - i) + j, imageDataPtr + LineByte * i + 3 * j + 2, 1);
//使左右翻转
/*memcpy(BChannel + Width * i + Width - 1 - j , imageDataPtr + LineByte * i + 3 * j + 0, 1);
memcpy(GChannel + Width * i + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 1, 1);
memcpy(RChannel + Width * i + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/
//使上下左右翻转
/*memcpy(BChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 0, 1);
memcpy(GChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 1, 1);
memcpy(RChannel + Width * (Height - 1 - i) + Width - 1 - j, imageDataPtr + LineByte * i + 3 * j + 2, 1);*/
//参考
/*memcpy(BChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 0, 1);
memcpy(GChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 1, 1);
memcpy(RChannel + Width * i + Width - j - 1, imageDataPtr + LineByte * (Height - 1 - i) + 3 * (Width - 1 - j) + 2, 1);*/
}
}
//创建3通道图像
GenImage3(
&image,
"byte",
Width,
Height,
Hlong(RChannel),
Hlong(GChannel),
Hlong(BChannel)
);
delete[] RChannel;
delete[] GChannel;
delete[] BChannel;
}
return image;
}