2015年10月17日 星期六

Emgu CV (4) Example2

pictureBox顯示原始圖、灰階圖、邊圓檢測圖。

1. 輸入範例程式,最後按"開始偵錯"按鈕進行編譯。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
 
namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog();
            dialog.Filter = "photo(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var filename = dialog.FileName;
                Image<bgr, byte=""> My_Image = new Image<bgr, byte="">(filename);
                pictureBox1.BackgroundImage = My_Image.ToBitmap();
                Image<gray, byte=""> grayFrame = My_Image.Convert<gray, byte="">();
                pictureBox2.BackgroundImage = grayFrame.ToBitmap();
                pictureBox3.BackgroundImage = grayFrame.Canny(new Gray(100),  new Gray(60)).ToBitmap();
            }
        }
    }
}


2. 執行結果。

沒有留言:

張貼留言