Halcon & C# 機器視覺學習日記二
導出Halcon算法
先安利一個虛擬攝像頭軟件 VCam,VCam軟件可以讓攝像直接採集一個視頻,爲以後的圖像處理學習提供很好的幫助。
VCam軟件界面
算法功能 :打開攝像頭,實時採集並顯示
- 使用Halcon軟件
a. 使用助手新建一個Image Acquisition
b. 檢測當前的設備
c. 連接設備
d. 實時採集圖像
e. 播放視頻查看是否成功
f. 插入代碼
g. 導出代碼,注意選擇你需要的版本`
導出的文件
//
// File generated by HDevelop for HALCON/.NET (C#) Version 19.05.0.0
// Non-ASCII strings in this file are encoded in local-8-bit encoding (cp936).
//
// Please note that non-ASCII characters in string constants are exported
// as octal codes in order to guarantee that the strings are correctly
// created on all systems, independent on any compiler settings.
//
// Source files with different encoding should not be mixed in one project.
//
using HalconDotNet;
public partial class HDevelopExport
{
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public HDevelopExport()
{
// Default settings used in HDevelop
HOperatorSet.SetSystem("width", 512);
HOperatorSet.SetSystem("height", 512);
if (HalconAPI.isWindows)
HOperatorSet.SetSystem("use_window_thread","true");
action();
}
#endif
#if !NO_EXPORT_MAIN
// 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 02: Code generated by Image Acquisition 02
hv_AcqHandle.Dispose();
HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb",
-1, "false", "default", "[0] e2eSoft VCam", 0, -1, out hv_AcqHandle);
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
while ((int)(1) != 0)
{
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
//Image Acquisition 02: Do something
}
HOperatorSet.CloseFramegrabber(hv_AcqHandle);
ho_Image.Dispose();
hv_AcqHandle.Dispose();
}
#endif
}
#if !(NO_EXPORT_MAIN || NO_EXPORT_APP_MAIN)
public class HDevelopExportApp
{
static void Main(string[] args)
{
new HDevelopExport();
}
}
#endif
這樣你剛剛用Halcon實現的功能就導出來,將這個文件添加到你的C#工程中就可以輕鬆實現打開攝像頭,並且實時採集了。