先安利一个虚拟摄像头软件 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#工程中就可以轻松实现打开摄像头,并且实时采集了。
