概述
//转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;
}
最后
以上就是舒适自行车为你收集整理的用DirectShow调用摄像头采集图像并转化为halcon图像的全部内容,希望文章能够帮你解决用DirectShow调用摄像头采集图像并转化为halcon图像所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复