C# 和EmguCV

想实现界面化的图像/视频处理算法,发现EmguCV封装了OPencv库,支持C#等,于是按照网上教程下载/安装来试试。

http://blog.csdn.net/fioletfly/article/details/7329051

配置过程网上贴很多参考。

做了一个简单的界面,两个按钮,两个图片显示框,对选择的图片进行灰度化处理。

C# 和EmguCV_第1张图片  C# 和EmguCV_第2张图片


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

namespace Csharp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Image dest;
        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(textBox1.Text);
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "BMP 文件 |*.bmp | JPG 文件 |*.jpg|JPEG 文件|*.jpeg|所有文件| *.*";
            if (openFileDialog.ShowDialog() == DialogResult.OK) {
               // CvInvoke.cvNamedWindow("打开图片");
                IntPtr img = CvInvoke.cvLoadImage(openFileDialog.FileName, Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_ANYCOLOR);
                //CvInvoke.cvShowImage("打开图片",img);
                //CvInvoke.cvWaitKey(0);
                //CvInvoke.cvReleaseImage(ref img);
                //CvInvoke.cvDestroyWindow("打开图片");
                dest = new Image(CvInvoke.cvGetSize(img));
                CvInvoke.cvCopy(img, dest, IntPtr.Zero);
                pictureBox1.Image = dest.ToBitmap();

 
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Image grayImg = dest.Convert();
            pictureBox2.Image = grayImg.ToBitmap();

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }
    }
}



你可能感兴趣的:(【Opencv】)