Emgu Cv示例

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 System.Diagnostics;  
using Emgu.CV;  
using Emgu.Util;  

namespace EMGU_STUDY_1._0  
{  
    public partial class Form1 : Form  
    {  
        Mat img1 = null;  
        Mat img2 = null;  
        Mat img3 = null;  
        Stopwatch sw = new Stopwatch();  
        public Form1()  
        {  
            InitializeComponent();  
        }  

        private void button1_Click(object sender, EventArgs e)  
        {  
            OpenFileDialog lvse = new OpenFileDialog();  
            lvse.Title = "选择图片";  
            lvse.InitialDirectory = "";  
            lvse.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";  
            lvse.FilterIndex = 1;  

            if (lvse.ShowDialog() == DialogResult.OK)  
            {  
                textBox1.Text = null;  
                sw.Reset();  
                sw.Start();  

                img1 = CvInvoke.Imread(lvse.FileName, Emgu.CV.CvEnum.LoadImageType.AnyColor);  
                imageBox1.Width = img1.Width / 2;  
                imageBox1.Height = img1.Height / 2;  
                imageBox1.Image = img1;  

                sw.Stop();  
                textBox1.Text = sw.ElapsedMilliseconds.ToString();  
            }  

        }  

        private void button2_Click(object sender, EventArgs e)  
        {  
            if (img1 != null)  
            {  
                img2 = new Mat(img1.Rows, img1.Cols, Emgu.CV.CvEnum.DepthType.Cv8U, 1);  
                textBox2.Text = null;  
                sw.Reset();  
                sw.Start();  

                CvInvoke.CvtColor(img1, img2, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);  
                imageBox2.Width = img2.Width / 2;  
                imageBox2.Height = img2.Height / 2;  
                imageBox2.Image = img2;  

                sw.Stop();  
                textBox2.Text = sw.ElapsedMilliseconds.ToString();  
            }  
        }  

        private void button3_Click(object sender, EventArgs e)  
        {  
            textBox3.Text = null;  
            OpenFileDialog lvse = new OpenFileDialog();  
            lvse.Title = "选择图片";  
            lvse.InitialDirectory = "";  
            lvse.Filter = "图片文件|*.bmp;*.jpg;*.jpeg;*.gif;*.png";  
            lvse.FilterIndex = 1;  
            if (lvse.ShowDialog() == DialogResult.OK)  
            {  
                sw.Reset();  
                sw.Start();  

                img3 = CvInvoke.Imread(lvse.FileName, Emgu.CV.CvEnum.LoadImageType.Grayscale);  
                imageBox3.Width = img3.Width/2;  
                imageBox3.Height = img3.Height/2;  
                imageBox3.Image = img3;  

                sw.Stop();  
                textBox3.Text = sw.ElapsedMilliseconds.ToString();  
            }  
        }  

        private void button4_Click(object sender, EventArgs e)  
        {  
            img1 = null;  
            img2 = null;  
            img3 = null;  
            imageBox1.Image = null;  
            imageBox2.Image = null;  
            imageBox3.Image = null;  
            textBox1.Text = null;  
            textBox2.Text = null;  
            textBox3.Text = null;  
        }  
    }  
}  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值