HALCON图像数据转BYTE图像数据,一般用与界面显示,只给出单通道的灰度图转换
unsigned char *buf=NULL;//定义全局图像缓存
int imgH,imgW;//定义全局图像缓存
////////////////////////////////////////////////////////////////////////////////////////////////
HObject ho_Image;
HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2;
HTuple hv_Pointer, hv_Type, hv_Height, hv_Width, hv_Exception;
HTuple hv_pathstring, hv_Min2, hv_Max2;
try
{
hv_pathstring = (HTuple)strPath;
ReadImage(&ho_Image, hv_pathstring);
GetImagePointer1(ho_Image, &hv_Pointer, &hv_Type, &hv_Width, &hv_Height);
//memset(&DrawImgRegionSet, 0, sizeof(struDrawImgRegionSet));
imgW = hv_Width;
imgH = hv_Height;
int w = imgW;
int h=imgH;
if(buf==NULL)
{
buf=new unsigned char[w*h*3];
}
unsigned char *pp = (unsigned char*)(long)hv_Pointer;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
int idx = j*w + i;
int idx1 = (h - j-1)*w+i;
buf[idx1 * 3] = pp[idx];
buf[idx1 * 3+1] = pp[ idx];
buf[idx1 * 3+2] = pp[idx];
}
}
//memcpy(&buf[0], pp, imgSize);
}
catch (HalconCpp::HException &HDevExpDefaultException)
{
HDevExpDefaultException.ToHTuple(&hv_Exception);
return false;
}
ho_Image.Clear();
以下是BYTE图像数据转到HALCON图像数据,一般由相机的SDK采集后转换处理
unsigned char *ppbuf;//全局变量,分配好空间
HObject ho_GetSetImg;
long Pointer;
Pointer = (long)ppbuf;
GenImage1(&ho_GetSetImg, "byte", (HTuple)hv_Width,
(HTuple)hv_Height, (HTuple)Pointer);
多个相机采集若是用台式机多网卡,一般采用千兆网卡,配置跟相机同一网段,分辨率高的也一般用传输速率高的网线。
若要笔记本调试多相机的程序,一般接千兆交换机还有交换机接进笔记本的数据网线千兆,低速率普通交换机或者普通网线在图像传输会有问题吧,还有初始化相机图像接口最好MAC来区分,因为HALCON先初始化哪个相机顺序不一定。