tvn-cosine / tesseract.net

a .net wrapper for Tesseract
GNU General Public License v3.0
24 stars 13 forks source link

AccessViolationException on DetectOrientationScript #19

Open ColdenHaulfield opened 6 years ago

ColdenHaulfield commented 6 years ago

Hey, have this exception when trying run this code. Can you help me?

TessBaseAPI tessBaseAPI = new TessBaseAPI(); tessBaseAPI.Init(System.IO.Path.Combine(Directory.GetCurrentDirectory(), "tessdata"), "rus", OcrEngineMode.DEFAULT); tessBaseAPI.SetPageSegMode(PageSegmentationMode.AUTO_ONLY);
Bitmap image = new Bitmap(path); MemoryStream byteStream = new MemoryStream(); image.Save(byteStream, System.Drawing.Imaging.ImageFormat.Tiff); var pix = Pix1.pixReadFromMemoryStream(byteStream);

        tessBaseAPI.SetImage(pix);
        tessBaseAPI.SetInputName(string.Empty);

        Tesseract.Orientation orientation;
        try
        {
            tessBaseAPI.DetectOrientationScript(out int orient_deg, out float orient_conf, out string script_name, out float script_conf);
        }
        catch (Exception ex)
        {
            string s = ex.Message;
        }
ColdenHaulfield commented 6 years ago

Switching PageSegmentationMode.AUTO_ONLY on OSD_ONLY and changing rus data on osd legacy data helps me

UPDATE. I was wrong and the change of PSM did not help. How can I detect the orientation of the image?

tvn-cosine commented 6 years ago

Will look into this

levpius commented 5 years ago

I am sure u may have moved on. I also was not able to use this with success. For me the function Orientation in the PageIterator worked "beautifully":

           tessBaseApi.SetImage(pix);
           Orientation orientation;
           WritingDirection direction;
           TextlineOrder order;
           float deskewAngle = 0;
            using (var pageIter = tessBaseApi2.AnalyseLayout())
            {
                pageIter.Begin();
                pageIter.Orientation(out orientation, out direction, out order, out deskewAngle);
           }