Update ScreenMatch.cs

This commit is contained in:
Namhyeon Go 2024-09-04 13:26:20 +09:00
parent 87d785df45
commit ca7b7ad3d5
4 changed files with 15 additions and 10 deletions

6
.gitmodules vendored
View File

@ -1,3 +1,9 @@
[submodule "app/assets/tessdata"]
path = app/assets/tessdata
url = https://github.com/tesseract-ocr/tessdata
[submodule "app/assets/tessdata_best"]
path = app/assets/tessdata_best
url = https://github.com/tesseract-ocr/tessdata_best
[submodule "app/assets/tessdata_fast"]
path = app/assets/tessdata_fast
url = https://github.com/tesseract-ocr/tessdata_fast

View File

@ -111,7 +111,7 @@ public class ScreenMatch
private string mode;
private List<string> _params = new List<string>();
private bool isSearchFromEnd = false;
private byte thresholdConvertToBinary = 255;
private byte thresholdConvertToBinary = 191;
private bool isSaveToFile = false;
private bool isMatching = false;
private bool isOCR128 = false;
@ -162,7 +162,7 @@ public class ScreenMatch
if (_params.Contains("ocr128"))
{
tesseractDataPath = Path.Combine(workingDirectory, "assets/tessdata");
tesseractDataPath = Path.Combine(workingDirectory, "app/assets/tessdata_best");
tesseractLanguage = "eng";
isOCR128 = true;
this.parent.Log("Use OCR within a 128x128 pixel range around specific coordinates.");
@ -360,14 +360,12 @@ public class ScreenMatch
Rectangle cropArea = new Rectangle(cropX, cropY, cropWidth, cropHeight);
// Crop image
Bitmap croppedBitmap = bitmap.Clone(cropArea, bitmap.PixelFormat);
Bitmap croppedBitmap = ConvertToBinary(bitmap.Clone(cropArea, bitmap.PixelFormat), thresholdConvertToBinary);
// OCR
using (var engine = new TesseractEngine(tesseractDataPath, tesseractLanguage, EngineMode.Default))
{
using (var img = PixConverter.ToPix(croppedBitmap))
{
using (var page = engine.Process(img))
using (var page = engine.Process(croppedBitmap))
{
text = page.GetText();
@ -375,7 +373,6 @@ public class ScreenMatch
parent.Log($"Text (GetText): {text}");
}
}
}
return text;
}

@ -0,0 +1 @@
Subproject commit e12c65a915945e4c28e237a9b52bc4a8f39a0cec

@ -0,0 +1 @@
Subproject commit 87416418657359cb625c412a48b6e1d6d41c29bd