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 meanshift
{
public partial class Form1 : Form
{
static string name;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
if (open.ShowDialog() == DialogResult.OK)
{
name = open.FileName;
}
}
private void test(string name)
{
Image<Bgr, byte> src = new Image<Bgr, byte>(name);//读取原图像
pictureBox2.Image = src.ToBitmap();
Image<Bgr, byte> src1 = new Image<Bgr, byte>(src.Size);
CvInvoke.cvPyrMeanShiftFiltering(src, src1, trackBar1.Value, trackBar2.Value, trackBar3.Value, new MCvTermCriteria(1));
pictureBox1.Image = src1.ToBitmap();//将处理后的图像显示出来
src.Dispose();
src1.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
test(name);
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
label1.Text = trackBar1.Value.ToString();
test(name);
}
private void trackBar2_ValueChanged(object sender, EventArgs e)
{
label2.Text = trackBar2.Value.ToString();
test(name);
}
private void trackBar3_ValueChanged(object sender, EventArgs e)
{
label3.Text = trackBar3.Value.ToString();
test(name);
}
}
}
效果可以更改滑动条来改变。
Parameters
src – The source 8-bit, 3-channel image.
dst – The destination image of the same format and the same size as the source.
sp – The spatial window radius.
sr – The color window radius.
maxLevel – Maximum level of the pyramid for the segmentation.
termcrit – Termination criteria: when to stop meanshift iterations