OCRProcessor thread safety

Are instances of OCRProcessor thread safe - can a single instance be shared among multiple threads? Or does each thread need its own instance?
I'm looking at this from a C# perspective if that makes a difference.

3 Replies 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team March 26, 2021 11:46 AM UTC

Hi Josh,   
  
Thank you for contacting Syncfusion support.   
  
The OCR processor is thread safe and single instance can be shared among the multiple threads. Please refer the below code snippet for more details,   
  
string[] files = Directory.GetFiles(@"../../Data");  
  
//Initialize the OCR processor by providing the path of tesseract binaries(SyncfusionTesseract.dll and liblept168.dll)  
OCRProcessor processor = new OCRProcessor(@"../../Tesseract Binaries/");  
  
Parallel.For(0, files.Length, (i, loopstate) =>  
{  
  
    //Load a PDF document  
    PdfLoadedDocument lDoc = new PdfLoadedDocument(files[i]);  
  
    //Set OCR language to process  
    processor.Settings.Language = Languages.English;  
  
    //Process OCR by providing the PDF document and Tesseract data  
    string str = processor.PerformOCR(lDoc, @"../../Tessdata/"true);  
  
    string name = Guid.NewGuid().ToString();  
  
    lDoc.Save(name + ".pdf");  
    lDoc.Close(true);  
});  
  
Please let us know if you need any further assistance on this.   
  
Regards,  
Sowmiya Loganathan  
 


Marked as answer

JB Josh Bu March 26, 2021 12:31 PM UTC

Thanks Sowmiya.  I'm just surprised since OCRProcessor seems to have several member variables it uses.


SL Sowmiya Loganathan Syncfusion Team March 29, 2021 12:14 PM UTC

Hi Josh,   
  
Thank you for the update. Please let us know if you need any further assistance on this.   
  
Regards,  
Sowmiya Loganathan 


Loader.
Up arrow icon