Forum Discussion

Nikolayev's avatar
Nikolayev
Contributor
3 years ago
Solved

Using Tesseract-OCR in TestComplete

Hi SmartBear Community,

 

I Use Tesseract for OCR  texte recognition ,

It works very well with to generate the .TXT file.

 

When the .TXT file is created, I read it with this Python script : 

 

Path = "D:\\TESTOCR\\Text.txt"

myFile = aqFile.OpenBinaryFile(Path, aqFile.faRead)
Log.Message("Ligne 1: "+ myFile.ReadString(1))
Log.Message("Ligne 2: "+ myFile.ReadString(2))
Log.Message("Ligne 3: "+ myFile.ReadString(3))

 

In the .TXT file,  I have English sentences, and I don't understand why I Have this Chinese ones in the log  : 

 

 

Tesseract use UTF-8 , so it should works ! ðŸ¤”

Someone have any idea  ?

 

Thank you all !

 

 

  • It works, problem solved ! I have found with this method  :   

     

    sPath = "D:\\TESTOCR\\Text.txt"

    myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)

    lNum = myFile.LinesCount
    for i in range(0, lNum):

      curLine = myFile.Line + 1
      Log.Message("The " + str(curLine) + " line is:")

      Line = myFile.ReadLine()

      Log.Message(Line)

5 Replies

  • It works, problem solved ! I have found with this method  :   

     

    sPath = "D:\\TESTOCR\\Text.txt"

    myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)

    lNum = myFile.LinesCount
    for i in range(0, lNum):

      curLine = myFile.Line + 1
      Log.Message("The " + str(curLine) + " line is:")

      Line = myFile.ReadLine()

      Log.Message(Line)

    • Mr_Bro's avatar
      Mr_Bro
      Champion Level 0

      Nikolayev ,

       

      it would be good if you share the code snippet which you used for texte recognition using Tesseract

       

       

  • Mr_Bro  I send it to you in a private message. It is exactely the same snippet sample that you can find above ,  here it is again : 

    sPath = "D:\\TESTOCR\\Text.txt"

    myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctANSI)

    lNum = myFile.LinesCount
    for i in range(0, lNum):

      curLine = myFile.Line + 1
      Log.Message("The " + str(curLine) + " line is:")

      Line = myFile.ReadLine()

      Log.Message(Line) 

  • hi Mr_Bro ,  It is done I share the Python code, I can explain you in private message 😉

    • Mr_Bro's avatar
      Mr_Bro
      Champion Level 0

      Nikolayev , not yet received the sample, can you please paste the sample snippet here or resend it please