Extract text from image and save txt file

Asked by Silvio Tadeu on 2018-04-11

Please,
My code:

import os
import shutil
import unittest
import time
import sys
import HTMLTestRunner

click (image) # whith the name: fone.png

from uuid import uuid4
folder_name = str(uuid4())
os.makedirs(folder_name)
with open("c:/CEx3 - ImagemCartao\SKL3.sikuli/teste.txt".format(fn=folder_name),'wb') as f:
    f.write(image_to_string(img1))

But the Sikuli show-me the error: [error] Error caused by: Traceback (most recent call last): File "C:\CEx3 - ImagemCartao\SKL3.sikuli\SKL3.py", line 42, in <module> f.write(image_to_string(img1)) NameError: name 'image_to_string' is not defined

The sikuli created the file : teste.txt but is clear!.

Thank's for all

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-04-12
Last reply:
2018-04-12
RaiMan (raimund-hocke) said : #1

As Jython/SikuliX I cannot see, where a function image_to_string() is defined.

Some imports missing?

Silvio Tadeu (staulik) said : #2

Sorry, have you an example from my script?.. I'm starting in Sikuli..

Thank you

RaiMan (raimund-hocke) said : #3

I do not have an example of your script, I can only see, what you have posted.

Where did you get the snippet then? Is it really complete or only an example?

Silvio Tadeu (staulik) said : #4

Hi Raiman this part is a example, but I tried to use!. Do you have any exemple?.

my class are

import os
import shutil
import unittest
import time
import sys
import HTMLTestRunner

from uuid import uuid4
folder_name = str(uuid4())
os.makedirs(folder_name)
with open("c:/CEx3 - ImagemCartao\SKL3.sikuli/teste.txt".format(fn=folder_name),'wb') as f:
    f.write(image_to_string(img1))

RaiMan (raimund-hocke) said : #5

someRegion = selectRegion()
textRead = someRegion.text()
print "textRead:", textRead

please read the docs.

Silvio Tadeu (staulik) said : #6

Nothing works right on it !!. Write in excel, capture the character of an image and save to a text file .. My good ..

Can you help with this problem?

Provide an answer of your own, or ask Silvio Tadeu for more information if necessary.

To post a message you must log in.