mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-24 04:02:36 +01:00
more ocr
This commit is contained in:
parent
bee7fedae5
commit
18fee311ce
@ -305,6 +305,41 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
|
||||
{
|
||||
AutoDetectedFonts.Add(_subtitleFontName + " " + _subtitleFontSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
// allow for error %
|
||||
var smallestDifference = int.MaxValue;
|
||||
BinaryOcrBitmap hit = null;
|
||||
foreach (var compareItem in bicDb.CompareImages)
|
||||
{
|
||||
if (compareItem.Width == _autoDetectFontBob.Width && compareItem.Height == _autoDetectFontBob.Height) // precise math in size
|
||||
{
|
||||
if (Math.Abs(compareItem.NumberOfColoredPixels - _autoDetectFontBob.NumberOfColoredPixels) < 3)
|
||||
{
|
||||
int dif = NikseBitmapImageSplitter.IsBitmapsAlike(compareItem, _autoDetectFontBob);
|
||||
if (dif < smallestDifference)
|
||||
{
|
||||
if (!BinaryOcrDb.AllowEqual(compareItem, _autoDetectFontBob))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
smallestDifference = dif;
|
||||
hit = compareItem;
|
||||
if (dif < 3)
|
||||
{
|
||||
break; // foreach ending
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (smallestDifference < 13)
|
||||
{
|
||||
AutoDetectedFonts.Add($"{_subtitleFontName} {_subtitleFontSize} - diff={smallestDifference}");
|
||||
}
|
||||
}
|
||||
|
||||
bicDb = new BinaryOcrDb(null);
|
||||
TrainLetter(ref numberOfCharactersLeaned, ref numberOfCharactersSkipped, bicDb, charactersLearned, s, false, true);
|
||||
|
@ -1131,6 +1131,30 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return different;
|
||||
}
|
||||
|
||||
internal static int IsBitmapsAlike(Ocr.Binary.BinaryOcrBitmap bmp1, Ocr.Binary.BinaryOcrBitmap bmp2)
|
||||
{
|
||||
int different = 0;
|
||||
int maxDiff = bmp1.Width * bmp1.Height / 5;
|
||||
for (int y = 0; y < bmp1.Height; y++)
|
||||
{
|
||||
var pixel = y * bmp1.Width;
|
||||
for (int x = 0; x < bmp1.Width; x++)
|
||||
{
|
||||
if (bmp1.GetPixel(pixel) != bmp2.GetPixel(pixel))
|
||||
{
|
||||
different++;
|
||||
}
|
||||
|
||||
pixel++;
|
||||
}
|
||||
if (different > maxDiff)
|
||||
{
|
||||
return different + 10;
|
||||
}
|
||||
}
|
||||
return different;
|
||||
}
|
||||
|
||||
internal static int IsBitmapsAlike(NikseBitmap bmp1, Ocr.Binary.BinaryOcrBitmap bmp2)
|
||||
{
|
||||
int different = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user