// Background Subtraction From the Given Background and Input Image public void removebackground(string filepath = null) { CvInvoke.Imshow("1- Background Image", bgImage); CvInvoke.Imshow("2- Forground Image", img); Image <Gray, byte> output = new Image <Gray, byte>(bgImage.Width, bgImage.Height); BackgroundSubtractorMOG2 bgsubtractor = new BackgroundSubtractorMOG2(varThreshold: 100, shadowDetection: false); bgsubtractor.Apply(bgImage, output); bgsubtractor.Apply(img, output); pictureViewBox.Image = output; CvInvoke.Imshow("3- Background Subtracted", output); //output.Canny(100,100); CvInvoke.Erode(output, output, null, new System.Drawing.Point(-1, -1), 1, BorderType.Reflect, default(MCvScalar)); CvInvoke.Imshow("4- After Applying Erode", output); CvInvoke.Dilate(output, output, null, new System.Drawing.Point(-1, -1), 5, BorderType.Reflect, default(MCvScalar)); CvInvoke.Imshow("5- After Dilation", output); // Write the Silhoutte output to the file if (filepath != null && saveResults == true) { CvInvoke.Imwrite(outputFolder + "bg_subtract_" + filepath, output); } // finding the Bounding Box of the Person frm = new PersonFrame(); Rectangle rec = frm.findBoundry(output); // Using Thinning Algorithm on Silhoutte Image <Gray, byte> thinOutput = new Image <Gray, byte>(output.Width, output.Height); XImgprocInvoke.Thinning(output, thinOutput, ThinningTypes.ZhangSuen); pictureViewBox.Image = thinOutput.Not().Not(); CvInvoke.Imshow("6- After Thinning Zhang Suen", thinOutput); // Write the thinned Image to the file if (filepath != null && saveResults == true) { CvInvoke.Imwrite(outputFolder + "thinned_" + filepath, thinOutput.Not().Not()); } // drawing bounding Box of the person CvInvoke.Rectangle(thinOutput, rec, new Rgb(Color.White).MCvScalar, 2); CvInvoke.Imshow("Person Bounding Box", thinOutput); // drawing the middle line of the Person //CvInvoke.Line(thinOutput, frm.middle_line.p1, frm.middle_line.p2, new Rgb(Color.White).MCvScalar, 2); // Display the Image //CvInvoke.Imshow("Person Fame", thinOutput); // Applying Hough Line Transformation Hough(thinOutput, filepath); img.Dispose(); output.Dispose(); thinOutput.Dispose(); }
public void Thining() { Image <Gray, Byte> sourceImage = new Image <Gray, byte>((Bitmap)pictureBox1.Image); Image <Gray, Byte> dstImage = new Image <Gray, Byte>(sourceImage.Width, sourceImage.Height); XImgprocInvoke.Thinning(sourceImage, dstImage, ThinningTypes.ZhangSuen); pictureBox1.Image = dstImage.ToBitmap(); maxBmpLevel = HistogramOperations.MaxBmpLevel(pictureBox1.Image); HistogramOperations.clearHistogram(chart1); histoTab = HistogramOperations.drawHistogram(chart1, pictureBox1.Image, maxBmpLevel); }
private void Thinning_Click(object sender, EventArgs e) { Mat mat = imageEmgu.Mat; Mat metGrey = imageEmgu.Mat; Mat metGeryOutput = new Mat(); ElementShape elementShape = elementShapee; CvInvoke.CvtColor(mat, metGrey, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray); Mat structuringElement = CvInvoke.GetStructuringElement(elementShape, new Size(3, 3), new Point(1, 1)); XImgprocInvoke.Thinning(metGrey, metGeryOutput, ThinningTypes.GuoHall); // CvInvoke.MorphologyEx(metGrey, metGeryOutput, MorphOp.Open, structuringElement, new System.Drawing.Point(1, 1), 2, BorderType.Isolated, CvInvoke.MorphologyDefaultBorderValue); ImagePostBox.Image = metGeryOutput.ToImage <Bgr, byte>().Bitmap; ImagePostBox.SizeMode = PictureBoxSizeMode.StretchImage; }