1、添加Halcon控件,创建WPF项目
在VS2013中创建一个WPF工程,然后添加halcon的控件和工具包,参见:
HSmartWindowControl之安装篇 (Visual Studio 2013 & Halcon 18)
在WPF工程中添加好HSmartWindowControlWPF控件后,将其拖入主窗体即可。
2、生成摄像头实时显示的halcon代码
使用Image Acquisition 连接笔记本自带的摄像头,然后生成实时显示的代码即可:
* Image Acquisition 01: Code generated by Image Acquisition 01 open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'rgb', -1, 'false', 'default', '[0] Integrated Camera', 0, -1, AcqHandle) grab_image_start (AcqHandle, -1) while (true) grab_image_async (Image, AcqHandle, -1) * Image Acquisition 01: Do something endwhile
3、导出C#代码
这里主要关注action函数:
// Main procedure private void action() { // Local iconic variables HObject ho_Image=null; // Local control variables HTuple hv_AcqHandle = new HTuple(); // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); //Image Acquisition 01: Code generated by Image Acquisition 01 //Image Acquisition 01: Attention: The initialization may fail in case parameters need to //Image Acquisition 01: be set in a specific order (e.g., image resolution vs. offset). hv_AcqHandle.Dispose(); HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] Integrated Camera", 0, -1, out hv_AcqHandle); HOperatorSet.GrabImageStart(hv_AcqHandle, -