/// <summary> /// Release the managed resources associated with this object /// </summary> protected override void ReleaseManagedResources() { _rectStorage.Dispose(); _vector.Dispose(); base.ReleaseManagedResources(); }
/// <summary> /// Release the storage related to this triangulation /// </summary> protected override void ReleaseManagedResources() { _storage.Dispose(); }
public static TouchImage ExtractContourAndHull(Image<Bgr, Byte> newImg) { TouchImage touchImage = new TouchImage(); touchImage.Image = newImg; //Image<Gray, byte> skin = new Image<Gray, byte>(newImg); using (MemStorage storage = new MemStorage()) { Image<Gray, Byte> grayImage = touchImage.Image.Convert<Gray, Byte>(); Contour<System.Drawing.Point> contours = grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); Contour<System.Drawing.Point> biggestContour = null; Double Result1 = 0; Double Result2 = 0; while (contours != null) { Result1 = contours.Area; if (Result1 > Result2) { Result2 = Result1; biggestContour = contours; } contours = contours.HNext; } if (biggestContour != null) { // currentFrame.Draw(biggestContour, new Bgr(Color.DarkViolet), 2); Contour<System.Drawing.Point> currentContour = biggestContour.ApproxPoly(biggestContour.Perimeter * 0.0025, storage); // currentFrame.Draw(currentContour, new Bgr(Color.LimeGreen), 2); // currentFrame.Draw(currentContour, new Bgr(Color.Red), 2); biggestContour = currentContour; // Seq<System.Drawing.Point> hull = biggestContour.GetConvexHull(Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE); touchImage.Box = biggestContour.GetMinAreaRect(); /* PointF[] points = touchImage.Box.GetVertices(); Rectangle handRect = touchImage.Box.MinAreaRect(); touchImage.Image.Draw(handRect, new Bgr(200, 0, 0), 1); touchImage.Image.Save(".\\aft\\BEFORE" + DateTime.Now.ToString("hh-mm-ss-fff") + ".jpg");*/ /* System.Drawing.Point[] ps = new System.Drawing.Point[points.Length]; for (int i = 0; i < points.Length; i++) ps[i] = new System.Drawing.Point((int)points[i].X, (int)points[i].Y); */ // currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(200, 125, 75), 2); //currentFrame.DrawPolyline(hull.ToArray(), true, new Bgr(Color.White), 2); // currentFrame.Draw(new CircleF(new PointF(box.center.X, box.center.Y), 3), new Bgr(200, 125, 75), 2); /* Seq<System.Drawing.Point> filteredHull = new Seq<System.Drawing.Point>(storage); for (int i = 0; i < hull.Total; i++) { if (Math.Sqrt(Math.Pow(hull[i].X - hull[i + 1].X, 2) + Math.Pow(hull[i].Y - hull[i + 1].Y, 2)) > touchImage.Box.size.Width / 10) { filteredHull.Push(hull[i]); } } */ touchImage.Defects = biggestContour.GetConvexityDefacts(storage, Emgu.CV.CvEnum.ORIENTATION.CV_CLOCKWISE).ToArray(); // touchImage.Image.Save(".\\aft\\BEFORE" + DateTime.Now.ToString("hh-mm-ss-fff") + ".jpg"); // string orientatio = ""; // ComputeFingersNum(touchImage, out orientatio); } storage.Dispose(); } return touchImage; }