资源描述:
《c++与halcon》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、从Halcon到VC++read_image(&Image,"文件名");//读入的为灰度图像//获取图像指针,注意输出变量的类型charlpcsType[MAX_STRING];HlongPointer,Width,Height;get_image_pointer1(Image,&Pointer,lpcsType,&Width,&Height);//Halcon与VC++中的图像之间,存在着上下翻转BYTE*lpByte;BYTE*ImageG;intbytewidth;bytewidth=((long)Width*3+3)/4*4;ImageG=NULL;ImageG=newB
2、YTE[bytewidth*(long)Height];lpByte=(BYTE*)Pointer;//注意结合图像像素存储的类型进行定义inti,j;for(j=(long)Height-1;j>=0;j--){//(注意tuple中图像数据的存放和VC中的差别)for(i=0;i<(long)WidthGray;i++){*(ImageG+j*bytewidth+i*3+0)=*lpByte;*(ImageG+j*bytewidth+i*3+1)=*lpByte;*(ImageG+j*bytewidth+i*3+2)=*lpByte;lpByte++;}}BITMAPINFO*
3、RotateBmpInfo;BYTE*bitBuffer;bitBuffer=NULL;bitBuffer=newBYTE[sizeof(BITMAPINFO)];RotateBmpInfo=(BITMAPINFO*)bitBuffer;RotateBmpInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);RotateBmpInfo->bmiHeader.biHeight=Height;RotateBmpInfo->bmiHeader.biWidth=Width;RotateBmpInfo->bmiHeader.biPlanes=1;Ro
4、tateBmpInfo->bmiHeader.biBitCount=24;RotateBmpInfo->bmiHeader.biCompression=BI_RGB;RotateBmpInfo->bmiHeader.biSizeImage=Height*bytewidth;RotateBmpInfo->bmiHeader.biXPelsPerMeter=0;RotateBmpInfo->bmiHeader.biYPelsPerMeter=0;RotateBmpInfo->bmiHeader.biClrUsed=0;RotateBmpInfo->bmiHeader.biClrImpo
5、rtant=0;CWnd*m_pWnd;m_pWnd=AfxGetApp()->GetMainWnd();CDC*pDC=m_pWnd->GetDC();::StretchDIBits(pDC->GetSafeHdc(),Width+10,Height+10,Width,//显示窗口宽度Height,//显示窗口高度0,0,Width,//图像宽度Height,//图像高度ImageG,RotateBmpInfo,DIB_RGB_COLORS,SRCCOPY);m_pWnd->ReleaseDC(pDC);delete[]ImageG;delete[]bitBuffer;2.从VC
6、++到Halconunsignedchar*Pointer;intwidth,height;Pointer=newunsignedchar[width*height];inti,j;for(i=0;i7、必须为HTuple类型,Pointer指针为unsignedchar类型,输入时转换为long型。b)width,height必须与Pointer指向的图像数据的长宽一致。c)Pointer指针在gen_image1_extern函数调用之前分配了内存,之后不要马上释放,否则会出错。应该在确保不再使用Image变量之后再释放。halcon内部会自动释放Image,感觉没有释放Pointer(还需要进一步验证)。d)显示图像时,可能存在着图像的上下翻转,可以按照1中的方