Emgu CV3+C#图像处理(五):C#界面使用用EmguCV加载图像

xiaoxiao2021-02-28  47

环境:Win7-64位+VS2012+EmguCV3.0.0

1、打开VS2012,新建一个C#下的Windows窗体应用程序: 2、打开“配置管理器”,“活动解决方案平台”选择“x64”; 3、打开“解决方案管理器”——>右击“引用”——>“添加引用”——>“浏览”,从“…\emgucv-windows-universal 3.0.0.2157\bin”目录下添加Emgu.CV.dll、Emgu.CV.UI.dll、Emgu.Util.dll、Emgu.Util.dll等几个常用的dll: 4、打开“工具箱”——>向窗口界面中拖拽一个ImageBox和两个Button控件,并适当调整窗体和控件的大小和位置,修改ImageBox属性“外观”中的“BackColor”为黑色,修改button1、button2的名称为“加载图像”、“窗口变色”:

5、若“工具箱”中没有“ImageBox”选项,则右击“常规”——>选择“选择工具箱项”——>“浏览”,从“…\emgucv-windows-universal 3.0.0.2157\bin”目录下添加Emgu.CV.UI.dll: 添加后,可以看到有“ImageBox”选项:

6、分别双击两个Button控件,然后在对应位置添加代码:

文件Form1.cs:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Emgu.CV; using Emgu.Util; using Emgu.CV.Structure; using Emgu.CV.CvEnum; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //加载图像 var dialog = new OpenFileDialog(); dialog.Filter = "图片(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp"; if (dialog.ShowDialog() == DialogResult.OK) { var filename = dialog.FileName; Image<Bgr, Byte> image; image = new Image<Bgr, byte>(@filename); imageBox1.Image = image; } } private void button2_Click(object sender, EventArgs e) { Image<Bgr, Byte> img = new Image<Bgr, Byte>(640, 400, new Bgr(200, 200, 0));//(640,400)为ImageBox1控件大小 imageBox1.Image = img;//在ImageBox1控件中显示图像 } } }

加载图像:


Emgu CV Library Documentation::Image

转载请注明原文地址: https://www.6miu.com/read-2623441.html

最新回复(0)