Home » c# » How to properly build a project in C# to include tessnet2?-Exceptionshub

How to properly build a project in C# to include tessnet2?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment


I created a Windows Form App in Visual Studio 2019 that utilizes the scanner attached on the local machine, and then extract the text from it then display the text on any web app thru a web socket. App runs as expected by clicking Start on the interface of visual studio.

But when I try to create a Setup Project, install it in a computer, the app was unable to use the tessnet2. It does not extract the text, it just displays its preview.

Here’s a code snippet on how I implemented it:

 if (img != null) {
   TempFileCollection tfc = new TempFileCollection("tempDir", false);
   string tempFile = tfc.AddExtension("png");
   img.Save(tempFile, ImageFormat.Png);;
   Console.WriteLine("Image Save");

   try {

     var image = new Bitmap(tempFile);
     var ocr = new Tesseract();

     ocr.Init(@ ".\tessdata", "eng", false);
     List < tessnet2.Word > result = ocr.DoOCR(image, Rectangle.Empty);

     //Obtain the texts from OCR result
     String[] texts = result.ConvertAll < String > (delegate(Word w) {
       return w.Text;
     String Result = String.Join(" ", texts);

     foreach(var socket in allSockets.ToList()) {
       PlatformInfo.Current.Log.Info("extracted text sent");

     PlatformInfo.Current.Log.Info("Tempfile deleted");

   } catch (Exception exception) {
     Console.WriteLine("error dude");

Here is also a screenshot of the project structure.
enter image description here

How to&Answers: