浅入浅出EmguCv(二)EmguCv打开指定图片

从这篇文章开始,会介绍一些通过EmguCv实现的一些简单的功能,这个内容的更新会跟我学习OpenCv的进度有关,最近在看一本关于OpenCv的书——《学习OpenCv》,主要例子还是通过这本书中的C++样例“翻译”为EmguCv版本,如果有更有效的“翻译方式”,也希望大牛们能给指出来。

1.C#创建一个窗体工程

在工程中的“解决方案资源管理器”中右键-添加引用,将EmguCv目录中的动态库加入。如下图所示:

2.在Form中添加一个Button和一个ImageBox

如果在工具箱中未找到imageBox,选择工具-选择工具箱项,在弹出的窗口中的.Net Framwork标签中点击浏览,把EmguCV目录下的Emgu.CV.UI.dll加入即可。

3.添加点击事件

 1  /// <summary>
 2         /// 点击按钮打开指定图片
 3         /// </summary>
 4         /// <param name="sender"></param>
 5         /// <param name="e"></param>
 6         private void OpenImage_Click(object sender, EventArgs e)
 7         {
 8             OpenFileDialog openFileDialog = new OpenFileDialog();
 9             if (openFileDialog.ShowDialog() == DialogResult.OK)
10             {
11                 try
12                 {
13                     capture = new Capture(openFileDialog.FileName);
14                     fnm = capture.GetCaptureProperty(CapProp.FrameCount);
15                     fps = (int)capture.GetCaptureProperty(CapProp.Fps);
16                     if (capture.Width != 0 && capture.Height != 0)
17                     {
18                         picWindow.Image = capture.QueryFrame();
19                     }
20                     
21                 }
22                 catch (Exception exp)
23                 {   
24                     MessageBox.Show(exp.Message);
25                 }
26                
27                 
28             }
29         }

4.运行程序得到的效果如下图所示:

原文地址:https://www.cnblogs.com/snipergodson/p/5818907.html