halcon学习基础-图像基本操作
2012-12-16 17:19
357 查看
摘自网上
Hobject mImg;
Hlong mW=0,mH=0,mDataPtr;
read_image(&mImg, "C:/Documents and Settings/Administrator/桌面/kk2.BMP");//1、加载图片到mImg对像中
get_image_size(mImg,&mW,&mH);//2、获取图片的宽度、高度
gen_image_const(&mImg,"byte", mW, mH);//2.1设置图像的宽度、高度
get_image_pointer1(mImg,&mDataPtr,mType,&mW,&mH);//3、将图像数据指针指向ptr 、宽度、高度
//--------4.-Vc++-->Halcon-----------------------------------------------
unsigned char *Pointer;
Pointer = new unsigned char[mH * mW];
for (i=0; i<mH; i++)
{
for (j=0; j<mW; j++)
{
Pointer[i*mW+j] = j % 255;
}
}
gen_image1_extern(&mImg, "byte", (HTuple)mW, (HTuple)mH, (long)Pointer, NULL);//设置图片对象mImg的数据内容、宽度、高度
//-----5. Halcon-->VC++---------------------------------------------------
BYTE * lpByte;
BYTE * ImageG=NULL;
int bytewidth;
bytewidth = ((long) mW * 3 + 3 ) / 4 * 4 ;
ImageG = new BYTE[ bytewidth * (long) mH ];
lpByte = (BYTE *) mDataPtr; //注意结合图像像素存储的类型进行定义
for( j = (long)mH-1; j>=0; j--)
{
//(注意tuple中图像数据的存放和VC中的差别)
for( i = 0; i < (long)mW; i++)
{
* (ImageG + j * bytewidth + i * 3 + 0 ) = * lpByte ;
* (ImageG + j * bytewidth + i * 3 + 1 ) = * lpByte ;
* (ImageG + j * bytewidth + i * 3 + 2 ) = * lpByte ;
lpByte++;
}
}
//------------6-GDI 显示图片数据-------------------------------------
BITMAPINFO * RotateBmpInfo;
BYTE * bitBuffer;
bitBuffer = NULL;
bitBuffer = new BYTE[sizeof(BITMAPINFO)];
RotateBmpInfo = (BITMAPINFO *)bitBuffer;
RotateBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RotateBmpInfo->bmiHeader.biHeight = mH;
RotateBmpInfo->bmiHeader.biWidth = mW;
RotateBmpInfo->bmiHeader.biPlanes = 1;
RotateBmpInfo->bmiHeader.biBitCount = 24;
RotateBmpInfo->bmiHeader.biCompression = BI_RGB;
RotateBmpInfo->bmiHeader.biSizeImage = mH * bytewidth;
RotateBmpInfo->bmiHeader.biXPelsPerMeter= 0;
RotateBmpInfo->bmiHeader.biYPelsPerMeter= 0;
RotateBmpInfo->bmiHeader.biClrUsed = 0;
RotateBmpInfo->bmiHeader.biClrImportant = 0;
CWnd * m_pWnd ;
m_pWnd = AfxGetApp()->GetMainWnd();
CDC *pDC = m_pWnd->GetDC();
::StretchDIBits(
pDC->GetSafeHdc(),
10,
10,
mW, //显示窗口宽度
mH, //显示窗口高度
0,
0,
mW, //图像宽度
mH, //图像高度
ImageG,
RotateBmpInfo,
DIB_RGB_COLORS,
SRCCOPY);
m_pWnd->ReleaseDC(pDC);
delete [] ImageG ;
delete [] bitBuffer ;
//set_window_attr("border_width",0);
//Hlong lWWindowID,WindowHandle;
//lWWindowID = (Hlong)this->m_hWnd;
//set_check("~father");
//open_window(0,0,mW,mH,lWWindowID,"visible","",&WindowHandle);//close_window(WindowHandle);
//set_check("father");
//disp_obj(mImg,WindowHandle);//disp_image(mImg,WindowHandle);
//----------------7--图像点击事件-------------------------------------------
Hlong Row,Column,Button;
get_mbutton(WindowHandle,&Row,&Column,&Button);
switch(Button)
{
case 1:
::MessageBox(NULL,"Left button !","提示",0);
break;
case 2:
::MessageBox(NULL,"Left button !","提示",0);
break;
case 4:
::MessageBox(NULL,"Left button !","提示",0);
break;
}
Hobject mImg;
Hlong mW=0,mH=0,mDataPtr;
read_image(&mImg, "C:/Documents and Settings/Administrator/桌面/kk2.BMP");//1、加载图片到mImg对像中
get_image_size(mImg,&mW,&mH);//2、获取图片的宽度、高度
gen_image_const(&mImg,"byte", mW, mH);//2.1设置图像的宽度、高度
get_image_pointer1(mImg,&mDataPtr,mType,&mW,&mH);//3、将图像数据指针指向ptr 、宽度、高度
//--------4.-Vc++-->Halcon-----------------------------------------------
unsigned char *Pointer;
Pointer = new unsigned char[mH * mW];
for (i=0; i<mH; i++)
{
for (j=0; j<mW; j++)
{
Pointer[i*mW+j] = j % 255;
}
}
gen_image1_extern(&mImg, "byte", (HTuple)mW, (HTuple)mH, (long)Pointer, NULL);//设置图片对象mImg的数据内容、宽度、高度
//-----5. Halcon-->VC++---------------------------------------------------
BYTE * lpByte;
BYTE * ImageG=NULL;
int bytewidth;
bytewidth = ((long) mW * 3 + 3 ) / 4 * 4 ;
ImageG = new BYTE[ bytewidth * (long) mH ];
lpByte = (BYTE *) mDataPtr; //注意结合图像像素存储的类型进行定义
for( j = (long)mH-1; j>=0; j--)
{
//(注意tuple中图像数据的存放和VC中的差别)
for( i = 0; i < (long)mW; i++)
{
* (ImageG + j * bytewidth + i * 3 + 0 ) = * lpByte ;
* (ImageG + j * bytewidth + i * 3 + 1 ) = * lpByte ;
* (ImageG + j * bytewidth + i * 3 + 2 ) = * lpByte ;
lpByte++;
}
}
//------------6-GDI 显示图片数据-------------------------------------
BITMAPINFO * RotateBmpInfo;
BYTE * bitBuffer;
bitBuffer = NULL;
bitBuffer = new BYTE[sizeof(BITMAPINFO)];
RotateBmpInfo = (BITMAPINFO *)bitBuffer;
RotateBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
RotateBmpInfo->bmiHeader.biHeight = mH;
RotateBmpInfo->bmiHeader.biWidth = mW;
RotateBmpInfo->bmiHeader.biPlanes = 1;
RotateBmpInfo->bmiHeader.biBitCount = 24;
RotateBmpInfo->bmiHeader.biCompression = BI_RGB;
RotateBmpInfo->bmiHeader.biSizeImage = mH * bytewidth;
RotateBmpInfo->bmiHeader.biXPelsPerMeter= 0;
RotateBmpInfo->bmiHeader.biYPelsPerMeter= 0;
RotateBmpInfo->bmiHeader.biClrUsed = 0;
RotateBmpInfo->bmiHeader.biClrImportant = 0;
CWnd * m_pWnd ;
m_pWnd = AfxGetApp()->GetMainWnd();
CDC *pDC = m_pWnd->GetDC();
::StretchDIBits(
pDC->GetSafeHdc(),
10,
10,
mW, //显示窗口宽度
mH, //显示窗口高度
0,
0,
mW, //图像宽度
mH, //图像高度
ImageG,
RotateBmpInfo,
DIB_RGB_COLORS,
SRCCOPY);
m_pWnd->ReleaseDC(pDC);
delete [] ImageG ;
delete [] bitBuffer ;
//set_window_attr("border_width",0);
//Hlong lWWindowID,WindowHandle;
//lWWindowID = (Hlong)this->m_hWnd;
//set_check("~father");
//open_window(0,0,mW,mH,lWWindowID,"visible","",&WindowHandle);//close_window(WindowHandle);
//set_check("father");
//disp_obj(mImg,WindowHandle);//disp_image(mImg,WindowHandle);
//----------------7--图像点击事件-------------------------------------------
Hlong Row,Column,Button;
get_mbutton(WindowHandle,&Row,&Column,&Button);
switch(Button)
{
case 1:
::MessageBox(NULL,"Left button !","提示",0);
break;
case 2:
::MessageBox(NULL,"Left button !","提示",0);
break;
case 4:
::MessageBox(NULL,"Left button !","提示",0);
break;
}
相关文章推荐
- GitHub入门与实践学习笔记--github学习基础之关于git的基本操作
- opencv学习(二十八)之基本图像阈值操作threshold
- (大数据工程师学习路径)第一步 Linux 基础入门----目录结构及文件基本操作
- openCV Python 学习笔记(一)图像的基本操作
- MySQL的日志基础知识及基本操作学习教程
- Linux程序设计学习笔记----多线程编程基础概念与基本操作
- OpenCV 学习笔记 ----图像的基本操作(二)
- 数据库基础学习1——数据库和表的创建和基本操作
- 多线程之 NSOperation 与 NSOperationQueue 的基本操作 适合基础学习
- php基础系列:从用户登录处理程序学习mysql扩展基本操作
- OpenCV学习笔记6-图像的基础操作
- 【学习笔记】GDAL对图像的基本操作(未完成)
- opencv3学习笔记1--图像的基本操作
- opencv2学习- - - 图像的基本操作
- 【OpenCV学习笔记】1.2图像的基本操作
- canvas学习之图像的基本操作
- opencv入门学习第一章,对图像基本的操作(图像腐蚀、图像模糊、canny图像边缘检测)
- MATLAB图像处理基础知识学习总结(MATLAB操作命令)
- OpenCV2学习笔记(一) 图像的基本操作
- 【从零学习Python】PIL安装与基本图像操作