Thanks to pyocr 
<https://github.com/jflesch/pyocr/blob/master/src/pyocr/libtesseract/tesseract_raw.py>
 
I figured it out!

# ... /snip
# 
https://github.com/jflesch/pyocr/blob/master/src/pyocr/libtesseract/tesseract_raw.py
class OSResults(Structure):
    _fields_ = [
        ('orientations', c_float * 4),
        ('scripts_na', c_float * 4 * (116 + 1 + 2 + 1)),
        ('unicharset', c_void_p),
        ('best_orientation_id', c_int),
        ('best_script_id', c_int),
        ('best_sconfidence', c_float),
        ('best_oconfidence', c_float),
        ('padding', c_char_p * 512),
    ]

# ... /snip

def create_tess_api(prefix=TESSDATA_PREFIX, lang='eng'):
    # ... /snip
    tesseract.TessBaseAPIDetectOS.argtypes = [base_api, POINTER(OSResults)]
    tesseract.TessBaseAPIDetectOS.restype = c_bool
    # ... /snip

def get_orientation(tesseract, leptonica, api, path, mode=0):
    tesseract.TessBaseAPISetPageSegMode(api, mode)
    pix = leptonica.pixRead(path)
    tesseract.TessBaseAPISetImage2(api, pix)
    osr = OSResults()
    it = tesseract.TessBaseAPIDetectOS(api, byref(osr))

    if it and osr:
        orientation, direction, line_order = c_int(), c_int(), c_int()
        skew = c_float()

        tesseract.TessPageIteratorOrientation(
            it, byref(orientation), byref(direction), byref(line_order),
            byref(skew))

        print('%s: %s' % (path, osr.best_orientation_id))
        print('confidence: %s' % osr.best_oconfidence)




On Friday, May 20, 2016 at 7:18:09 PM UTC+3, Reuben Cummings wrote:
>
> I found some helpful code on the forum 
> <https://groups.google.com/d/msg/tesseract-ocr/g5aE_OvgyTU/4KRPdBgj3vAJ>:
>
> OSResults *orientationStruct = new OSResults();
> bool gotOrientation = myTess->DetectOS(orientationStruct);
> int bestOrientation = -1;
> float bestOrientationScore = 0;
>
> if ((gotOrientation) && (orientationStruct->orientations != NULL)) {
>     for (int i=0; i<4; i++) {
>         if (orientationStruct->orientations[i] > bestOrientationScore) {
>             bestOrientation = i;
>             bestOrientationScore = orientationStruct->orientations[i];
>         }
>     }
> }
>
> // This is the result we were asked for
> results.textOrientation = bestOrientation; 
>
>
> But unfortunately, OSResults 
> <https://zdenop.github.io/tesseract-doc/struct_o_s_results.html> isn't 
> implemented in the c-api. 
> <https://fossies.org/dox/tesseract-3.04.01/capi_8cpp.html#aae7d8f59b4757edde9afbdf64e649fb9>
>  
> Any suggestions?
>
>
>
> On Friday, May 20, 2016 at 9:32:36 AM UTC+3, Reuben Cummings wrote:
>>
>> If i try to run the script with psm mode=0 (like the executable) i dont 
>> get any results either. Further research has led me to the DetectOS 
>> function which seems useful.
>
>

-- 
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].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/8bf265dc-358b-4477-a5bb-02ab6059492b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to