Hi Zendko,
I am facing segmentation fault after calling the readImage method hundreds
of times in a script.
Please help me resolving this ..
Error:
Error in pixRemoveColormap: pixs must be {1,2,4,8} bpp
Error in pixGetDepth: pix not defined
Error in pixGetWpl: pix not defined
Please call SetImage before attempting recognition.Segmentation fault
Code Snippet:
def
readImage(filename,frac=0,xTopFrac=1,yTopFrac=1,xBottomFrac=1,yBottomFrac=1):
result_text = ""
#Initialize the Tesseract API
api = tesseract.TessBaseAPICreate()
rc = tesseract.TessBaseAPIInit3(api, TESSDATA_PREFIX, lang);
if (rc):
tesseract.TessBaseAPIDelete(api)
logging.error("Could not initialize tesseract.\n")
raise Exception("Could not initialize tesseract.")
if(frac == 0):
logging.debug("No Focusing required")
#Get the ext from Image
text_out = tesseract.TessBaseAPIProcessPages(api, filename, None ,
0);
result_text = ctypes.string_at(text_out)
else :
logging.debug("Focus Required. Fractions passed")
logging.debug(xTopFrac+" "+yTopFrac+" "+xBottomFrac+" "+yBottomFrac)
#Get the Image height and Width
pix_image = leptonica.pixRead(filename)
x = leptonica.pixGetWidth(pix_image)
y = leptonica.pixGetHeight(pix_image)
logging.debug("Image width: " + str(x))
logging.debug("Image height: " + str(y))
tesseract.TessBaseAPISetImage2(api, pix_image)
#Setting origin (xPoint,yPoint ) and width and height
xPoint = int(float(Fraction(xTopFrac)*x))
yPoint = int(float(Fraction(yTopFrac)*y))
width = int(float(Fraction(xBottomFrac)*x)) - xPoint
height = int(float(Fraction(yBottomFrac)*y)) - yPoint
logging.debug("Origin : ")
logging.debug(str(xPoint)+" "+str(yPoint))
logging.debug("Width & Height :")
logging.debug(str(width)+" "+str(height))
#Setting the rectangle
tesseract.TessBaseAPISetRectangle(api,xPoint,yPoint,width-1,height-1)
#get the text
text_out = tesseract.TessBaseAPIGetUTF8Text(api)
result_text = ctypes.string_at(text_out)
tesseract.TessBaseAPIDelete(api)
logging.debug("Result Text : "+result_text)
return result_text
Thanks,
Sneha
On Fri, Dec 6, 2013 at 12:26 AM, zdenko podobny <[email protected]> wrote:
> You need to use leptonica (e.g. via ctypes, but there is also python
> module pylepthonica).
>
> Modify relevant part of script with something like this:
>
>
> lep = ctypes.cdll.LoadLibrary("liblept.so")
> pix_image = lep.pixRead(filename)print "image width:",
> lep.pixGetWidth(pix_image)print "image height:", lep.pixGetHeight(pix_image)
>
> tesseract.TessBaseAPISetImage2(api, pix_image)
> tesseract.TessBaseAPISetRectangle(api, 30, 60, 400, 100)
> text_out = tesseract.TessBaseAPIGetUTF8Text(api)
> result_text = ctypes.string_at(text_out)print result_text
>
>
> Zdenko
>
>
> On Thu, Dec 5, 2013 at 10:34 AM, Sneha Murganoor <[email protected]>wrote:
>
>> Hi Zdenko,
>>
>> how to get size of image and set recognition to a sub-rectangle of the
>> image in this?
>>
>> Thanks,
>> Sneha
>>
>>
>> On Wed, Dec 4, 2013 at 11:18 AM, Sneha Murganoor <[email protected]>wrote:
>>
>>> Zdenko,
>>>
>>> It is just excellent. It works very well. Thank you.
>>>
>>> Thanks,
>>> Sneha
>>>
>>>
>>> On Wed, Nov 20, 2013 at 6:59 PM, Nick White <[email protected]>wrote:
>>>
>>>> Hi Zdenko,
>>>>
>>>> On Wed, Nov 20, 2013 at 02:19:07PM +0100, zdenko podobny wrote:
>>>> > Anyway you can use tesseract 3.02.02 in python via ctypes - see
>>>> example[1]
>>>> >
>>>> > [1]
>>>> https://code.google.com/p/tesseract-ocr/source/browse/trunk/contrib/
>>>> > tesseract-c_api-demo.py?r=903
>>>>
>>>> That's neat, I hadn't seen python's ctypes before! Any chance you
>>>> could add that (or a link to it) to the APIExample wiki page?
>>>>
>>>> Nick
>>>>
>>>> --
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "tesseract-ocr" group.
>>>> To post to this group, send email to [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/tesseract-ocr?hl=en
>>>>
>>>> ---
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "tesseract-ocr" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/tesseract-ocr/tfi9RrPk3_E/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "tesseract-ocr" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/tesseract-ocr?hl=en
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "tesseract-ocr" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "tesseract-ocr" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/tesseract-ocr?hl=en
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "tesseract-ocr" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/tesseract-ocr/tfi9RrPk3_E/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
--
You received this message because you are subscribed to the Google
Groups "tesseract-ocr" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tesseract-ocr?hl=en
---
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.