From f34b3cc6e83c45c98e3828c09d47f2f99b89742b Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 8 Sep 2013 12:30:57 +0000 Subject: [PATCH] Fixed crash in OCR via Image compare with large image databases - thx Zoltan :) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@2064 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/VobSubOcr.cs | 25 +++++++++++++++---------- src/Logic/ImageSplitter.cs | 5 +++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Forms/VobSubOcr.cs b/src/Forms/VobSubOcr.cs index b65dd67ea..145141445 100644 --- a/src/Forms/VobSubOcr.cs +++ b/src/Forms/VobSubOcr.cs @@ -2160,7 +2160,9 @@ namespace Nikse.SubtitleEdit.Forms // check for expand match! if (compareItem.ExpandCount > 0 && compareItem.Bitmap.Width > targetItem.Bitmap.Width) { - int dif = ImageSplitter.IsBitmapsAlike(compareItem.Bitmap, ImageSplitter.Copy(parentBitmap, new Rectangle(targetItem.X, targetItem.Y, compareItem.Bitmap.Width, compareItem.Bitmap.Height))); + Bitmap cutBitmap = ImageSplitter.Copy(parentBitmap, new Rectangle(targetItem.X, targetItem.Y, compareItem.Bitmap.Width, compareItem.Bitmap.Height)); + int dif = ImageSplitter.IsBitmapsAlike(compareItem.Bitmap, cutBitmap); + cutBitmap.Dispose(); if (dif < smallestDifference) { smallestDifference = dif; @@ -2196,30 +2198,33 @@ namespace Nikse.SubtitleEdit.Forms { Bitmap cutBitmap = CopyBitmapSection(target, new Rectangle(1, 0, target.Width - 2, target.Height)); int topCrop = 0; - cutBitmap = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop, 2); - if (cutBitmap.Height != target.Height) - FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap); + Bitmap cutBitmap2 = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop, 2); + if (cutBitmap2.Height != target.Height) + FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2); cutBitmap.Dispose(); + cutBitmap2.Dispose(); } if (smallestDifference > 0 && target.Width > 15) { Bitmap cutBitmap = CopyBitmapSection(target, new Rectangle(1, 0, target.Width - 2, target.Height)); int topCrop = 0; - cutBitmap = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop); - if (cutBitmap.Height != target.Height) - FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap); + Bitmap cutBitmap2 = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop); + if (cutBitmap2.Height != target.Height) + FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2); cutBitmap.Dispose(); + cutBitmap2.Dispose(); } if (smallestDifference > 0 && target.Width > 15) { Bitmap cutBitmap = CopyBitmapSection(target, new Rectangle(1, 0, target.Width - 2, target.Height)); int topCrop = 0; - cutBitmap = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop); - if (cutBitmap.Height != target.Height) - FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap); + Bitmap cutBitmap2 = ImageSplitter.CropTopAndBottom(cutBitmap, out topCrop); + if (cutBitmap2.Height != target.Height) + FindBestMatch(ref index, ref smallestDifference, ref smallestIndex, cutBitmap2); cutBitmap.Dispose(); + cutBitmap2.Dispose(); } } diff --git a/src/Logic/ImageSplitter.cs b/src/Logic/ImageSplitter.cs index 8170b561d..d4bf273fd 100644 --- a/src/Logic/ImageSplitter.cs +++ b/src/Logic/ImageSplitter.cs @@ -592,19 +592,20 @@ namespace Nikse.SubtitleEdit.Logic { int different = 0; int maxDiff = (int)(bmp1.Width * bmp1.Height / 5.0); + NikseBitmap nbmp1 = new NikseBitmap(bmp1); for (int x = 1; x < bmp1.Width; x++) { for (int y = 1; y < bmp1.Height; y++) { - if (!IsColorClose(bmp1.GetPixel(x, y), bmp2.GetPixel(x, y), 20)) + if (!IsColorClose(nbmp1.GetPixel(x, y), bmp2.GetPixel(x, y), 20)) { different++; } } if (different > maxDiff) return different + 10; - } + } return different; }