Пример #1
0
        public void TestSimple()
        {
            Global.SetEnv("debug", Global.GetEnv("debug") + "");
            // image file name to recognize
            string imgFileName           = "line.png";
            string imgCsegFileName       = "line.cseg.png";
            string imgTranscriptFileName = "line.txt";

            // line recognizer
            Linerec lrec = (Linerec)Linerec.LoadLinerec("default.model");

            //Linerec lrec = (Linerec)Linerec.LoadLinerec("2m2-reject.cmodel");
            //Linerec lrec = (Linerec)Linerec.LoadLinerec("multi3.cmodel");
            //Linerec lrec = (Linerec)Linerec.LoadLinerec("latin-ascii.model");
            lrec.Info();

            // language model
            OcroFST default_lmodel = OcroFST.MakeOcroFst();

            default_lmodel.Load("default.fst");
            OcroFST lmodel = default_lmodel;

            // read image
            Bytearray image = new Bytearray(1, 1);

            ImgIo.read_image_gray(image, imgFileName);

            // recognize!
            OcroFST  fst  = OcroFST.MakeOcroFst();
            Intarray rseg = new Intarray();

            lrec.RecognizeLine(rseg, fst, image);

            // show result 1
            string resStr;

            fst.BestPath(out resStr);
            Console.WriteLine("Fst BestPath:   {0}", resStr);

            // find result 2
            Intarray   v1   = new Intarray();
            Intarray   v2   = new Intarray();
            Intarray   inp  = new Intarray();
            Intarray   outp = new Intarray();
            Floatarray c    = new Floatarray();

            BeamSearch.beam_search(v1, v2, inp, outp, c, fst, lmodel, 100);

            FstUtil.remove_epsilons(out resStr, outp);
            Console.WriteLine("Fst BeamSearch: {0}", resStr);

            Intarray cseg = new Intarray();

            SegmRoutine.rseg_to_cseg(cseg, rseg, inp);
            SegmRoutine.make_line_segmentation_white(cseg);
            ImgLabels.simple_recolor(cseg); // for human readable
            ImgIo.write_image_packed(imgCsegFileName, cseg);
            File.WriteAllText(imgTranscriptFileName, resStr.Replace(" ", ""));
        }
Пример #2
0
        private void DoTestLinerecRecognize(Linerec linerec, string bookPath, string filename)
        {
            Bytearray image = new Bytearray();

            ImgIo.read_image_gray(image, bookPath + filename);
            // recognize!
            OcroFST fst = OcroFST.MakeOcroFst();

            linerec.RecognizeLine(fst, image);
            // show result
            string resStr;

            fst.BestPath(out resStr);
            Console.WriteLine("Fst BestPath:   {0}", resStr);
        }