public void StraightenAndCrop(string filename) { int handle = ImageOperations.SetImage(new Bitmap(filename)); ImageOperations.CardScan_RectifyRawImageHighGradientError(handle); int handle2 = ImageOperations.Copy(handle); ImageOperations.SizeHalve(handle, HalveSizeType.Average); ImageOperations.Invert(handle); float a = 90.0f - ImageOperations.HoughGradient(handle, 76, 104, 100); ImageOperations.Rotate(handle2, a); int minx = 0; int miny = 0; int maxx = 0; int maxy = 0; ImageOperations.CardScan_DetermineCardBounds(handle2, 20, ref minx, ref maxx, ref miny, ref maxy); ImageOperations.Crop(handle2, minx, miny, maxx - minx + 1, maxy - miny + 1); int handle3 = ImageOperations.Copy(handle2); //ImageOperations.SizeHalve(handle3, HalveSizeType.Average); ImageOperations.Threshold(handle3, 9); int handle4 = ImageOperations.Copy(handle3); int handle5 = ImageOperations.Copy(handle4); ImageOperations.RLSA(handle3, 30, RLSA_Direction.Right); ImageOperations.RLSA(handle4, 30, RLSA_Direction.Left); ImageOperations.LogicalAnd(handle3, handle4); ImageOperations.GetImage(handle3).Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "__" + System.IO.Path.GetFileName(filename))); List <System.Drawing.Rectangle> rs = ImageOperations.GenerateBoundingBoxes(handle3); rs = ImageOperations.RemoveSmallBoxes(rs, 5); for (int i = 0; i < rs.Count; ++i) { ImageOperations.DrawRectangle(handle5, rs[i], 128); } ImageOperations.GetImage(handle5).Save(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(filename), "_" + System.IO.Path.GetFileName(filename))); ImageOperations.DeleteImage(handle); ImageOperations.DeleteImage(handle2); ImageOperations.DeleteImage(handle3); ImageOperations.DeleteImage(handle4); ImageOperations.DeleteImage(handle5); }