一、相机采图
1、查询设备信息
HTuple Information, Values;
info_framegrabber("GigEVision", "device", &Information, &Values);
Information用来获取相机信息
Values用来获取相机名称
2、打开相机
HTuple m_hFrameGrabber; //相机句柄
open_framegrabber("GigEVision",0,0,0,0,0,0,"progressive",-1,"default",
-1,"false","default",Values[0],0,-1,&m_hFrameGrabber);
打开第二个相机
open_framegrabber("GigEVision",0,0,0,0,0,0,"progressive",-1,"default",
-1,"false","default",Values[1],0,-1,&m_hFrameGrabber);
注意相机名的调用方法。
3、获取相机参数
HTuple m_ImageWidth;get_framegrabber_param(m_hFrameGrabber,"m_ImageWidth",&m_ImageWidth);
4、单帧抓取
Hobject * pImage; //图片指针
grab_image(pImage,m_hFrameGrabber);
由于grab_image函数不能中断执行,因此在多线程中调用时,需要注意对它的原子保护。
5、关闭相机
close_framegrabber(m_hFrameGrabber);
二、图像显示
1、抓取单帧图像
m_Camera.SingleGrab(GetImage());
2、显示图片
CHalconBase::uShowImageOrSize(GetMyHalconWnd(),GetImage());
注:
1)获取显示窗口句柄GetMyHalconWnd()
2)获取图片指针GetImage()
3)显示函数原型
void CHalconBase::uShowImageOrSize(HTuple* WindowsHandle,Hobject* obj)
{
if(NULL == WindowsHandle || NULL ==obj)return;
else
{
if((long*)1 == obj->Id())return;
Hlong Width,Height;
get_image_size(*obj,&Width,&Height);
set_part(*WindowHandle,0,0,Height-1,Width-1);
disp_obj(*obj,*WindowsHandle);
}
}