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.CvEnum
using Emgu.CV.Structure
using Emgu.Util
namespace WindowsFormsApplication23
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent()
}
private void button1_Click(object sender, EventArgs e)
{
string strFileName = string.Empty
OpenFileDialog ofd = new OpenFileDialog()
if (ofd.ShowDialog() == DialogResult.OK)
{
IntPtr img = CvInvoke.cvLoadImage(ofd.FileName, Emgu.CV.CvEnum.LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_GRAYSCALE)
Image<Gray, Byte> dst = new Image<Gray, Byte>(CvInvoke.cvGetSize(img))
Image<Gray, Byte> depth_Threshold1 = new Image<Gray, Byte>(CvInvoke.cvGetSize(img))
Image<Gray, Byte> depth_Threshold2 = new Image<Gray, Byte>(CvInvoke.cvGetSize(img))
Image<Gray, Byte> depth_Morphic1 = new Image<Gray, Byte>(CvInvoke.cvGetSize(img))
Image<Gray, Byte> depth_Contour1 = new Image<Gray, Byte>(CvInvoke.cvGetSize(img))
CvInvoke.cvCopy(img, dst, IntPtr.Zero)
imageBox1.Image = dst
//阈值操作后的深度图像
IntPtr depth_Threshold = CvInvoke.cvCreateImage(CvInvoke.cvGetSize(img), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 1)
//形态学操作后的深度图像
IntPtr depth_Morphic = CvInvoke.cvCreateImage(CvInvoke.cvGetSize(img), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 1)
//进行边界提取后的深度图像
IntPtr depth_Contour = CvInvoke.cvCreateImage(CvInvoke.cvGetSize(img), Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_8U, 1)
//单一阈值分割
CvInvoke.cvThreshold(img, depth_Threshold, 60, 255, Emgu.CV.CvEnum.THRESH.CV_THRESH_TOZERO)
CvInvoke.cvCopy(depth_Threshold, depth_Threshold1, IntPtr.Zero)
imageBox2.Image = depth_Threshold1
//腐蚀运算
CvInvoke.cvErode(depth_Threshold, depth_Threshold, IntPtr.Zero, 3)
CvInvoke.cvCopy(depth_Threshold, depth_Threshold2, IntPtr.Zero)
imageBox3.Image = depth_Threshold2
//膨胀运算
CvInvoke.cvDilate(depth_Threshold, depth_Morphic, IntPtr.Zero, 3)
CvInvoke.cvCopy(depth_Morphic, depth_Morphic1, IntPtr.Zero)
imageBox4.Image = depth_Morphic1
//进行复制
CvInvoke.cvCopy(depth_Morphic, depth_Contour, IntPtr.Zero)
CvInvoke.cvCopy(depth_Contour, depth_Contour1, IntPtr.Zero)
imageBox5.Image = depth_Contour1
}
}
}
}