123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- using OpenCvSharp;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- //using OpenCvSharp;
- namespace NewSegDll
- {
- public partial class Form1 : Form
- {
- //External parameters
- public int[] m_aiTrackBarMethod3;
- public Mat m_MOrgImg;
- public Mat MGryImg;
- public Mat m_Mbinaryzation;
- public int m_iWhichBlur;
- public int m_iMethod3DoSeg = 0;
- //Internal parameters
- public Mat m_MShowImg = null;
- int m_iMaxV;
- int m_iMinV;
- Bitmap m_BMImage;
- public Form1()
- {
- InitializeComponent();
- button5.Enabled = false;
- button6.Enabled = false;
- this.Activated += new EventHandler(Form1_Activated);
- }
- protected void Form1_Activated(object sender, System.EventArgs e)
- {
- m_iMethod3DoSeg = 0;
- if(null == m_MShowImg)
- {
- m_MShowImg = new Mat();
- m_MShowImg = m_MOrgImg.Clone();
- //m_MOrgImg.CopyTo(m_MShowImg);
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap(m_MShowImg.Width, m_MShowImg.Height, (int)m_MShowImg.Step(), PixelFormat.Format24bppRgb, m_MShowImg.Data);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, /*(System.IntPtr)*/m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- trackBar1.Minimum = 0;
- trackBar1.Maximum = 255;
- trackBar1.LargeChange = 5;
- trackBar1.SmallChange = 1;
- trackBar2.Minimum = 0;
- trackBar2.Maximum = 255;
- trackBar2.LargeChange = 5;
- trackBar2.SmallChange = 1;
- trackBar3.Minimum = 0;
- trackBar3.Maximum = 20;
- trackBar3.LargeChange = 2;
- trackBar3.SmallChange = 1;
- trackBar4.Minimum = 0;
- trackBar4.Maximum = 20;
- trackBar4.LargeChange = 2;
- trackBar4.SmallChange = 1;
- trackBar5.Minimum = 0;
- trackBar5.Maximum = 10;
- trackBar5.LargeChange = 2;
- trackBar5.SmallChange = 1;
- trackBar6.Minimum = -10;
- trackBar6.Maximum = 20;
- trackBar6.LargeChange = 3;
- trackBar6.SmallChange = 1;
- trackBar1.Value = m_aiTrackBarMethod3[0];
- trackBar2.Value = m_aiTrackBarMethod3[1];
- trackBar3.Value = m_aiTrackBarMethod3[2];
- trackBar4.Value = m_aiTrackBarMethod3[3];
- if (trackBar5.Maximum >= m_aiTrackBarMethod3[4]) trackBar5.Value = m_aiTrackBarMethod3[4];
- trackBar6.Value = m_aiTrackBarMethod3[5];
- if (1 == m_iWhichBlur)
- {
- radioButton1.Checked = false;
- radioButton2.Checked = true;
- radioButton3.Checked = false;
- radioButton4.Checked = false;
- }
- else if (2 == m_iWhichBlur)
- {
- radioButton1.Checked = false;
- radioButton2.Checked = false;
- radioButton3.Checked = true;
- radioButton4.Checked = false;
- }
- else if (3 == m_iWhichBlur)
- {
- radioButton1.Checked = false;
- radioButton2.Checked = false;
- radioButton3.Checked = false;
- radioButton4.Checked = true;
- }
- else
- {
- radioButton1.Checked = true;
- radioButton2.Checked = false;
- radioButton3.Checked = false;
- radioButton4.Checked = false;
- }
- if(true == radioButton4.Checked)
- {
- trackBar4.Enabled = true;
- label4.ForeColor = System.Drawing.Color.Black;
- }
- else
- {
- trackBar4.Enabled = false;
- label4.ForeColor = System.Drawing.Color.LightGray;
- }
-
- this.Update();
- }
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void trackBar2_Scroll(object sender, EventArgs e)
- {
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void trackBar3_Scroll(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- Mat MBlur = new Mat();
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- /*
- MatPointerMed = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.MedianBlur(MGryImg, MBlur, iLength);
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.Blur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength));
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- /*
- MatPointerGau = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- double dSigma = m_aiTrackBarMethod3[3];
- Cv2.GaussianBlur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength), dSigma, dSigma);
- }
- else
- {
- m_iWhichBlur = 0;
- MBlur = MGryImg;
- //MGryImg.CopyTo(MBlur);
- }
- Mat mat_mean = new Mat(), mat_stddev = new Mat();
- double m, s, d;
- Cv2.MeanStdDev(MBlur, mat_mean, mat_stddev);
- m = mat_mean.At<double>(0, 0);
- s = mat_stddev.At<double>(0, 0);
- d = 0.2;
- double th;
- th = m + d * s;
- double dThr = Cv2.Threshold(MBlur, m_Mbinaryzation, th, 255, ThresholdTypes.Binary);
- //Cv2.BitwiseNot(m_Mbinaryzation, m_Mbinaryzation);
- int[] point = new int[2];
- m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(0, 0, 255);
- int Rows = m_Mbinaryzation.Rows;
- int Cols = m_Mbinaryzation.Cols;
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (1 > m_Mbinaryzation.At<Byte>(point[0], point[1]))
- {
- //Vec3b colTemp = m_MShowImg.At<Vec3b>(point);
- //colTemp.Item2 = 255;
- //m_MShowImg.Set<Vec3b>(point, colTemp);
- m_MShowImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- button5.Enabled = true;
- button6.Enabled = true;
- this.Update();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- Mat MBlur = new Mat();
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- /*
- MatPointerMed = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.MedianBlur(MGryImg, MBlur, iLength);
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.Blur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength));
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- /*
- MatPointerGau = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- double dSigma = m_aiTrackBarMethod3[3];
- Cv2.GaussianBlur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength), dSigma, dSigma);
- }
- else
- {
- m_iWhichBlur = 0;
- MBlur = MGryImg;
- //MGryImg.CopyTo(MBlur);
- }
- double dThr = Cv2.Threshold(MBlur, m_Mbinaryzation, 0, 255, ThresholdTypes.Otsu);
- //Cv2.BitwiseNot(m_Mbinaryzation, m_Mbinaryzation);
- int[] point = new int[2];
- m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(0, 0, 255);
- int Rows = m_Mbinaryzation.Rows;
- int Cols = m_Mbinaryzation.Cols;
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (1 > m_Mbinaryzation.At<Byte>(point[0], point[1]))
- {
- //Vec3b colTemp = m_MShowImg.At<Vec3b>(point);
- //colTemp.Item2 = 255;
- //m_MShowImg.Set<Vec3b>(point, colTemp);
- m_MShowImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- button5.Enabled = true;
- button6.Enabled = true;
- this.Update();
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- if (true == radioButton4.Checked)
- {
- trackBar4.Enabled = true;
- label4.ForeColor = System.Drawing.Color.Black;
- }
- else
- {
- trackBar4.Enabled = false;
- label4.ForeColor = System.Drawing.Color.LightGray;
- }
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- if (true == radioButton4.Checked)
- {
- trackBar4.Enabled = true;
- label4.ForeColor = System.Drawing.Color.Black;
- }
- else
- {
- trackBar4.Enabled = false;
- label4.ForeColor = System.Drawing.Color.LightGray;
- }
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void radioButton3_CheckedChanged(object sender, EventArgs e)
- {
- if (true == radioButton4.Checked)
- {
- trackBar4.Enabled = true;
- label4.ForeColor = System.Drawing.Color.Black;
- }
- else
- {
- trackBar4.Enabled = false;
- label4.ForeColor = System.Drawing.Color.LightGray;
- }
- }
- private void radioButton4_CheckedChanged(object sender, EventArgs e)
- {
- if (true == radioButton4.Checked)
- {
- trackBar4.Enabled = true;
- label4.ForeColor = System.Drawing.Color.Black;
- }
- else
- {
- trackBar4.Enabled = false;
- label4.ForeColor = System.Drawing.Color.LightGray;
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- Mat MBlur = new Mat();
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- /*
- MatPointerMed = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.MedianBlur(MGryImg, MBlur, iLength);
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.Blur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength));
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- /*
- MatPointerGau = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- double dSigma = m_aiTrackBarMethod3[3];
- Cv2.GaussianBlur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength), dSigma, dSigma);
- }
- else
- {
- m_iWhichBlur = 0;
- MBlur = MGryImg;
- //MGryImg.CopyTo(MBlur);
- }
- if (m_aiTrackBarMethod3[0] > m_aiTrackBarMethod3[1])
- {
- int iTemp = m_aiTrackBarMethod3[0];
- m_aiTrackBarMethod3[0] = m_aiTrackBarMethod3[1];
- m_aiTrackBarMethod3[1] = iTemp;
- trackBar1.Value = m_aiTrackBarMethod3[0];
- trackBar2.Value = m_aiTrackBarMethod3[1];
- }
- m_iMaxV = m_aiTrackBarMethod3[1];
- m_iMinV = m_aiTrackBarMethod3[0];
- Mat MTempMax, MTempMin;
- if(0 == m_iMinV)
- {
- MTempMin = new Mat(MBlur.Rows, MBlur.Cols, MatType.CV_8UC1, Scalar.All(0));
- }
- else
- {
- MTempMin = new Mat();
- Cv2.Threshold(MBlur, MTempMin, m_iMinV-1, 255, ThresholdTypes.BinaryInv);
- }
- if (255 == m_iMaxV)
- {
- MTempMax = new Mat(MBlur.Rows, MBlur.Cols, MatType.CV_8UC1, Scalar.All(0));
- }
- else
- {
- MTempMax = new Mat();
- Cv2.Threshold(MBlur, MTempMax, m_iMaxV, 255, ThresholdTypes.Binary);
- }
- m_Mbinaryzation = MTempMin | MTempMax;
- //Cv2.BitwiseNot(m_Mbinaryzation, m_Mbinaryzation);
- int[] point = new int[2];
- m_MShowImg = m_MOrgImg.Clone();
- //m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(0, 0, 255);
- int Rows = m_Mbinaryzation.Rows;
- int Cols = m_Mbinaryzation.Cols;
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (1 > m_Mbinaryzation.At<Byte>(point[0], point[1]))
- {
- //Vec3b colTemp = m_MShowImg.At<Vec3b>(point);
- //colTemp.Item2 = 255;
- //m_MShowImg.Set<Vec3b>(point, colTemp);
- m_MShowImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- button5.Enabled = true;
- button6.Enabled = true;
- this.Update();
- }
- private void button2_Click(object sender, EventArgs e)
- {
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;// 50;// m_aiTrackBarMethod3[4] + 1;// 10;// 9;//
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- Mat MBlur = new Mat();
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- /*
- MatPointerMed = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.MedianBlur(MGryImg, MBlur, iLength);
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- Cv2.Blur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength));
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- /*
- MatPointerGau = new Mat(m_MatRealZV.Size(), MatType.CV_32F);
- */
- int iLength = m_aiTrackBarMethod3[2] * 2 + 1;
- double dSigma = m_aiTrackBarMethod3[3];
- Cv2.GaussianBlur(MGryImg, MBlur, new OpenCvSharp.Size(iLength, iLength), dSigma, dSigma);
- }
- else
- {
- m_iWhichBlur = 0;
- MBlur = MGryImg;
- //MGryImg.CopyTo(MBlur);
- }
- int iAPLength = m_aiTrackBarMethod3[4] * 2 + 1;
- int iAPThreshold = m_aiTrackBarMethod3[5];
- Cv2.AdaptiveThreshold(MBlur, m_Mbinaryzation, 255, AdaptiveThresholdTypes.GaussianC, ThresholdTypes.Binary, iAPLength, iAPThreshold);
- OpenCvSharp.Size bianjieSize = m_Mbinaryzation.Size();
- Mat Temp = Mat.Zeros(bianjieSize.Height + 2, bianjieSize.Width + 2, m_Mbinaryzation.Type());//延展图像
- m_Mbinaryzation.CopyTo(Temp.SubMat(new Range(1, bianjieSize.Height + 1), new Range(1, bianjieSize.Width + 1)));
- Cv2.FloodFill(Temp, new OpenCvSharp.Point(0, 0), new Scalar(255));
- Mat cutImg = new Mat();
- Temp.SubMat(new Range(1, bianjieSize.Height + 1), new Range(1, bianjieSize.Width + 1)).CopyTo(cutImg);
- Cv2.BitwiseNot(cutImg, cutImg);
- m_Mbinaryzation = m_Mbinaryzation | cutImg;
- //Cv2.BitwiseNot(m_Mbinaryzation, m_Mbinaryzation);
- int[] point = new int[2];
- m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(0, 0, 255);
- int Rows = m_Mbinaryzation.Rows;
- int Cols = m_Mbinaryzation.Cols;
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (1 > m_Mbinaryzation.At<Byte>(point[0], point[1]))
- {
- //Vec3b colTemp = m_MShowImg.At<Vec3b>(point);
- //colTemp.Item2 = 255;
- //m_MShowImg.Set<Vec3b>(point, colTemp);
- m_MShowImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- button5.Enabled = true;
- button6.Enabled = true;
- this.Update();
- }
- private void button5_Click(object sender, EventArgs e)
- {
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- }
- else
- {
- m_iWhichBlur = 0;
- }
- OpenCvSharp.Size bianjieSize = m_Mbinaryzation.Size();
- Mat Temp = Mat.Zeros(bianjieSize.Height + 2, bianjieSize.Width + 2, m_Mbinaryzation.Type());//延展图像
- Mat imageMask = new Mat(m_Mbinaryzation.Size(), MatType.CV_8UC1, new Scalar(255));
- OpenCvSharp.Mat posSrc = new OpenCvSharp.Mat(Temp, new OpenCvSharp.Rect(1, 1, bianjieSize.Width + 1, bianjieSize.Height + 1));
- m_Mbinaryzation.CopyTo(posSrc, imageMask);//原图像复制到新图像
- //m_Mbinaryzation.CopyTo( Temp.SubMat(new Range(1, bianjieSize.Height + 1), new Range(1, bianjieSize.Width + 1)) );
- Cv2.FloodFill(Temp, new OpenCvSharp.Point(0, 0), new Scalar(255));
- Mat cutImg = new Mat();
- //Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- //OpenCvSharp.Point[][] arr = new OpenCvSharp.Point[1][];
- //arr[0] = new OpenCvSharp.Point[] { new OpenCvSharp.Point(rectangle.X, rectangle.Y), new OpenCvSharp.Point(rectangle.X + rectangle.Width, rectangle.Y), new OpenCvSharp.Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), new OpenCvSharp.Point(rectangle.X, rectangle.Y + rectangle.Height) };
- //Cv2.FillPoly(imageMask, arr, new Scalar(255));
- //OpenCvSharp.Mat posSrc = new OpenCvSharp.Mat(result, new OpenCvSharp.Rect(newOriX, newOriY, matNew.Width, matNew.Height));
- //tempMatSrc.CopyTo(posSrc, mask);//原图像复制到新图像
- cutImg = Temp.SubMat(new Range(1, bianjieSize.Height + 1), new Range(1, bianjieSize.Width + 1)).Clone();
- //Temp.SubMat(new Range(1, bianjieSize.Height + 1), new Range(1, bianjieSize.Width + 1)).CopyTo(cutImg);
- Cv2.BitwiseNot(cutImg, cutImg);
- m_Mbinaryzation = m_Mbinaryzation | cutImg;
- //Cv2.BitwiseNot(m_Mbinaryzation, m_Mbinaryzation);
- int[] point = new int[2];
- m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(0, 0, 255);
- int Rows = m_Mbinaryzation.Rows;
- int Cols = m_Mbinaryzation.Cols;
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (1 > m_Mbinaryzation.At<Byte>(point[0], point[1]))
- {
- //Vec3b colTemp = m_MShowImg.At<Vec3b>(point);
- //colTemp.Item2 = 255;
- //m_MShowImg.Set<Vec3b>(point, colTemp);
- m_MShowImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- this.Update();
- }
- public NewSeg NSeg;
- private void button6_Click(object sender, EventArgs e)
- {
- //m_aiTrackBarMethod3[0] = trackBar1.Value;
- //m_aiTrackBarMethod3[1] = trackBar2.Value;
- //m_aiTrackBarMethod3[2] = trackBar3.Value;
- //m_aiTrackBarMethod3[3] = trackBar4.Value;
- //m_aiTrackBarMethod3[4] = trackBar5.Value;
- //m_aiTrackBarMethod3[5] = trackBar6.Value;
- //if (true == radioButton2.Checked)
- //{
- // m_iWhichBlur = 1;
- //}
- //else if (true == radioButton3.Checked)
- //{
- // m_iWhichBlur = 2;
- //}
- //else if (true == radioButton4.Checked)
- //{
- // m_iWhichBlur = 3;
- //}
- //else
- //{
- // m_iWhichBlur = 0;
- //}
- //m_iMethod3DoSeg = 1;
- //m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- //this.pictureBox1.Image = m_BMImage;
- //this.Update();
- m_aiTrackBarMethod3[0] = trackBar1.Value;
- m_aiTrackBarMethod3[1] = trackBar2.Value;
- m_aiTrackBarMethod3[2] = trackBar3.Value;
- m_aiTrackBarMethod3[3] = trackBar4.Value;
- m_aiTrackBarMethod3[4] = trackBar5.Value;
- m_aiTrackBarMethod3[5] = trackBar6.Value;
- if (true == radioButton2.Checked)
- {
- m_iWhichBlur = 1;
- }
- else if (true == radioButton3.Checked)
- {
- m_iWhichBlur = 2;
- }
- else if (true == radioButton4.Checked)
- {
- m_iWhichBlur = 3;
- }
- else
- {
- m_iWhichBlur = 0;
- }
- m_iMethod3DoSeg = 1;
- this.NSeg.Method3DoSegButonClickAction();
- Mat watermark = this.NSeg.m_watermark;
- int Rows = watermark.Rows;
- int Cols = watermark.Cols;
- int[] point = new int[2];
- m_MOrgImg.CopyTo(m_MShowImg);
- Vec3b redcol = new Vec3b(255, 0, /*255*/0);
- for (point[0] = 0; point[0] < Rows; point[0]++)
- {
- for (point[1] = 0; point[1] < Cols; point[1]++)
- {
- if (0 >= watermark.At<int>(point[0], point[1]))
- {
- m_MShowImg.Set<Vec3b>(point, redcol);
- //m_MOutImg.Set<Vec3b>(point, redcol);
- }
- }
- }
- m_BMImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(/*this.NSeg.m_MOutImg*/m_MShowImg);// new Bitmap((int)m_MShowImg.Cols, (int)m_MShowImg.Rows, (int)m_MShowImg.Step(), System.Drawing.Imaging.PixelFormat.Format24bppRgb, (System.IntPtr)m_MShowImg.Data);
- this.pictureBox1.Image = m_BMImage;
- this.Update();
- //this.Close();
- }
- private void trackBar5_Scroll(object sender, EventArgs e)
- {
- }
- }
- }
|