VS2013+emguCV2.4.2的配置

emguCV是OpenCV關於C#的封裝庫。能夠說是OpenCV在C#中使用的版本,能夠彌補OpenCV關於GUI界面的缺陷。對於emguCV網上資料較少,但不能說它沒用。spa

一.emguCV配置(win10系統下)code

1.環境變量的配置(個人電腦->屬性->高級系統配置->環境變量)orm

在path路徑下添加emguCV安裝路徑blog

有些電腦須要重啓才能生效。圖片

2.在VS2013中新建WindowsForm工程string

3.在解決方案的reference中添加五個動態庫it

4.在TOOLS->choose Toolbox items...中選中一下幾個.dllio

此時emguCV基本上配置完了,接下來就能夠下代碼了,下面的代碼,嵌入水印功能還未完善。class

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using System.IO;
11 using Emgu.CV;
12 using Emgu.Util;
13 using Emgu.CV.Structure;
14 
15 
16 namespace WindowsFormsApplication1
17 {
18     public partial class Form1 : Form
19     {
20         public Form1()
21         {
22             InitializeComponent();
23         }
24 
25         private void button1_Click(object sender, EventArgs e)
26         {
27             var dialog = new OpenFileDialog();
28             dialog.Filter = "圖片(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp";
29             if (dialog.ShowDialog() == DialogResult.OK)
30             {
31                 var filename = dialog.FileName;
32 
33                 IntPtr image = CvInvoke.cvLoadImage(filename, Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR);
34                 Image<Bgr, byte> dest = new Image<Bgr, byte>(CvInvoke.cvGetSize(image));
35                 CvInvoke.cvCopy(image, dest, IntPtr.Zero);
36                 pictureBox1.Image = dest.ToBitmap();
37             }
38 
39             //OpenFileDialog ofd = new OpenFileDialog();
40             //ofd.ShowDialog();
41             //string path = ofd.FileName;
42             //textBox1.Text = File.ReadAllText(path,Encoding.Default);  
43         }
44 
45         private void textBox1_TextChanged(object sender, EventArgs e)
46         {
47 
48         }
49 
50         private void pictureBox1_Click(object sender, EventArgs e)
51         {
52         
53         }
54 
55         private void button2_Click(object sender, EventArgs e) //打開水印
56         {
57             var dialog = new OpenFileDialog();
58             dialog.Filter = "圖片(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp";
59             if (dialog.ShowDialog() == DialogResult.OK)
60             {
61                 var filename = dialog.FileName;
62 
63                 IntPtr mark = CvInvoke.cvLoadImage(filename, Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR);
64                 Image<Bgr, byte> rawMark = new Image<Bgr, byte>(CvInvoke.cvGetSize(mark));
65                 CvInvoke.cvCopy(mark, rawMark, IntPtr.Zero);
66                 pictureBox2.Image = rawMark.ToBitmap();
67                              
68             }
69         }
70 
71         private void embed_Click(object sender, EventArgs e) //嵌入水印
72         {
73 
74         }
75     }
76 }

運行結果:變量

相關文章
相關標籤/搜索