2using System.Collections.Generic;
5using System.Reflection;
1210 Canadian_Aboriginal,
1352 this.Prefix = prefix;
1353 this.Language = language;
1362 if (fileName.EndsWith(
".traineddata"))
1364 fileName = Path.GetFullPath(fileName);
1366 this.Prefix = Path.GetDirectoryName(fileName);
1367 this.Language = Path.GetFileName(fileName).Substring(0, Path.GetFileName(fileName).Length - 12);
1371 this.Prefix = Path.GetTempPath();
1372 this.Language = Guid.NewGuid().ToString(
"N");
1374 File.Copy(fileName, Path.Combine(
this.Prefix,
this.Language +
".traineddata"));
1379 private static readonly
string ExecutablePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
1380 private static readonly
string LocalCachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
1389 string languageName = language.ToString().ToLower();
1391 string prefix =
null;
1393 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"fast", languageName +
".traineddata")))
1395 prefix = Path.Combine(ExecutablePath,
"tessdata",
"fast");
1397 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"fast", languageName +
".traineddata")))
1399 prefix = Path.Combine(ExecutablePath,
"fast");
1401 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"fast", languageName +
".traineddata")))
1403 prefix = Path.Combine(LocalCachePath,
"tessdata",
"fast");
1405 else if (useAnyCached)
1407 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath, languageName +
".traineddata")))
1409 prefix = Path.Combine(ExecutablePath);
1411 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"best", languageName +
".traineddata")))
1413 prefix = Path.Combine(ExecutablePath,
"tessdata",
"best");
1415 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"best", languageName +
".traineddata")))
1417 prefix = Path.Combine(ExecutablePath,
"best");
1419 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"best", languageName +
".traineddata")))
1421 prefix = Path.Combine(LocalCachePath,
"tessdata",
"best");
1427 string remotePath =
"https://github.com/tesseract-ocr/tessdata_fast/raw/main/" + languageName +
".traineddata";
1429 string localDirectory = Path.Combine(LocalCachePath,
"tessdata",
"fast");
1431 if (!Directory.Exists(localDirectory))
1433 Directory.CreateDirectory(localDirectory);
1436 using (WebClient client =
new WebClient())
1438 client.DownloadFile(remotePath, Path.Combine(localDirectory, languageName +
".traineddata"));
1441 prefix = localDirectory;
1444 this.Prefix = prefix;
1445 this.Language = languageName;
1455 string languageName = language.ToString().ToLower();
1457 string prefix =
null;
1459 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"best", languageName +
".traineddata")))
1461 prefix = Path.Combine(ExecutablePath,
"tessdata",
"best");
1463 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"best", languageName +
".traineddata")))
1465 prefix = Path.Combine(ExecutablePath,
"best");
1467 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"best", languageName +
".traineddata")))
1469 prefix = Path.Combine(LocalCachePath,
"tessdata",
"best");
1471 else if (useAnyCached)
1473 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath, languageName +
".traineddata")))
1475 prefix = Path.Combine(ExecutablePath);
1477 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"fast", languageName +
".traineddata")))
1479 prefix = Path.Combine(ExecutablePath,
"tessdata",
"fast");
1481 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"fast", languageName +
".traineddata")))
1483 prefix = Path.Combine(ExecutablePath,
"fast");
1485 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"fast", languageName +
".traineddata")))
1487 prefix = Path.Combine(LocalCachePath,
"tessdata",
"fast");
1493 string remotePath =
"https://github.com/tesseract-ocr/tessdata_best/raw/main/" + languageName +
".traineddata";
1495 string localDirectory = Path.Combine(LocalCachePath,
"tessdata",
"best");
1497 if (!Directory.Exists(localDirectory))
1499 Directory.CreateDirectory(localDirectory);
1502 using (WebClient client =
new WebClient())
1504 client.DownloadFile(remotePath, Path.Combine(localDirectory, languageName +
".traineddata"));
1507 prefix = localDirectory;
1510 this.Prefix = prefix;
1511 this.Language = languageName;
1521 string languageName = script.ToString().Replace(
"_Vert",
"_vert");
1523 string prefix =
null;
1525 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"fast",
"script", languageName +
".traineddata")))
1527 prefix = Path.Combine(ExecutablePath,
"tessdata",
"fast",
"script");
1529 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"fast",
"script", languageName +
".traineddata")))
1531 prefix = Path.Combine(ExecutablePath,
"fast",
"script");
1533 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"fast",
"script", languageName +
".traineddata")))
1535 prefix = Path.Combine(LocalCachePath,
"tessdata",
"fast",
"script");
1537 else if (useAnyCached)
1539 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"script", languageName +
".traineddata")))
1541 prefix = Path.Combine(ExecutablePath,
"script");
1543 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath, languageName +
".traineddata")))
1545 prefix = Path.Combine(ExecutablePath);
1547 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"best",
"script", languageName +
".traineddata")))
1549 prefix = Path.Combine(ExecutablePath,
"tessdata",
"best",
"script");
1551 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"best",
"script", languageName +
".traineddata")))
1553 prefix = Path.Combine(ExecutablePath,
"best",
"script");
1555 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"best",
"script", languageName +
".traineddata")))
1557 prefix = Path.Combine(LocalCachePath,
"tessdata",
"best",
"script");
1563 string remotePath =
"https://github.com/tesseract-ocr/tessdata_fast/raw/main/script/" + languageName +
".traineddata";
1565 string localDirectory = Path.Combine(LocalCachePath,
"tessdata",
"fast",
"script");
1567 if (!Directory.Exists(localDirectory))
1569 Directory.CreateDirectory(localDirectory);
1572 using (WebClient client =
new WebClient())
1574 client.DownloadFile(remotePath, Path.Combine(localDirectory, languageName +
".traineddata"));
1577 prefix = localDirectory;
1580 this.Prefix = prefix;
1581 this.Language = languageName;
1591 string languageName = script.ToString().Replace(
"_Vert",
"_vert");
1593 string prefix =
null;
1595 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"best",
"script", languageName +
".traineddata")))
1597 prefix = Path.Combine(ExecutablePath,
"tessdata",
"best",
"script");
1599 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"best",
"script", languageName +
".traineddata")))
1601 prefix = Path.Combine(ExecutablePath,
"best",
"script");
1603 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"best",
"script", languageName +
".traineddata")))
1605 prefix = Path.Combine(LocalCachePath,
"tessdata",
"best",
"script");
1607 else if (useAnyCached)
1609 if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"script", languageName +
".traineddata")))
1611 prefix = Path.Combine(ExecutablePath,
"script");
1613 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath, languageName +
".traineddata")))
1615 prefix = Path.Combine(ExecutablePath);
1617 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"tessdata",
"fast",
"script", languageName +
".traineddata")))
1619 prefix = Path.Combine(ExecutablePath,
"tessdata",
"fast",
"script");
1621 else if (!
string.IsNullOrEmpty(ExecutablePath) && File.Exists(Path.Combine(ExecutablePath,
"fast",
"script", languageName +
".traineddata")))
1623 prefix = Path.Combine(ExecutablePath,
"fast",
"script");
1625 else if (File.Exists(Path.Combine(LocalCachePath,
"tessdata",
"fast",
"script", languageName +
".traineddata")))
1627 prefix = Path.Combine(LocalCachePath,
"tessdata",
"fast",
"script");
1633 string remotePath =
"https://github.com/tesseract-ocr/tessdata_best/raw/main/script/" + languageName +
".traineddata";
1635 string localDirectory = Path.Combine(LocalCachePath,
"tessdata",
"best",
"script");
1637 if (!Directory.Exists(localDirectory))
1639 Directory.CreateDirectory(localDirectory);
1642 using (WebClient client =
new WebClient())
1644 client.DownloadFile(remotePath, Path.Combine(localDirectory, languageName +
".traineddata"));
1647 prefix = localDirectory;
1650 this.Prefix = prefix;
1651 this.Language = languageName;
Represents a language used by Tesseract OCR.
Fast
Fast integer versions of trained models. These are models for a single language.
BestScripts
Best (most accurate) trained models. These are models for a single script supporting one or more lang...
TesseractLanguage(FastScripts script, bool useAnyCached=false)
Create a new TesseractLanguage object using a fast integer version of a trained model for the specifi...
TesseractLanguage(BestScripts script, bool useAnyCached=false)
Create a new TesseractLanguage object using the best (most accurate) version of the trained model for...
TesseractLanguage(Best language, bool useAnyCached=false)
Create a new TesseractLanguage object using the best (most accurate) version of the trained model for...
TesseractLanguage(string prefix, string language)
Create a new TesseractLanguage object using the provided prefix and language name,...
Best
Best (most accurate) trained models. These are models for a single language.
string Prefix
The name of the folder where the language file is located.
TesseractLanguage(Fast language, bool useAnyCached=false)
Create a new TesseractLanguage object using a fast integer version of a trained model for the specifi...
TesseractLanguage(string fileName)
Create a new TesseractLanguage object using the specified trained model data file.
string Language
The name of the language. The Tesseract library will assume that the trained language data file can b...
FastScripts
Fast integer versions of trained models. These are models for a single script supporting one or more ...