public DiffContainer GetDiffs(Bitmap newFrame, int compressRate) { //sw.Restart(); Image <Bgr, Byte> Frame = new Image <Bgr, byte>(newFrame); if (_oldImage == null || _oldImage.Height != newFrame.Height) { _oldImage = new Bitmap(newFrame.Width, newFrame.Height); } Previous_Frame = new Image <Bgr, byte>(_oldImage); Image <Bgr, Byte> Difference; Difference = Previous_Frame.AbsDiff(Frame); Image <Gray, Byte> gray = Difference.Convert <Gray, Byte>().PyrDown().PyrUp(); DiffContainer container = new DiffContainer(); List <MovedObject> movedObjects = new List <MovedObject>(); using (MemStorage storage = new MemStorage()) for (Contour <System.Drawing.Point> contours = gray.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_EXTERNAL, storage); contours != null; contours = contours.HNext) { Contour <Point> contour = contours.ApproxPoly(contours.Perimeter * 0.001); if (contour.Area > 100) // if (contour.Total > 5) { Rectangle rect = contour.BoundingRectangle; rect.X -= 1; rect.Y -= 1; rect.Width += 2; rect.Height += 2; var part = Frame.GetSubRect(rect); //var j = ImageResizer.ImageBuilder.Current.Build(part.ToBitmap(), // new ImageResizer.ResizeSettings( // "maxwidth=" + part.Width / CompressRate + // "&maxheight=" + part.Height + // "&format=jpg&quality=20" // )); var j = part.ToBitmap(); container.Data.Add(rect, j); } } UpdateOldFrame(container); //sw.Stop(); //container.Elapsed = sw.ElapsedMilliseconds; return(container); }