Skip to content

Commit

Permalink
Remove tempFolder from TesseractOcrEngine constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Dec 29, 2023
1 parent 8e21493 commit f66d30b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions NAPS2.Lib/Modules/CommonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ protected override void Load(ContainerBuilder builder)
: NativeLibrary.FindExePath(PlatformCompat.System.TesseractExecutableName);
var engine = new TesseractOcrEngine(
tesseractPath,
ctx.Resolve<TesseractLanguageManager>().TessdataBasePath,
Paths.Temp);
ctx.Resolve<TesseractLanguageManager>().TessdataBasePath);
var errorOutput = ctx.Resolve<ErrorOutput>();
engine.OcrError += (_, args) => errorOutput.DisplayError(SdkResources.OcrError, args.Exception);
engine.OcrTimeout += (_, _) => errorOutput.DisplayError(SdkResources.OcrTimeout);
Expand Down
2 changes: 1 addition & 1 deletion NAPS2.Sdk.Tests/ContextualTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void SetUpOcr()
CopyResourceToFile(BinaryResources.eng_traineddata, fast, "eng.traineddata");
CopyResourceToFile(BinaryResources.heb_traineddata, fast, "heb.traineddata");
ScanningContext.OcrEngine =
new TesseractOcrEngine(tesseractPath, FolderPath, FolderPath);
new TesseractOcrEngine(tesseractPath, FolderPath);
}

public void SetUpFakeOcr() => SetUpFakeOcr(new());
Expand Down
6 changes: 2 additions & 4 deletions NAPS2.Sdk/Ocr/TesseractOcrEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ public class TesseractOcrEngine : IOcrEngine
{
private readonly string _tesseractPath;
private readonly string? _languageDataBasePath;
private readonly string _tempFolder;

public TesseractOcrEngine(string tesseractPath, string? languageDataBasePath, string tempFolder)
public TesseractOcrEngine(string tesseractPath, string? languageDataBasePath = null)
{
_tesseractPath = tesseractPath;
_languageDataBasePath = languageDataBasePath;
_tempFolder = tempFolder;
}

public async Task<OcrResult?> ProcessImage(ScanningContext scanningContext, string imagePath, OcrParams ocrParams,
CancellationToken cancelToken)
{
var logger = scanningContext.Logger;
string tempHocrFilePath = Path.Combine(_tempFolder, Path.GetRandomFileName());
string tempHocrFilePath = Path.Combine(scanningContext.TempFolderPath, Path.GetRandomFileName());
string tempHocrFilePathWithExt = tempHocrFilePath + ".hocr";
try
{
Expand Down

0 comments on commit f66d30b

Please sign in to comment.