Closed GoogleCodeExporter closed 8 years ago
could u show me a sample script to demonstrate your problem?
Original comment by FreeT...@gmail.com
on 7 Dec 2013 at 2:43
OK, here's the wrapper I use around Tesseract's API:
-----8<-----
# this is the bare wrapper around Tesseract recognition. May be used
# with pages, blocks, lines, or words depending on the mode
def tess_read_text(image, mode=tesseract.PSM_SINGLE_BLOCK):
numbers = "0123456789"
punct = "/.,#$@()*<>:-=%&"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = "abcdefghijklmnopqrstuvwxyz"
api = tesseract.TessBaseAPI()
api.Init(".", "eng", tesseract.OEM_DEFAULT)
api.SetVariable("tessedit_char_whitelist", upper + lower + numbers + punct)
api.SetVariable("assume_fixed_pitch_char_segment", "1")
api.SetPageSegMode(mode)
api.ClearAdaptiveClassifier()
work = cv.copyMakeBorder(image, 30, 30, 30, 30, cv.BORDER_CONSTANT, value=(255,255,255))
height1, width1 = work.shape
new_image = cv.cv.CreateImageHeader((width1,height1), cv.IPL_DEPTH_8U, 1)
cv.cv.SetData(new_image, work.tostring(), work.dtype.itemsize * (width1))
tesseract.SetCvImage(new_image, api)
text = api.GetUTF8Text().strip()
conf = get_word_confidences(api, text) # wrapper around AllWordConfidences()
wordinfo = api.GetWords(None)
print "text:", text
print "word confidences:", conf
print "word info:", type(wordinfo), wordinfo
return (text, zip(text.split(' '), conf))
-----8<-----
And here's some output from that bit of code:
text: FULTON
word confidences: [('FULTON', 83)]
word info: <type 'SwigPyObject'> <Swig Object of type 'Boxa *' at 0x2357900>
So what am I supposed to do with that SWIG-wrapped Boxa *? It doesn't have any
useful methods defined, nor any SwIG helpers I can find. I'd like to get out
the box coordinates in the array.
Original comment by wsgrib...@gmail.com
on 10 Dec 2013 at 4:19
??? conf = get_word_confidences(api, text) # wrapper around
AllWordConfidences()
should be
conf=api.MeanTextConf()
pls refer to example 3
Original comment by FreeT...@gmail.com
on 3 May 2014 at 6:22
MeanTextConf is not a replacement for AllWordConfidences. In my case it is
important to know the confidence for each recognized word, not for the entire
block as an aggregate.
Original comment by wsgrib...@gmail.com
on 4 May 2014 at 1:20
try this
import cv2.cv as cv
import tesseract
api = tesseract.TessBaseAPI()
api.Init(".","eng",tesseract.OEM_DEFAULT)
api.SetPageSegMode(tesseract.PSM_AUTO)
image=cv.LoadImage("eurotext.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
tesseract.SetCvImage(image,api)
text=api.GetUTF8Text()
conf=api.MeanTextConf()
print text,len(text)
print "Cofidence Level: %d %%"%conf
print "Confidences of All word"
confOfText=api.AllWordConfidences()
confOfText=tesseract.intArray_frompointer(confOfText)
for i in range(len(text)):
print i,confOfText[i]
Original comment by FreeT...@gmail.com
on 4 May 2014 at 7:22
[deleted comment]
You might need to compile the svn version of python tesseract.
Original comment by FreeT...@gmail.com
on 4 May 2014 at 7:26
Done!
Original comment by FreeT...@gmail.com
on 4 May 2014 at 11:49
Attachments:
Original comment by FreeT...@gmail.com
on 9 May 2014 at 7:49
Original issue reported on code.google.com by
wsgrib...@gmail.com
on 5 Dec 2013 at 7:21