示例#1
0
        public void TestArrays()
        {
            string imgfn = "test-c3.png";

            // load Bytearray
            Bytearray ba = new Bytearray(1, 1);

            ImgIo.read_image_gray(ba, imgfn);
            OcrRoutine.Invert(ba);
            //NarrayUtil.Sub((byte)255, image);
            byte[] bytes1 = ba.To1DArray();
            NarrayShow.ShowConsole(ba);
            StdInput linput1 = new StdInput(ba);

            Console.WriteLine();

            // load StdInput
            Bitmap   bitmap  = ImgIo.LoadBitmapFromFile(imgfn);
            StdInput linput2 = StdInput.FromBitmap(bitmap);
            //NarrayShow.ShowConsole(linput2);

            // test convert
            Floatarray fa      = linput2.ToFloatarray();
            StdInput   linput3 = new StdInput(fa);

            Console.WriteLine("Arrays is identical? {0}", Equals(linput1.GetDataBuffer(), linput2.GetDataBuffer()));
            Console.WriteLine("Arrays is identical? {0}", Equals(linput2.GetDataBuffer(), linput3.GetDataBuffer()));
        }
示例#2
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(" ", ""));
        }
示例#3
0
        public override bool GetLine(Bytearray image, int page, int line, string variant = null)
        {
            string s = PathFile(page, line, variant, "png");

            if (!File.Exists(s))
            {
                return(false);
            }
            ImgIo.read_image_gray(image, s);
            return(true);
        }
示例#4
0
        private void DoTestRecognize(LenetClassifier classifier)
        {
            OutputVector ov = new OutputVector();
            Floatarray   v  = new Floatarray();
            Bytearray    ba = new Bytearray(1, 1);

            ImgIo.read_image_gray(ba, testPngFileName);
            NarrayUtil.Sub(255, ba);
            v.Copy(ba);
            v /= 255.0;
            classifier.XOutputs(ov, v);
            Console.WriteLine("Featured output class '{0}', score '{1}'", (char)ov.Key(ov.BestIndex), ov.Value(ov.BestIndex));
        }
示例#5
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);
        }
示例#6
0
        static void Main(string[] args)
        {
            //MlpClassifier mlp = new MlpClassifier();

            /*OcroFST fst = OcroFST.MakeFst("OcroFST");
             * fst.Load("ocr-dict-case.fst");
             *
             * Console.WriteLine("{0} ({1})", fst.Name, fst.Interface);
             * Console.WriteLine("{0}..{1}", fst.GetStart(), fst.nStates());
             * fst.Save("test.fst");*/

            //TestDataSet ds = new TestDataSet();

            /*Console.WriteLine("Interface: {0}", ds.Interface);
             * Console.WriteLine("Name: {0}", ds.Name);
             * Console.WriteLine("Description: {0}", ds.Description);*/

            /*Console.WriteLine(String.Format("{0:X6}", 15));
             * DirPattern dpatt1 = new DirPattern("data2", @"[0-9][0-9][0-9][0-9]");
             * Console.WriteLine("Count: {0}", dpatt1.Length);
             * DirPattern dpatt2 = new DirPattern("data2", @"([0-9][0-9][0-9][0-9])\.png");
             * Console.WriteLine("Count: {0}", dpatt2.Length);
             *
             * Console.WriteLine("Exist: {0}",
             *  DirPattern.Exist("data2", @"[0-9][0-9][0-9][0-9]", @"([0-9][0-9][0-9][0-9][0-9][0-9])\.png"));*/

            //new TestBookStore().RunTest();


            Ocronet.Dynamic.Utils.Logger.Default.verbose = true;

            //new TestLenetWrapper().RunTest();
            //TestLenetClassifier testLenet = new TestLenetClassifier();
            //testLenet.TestArrays();
            //testLenet.TestSaveNetwork();
            //testLenet.TestRecognize();

            //new TestDataset().TestRowDataset();

            TestLinerec testLinerec = new TestLinerec();

            //testLinerec.TestSimple();
            //testLinerec.TestTrainLatinCseg();
            testLinerec.TestTrainLenetCseg();
            //testLinerec.TestRecognizeCseg();
            //testLinerec.TestComputeMissingCseg();
            //testLinerec.TestSimple();

            if (args.Length == 0)
            {
                Console.WriteLine("Usage: DynamicConsole.exe imagefile");
                return;
            }

            //args[0] = "scan1.png";
            //args[0] = "lenna.jpg";
            string fileNameWoExt = Path.GetFileNameWithoutExtension(args[0]);

            Bytearray image = new Bytearray(1, 1);

            //Intarray image = new Intarray(1, 1);
            ImgIo.read_image_gray(image, args[0]);
            Bytearray binimage  = new Bytearray(1, 1);
            Intarray  segmimage = new Intarray(1, 1);

            IBinarize binarizer = new BinarizeByOtsu();
            //binarizer.Set("k", 0.05);
            //binarizer.Set("w", 5);
            ISegmentLine segmenter = new DpSegmenter();

            binarizer.Binarize(binimage, image);
            ImgIo.write_image_gray(fileNameWoExt + ".bin.png", binimage);

            //new BinarizeByOtsu().Binarize(binimage, image);
            segmenter.Charseg(ref segmimage, binimage);
            ImgLabels.simple_recolor(segmimage);
            ImgIo.write_image_packed(fileNameWoExt + ".rseg.png", segmimage);
        }