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
This commit is contained in:
niksedk 2013-09-08 12:30:57 +00:00
parent 24474dce45
commit f34b3cc6e8
2 changed files with 18 additions and 12 deletions

View File

@ -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();
}
}

View File

@ -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;
}