示例#1
0
        public void get_recog(byte[] p_bt, int p_len, int w, int h, int p_stride)
        {
            try
            {
                se.smartid.Image sm_img = new se.smartid.Image(p_bt, (uint)Math.Abs(p_stride) * 3, w, h, Math.Abs(p_stride), 3);
                recog_result = session.ProcessImage(sm_img);
            }
            catch (Exception e)
            {
                MessageBox.Show("Error " + e);
            }

            if (recog_result.IsTerminal() || cnt >= cnt_recog)
            {
                if (File.Exists(curr_dir + @"\recognize.log"))
                {
                    File.Delete(curr_dir + @"\recognize.log");
                }

                System.IO.FileStream ostrm = new FileStream(curr_dir + @"\recognize.log", FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter         writer;
                TextWriter           oldOut = Console.Out;

                writer = new StreamWriter(ostrm);
                Console.SetOut(writer);

                Console.WriteLine("Start recognize application");
                Console.WriteLine("--------------------------------");

                reporter = new CsReporter();

                // this is important: GC works differently with native-heap objects
                OutputRecognitionResult(recog_result);

                recog_result.Dispose();
                session.Dispose();
                engine.Dispose();
                reporter.Dispose();

                Console.WriteLine("End application!");
                Console.SetOut(oldOut);

                writer.Close();
                ostrm.Close();
                destroy();
            }
            else
            {
                cnt++;
                pBar.PerformStep();
                Capture();
            }
        }
示例#2
0
        public void get_recog()
        {
            System.IO.FileStream ostrm = new FileStream(curr_dir + @"\recognize.log", FileMode.OpenOrCreate, FileAccess.Write);
            string image_path          = curr_dir + @"\recog.jpg";
            string config_path         = curr_dir + @"\smartid.json";
            string document_types      = "rus.passport.*";

            StreamWriter writer;
            TextWriter   oldOut = Console.Out;

            writer = new StreamWriter(ostrm);
            Console.SetOut(writer);

            Console.WriteLine("Start recognize application");
            Console.WriteLine("--------------------------------");
            Console.WriteLine("image_path = {0}", image_path);
            Console.WriteLine("config_path = {0}", config_path);
            Console.WriteLine("document_types = {0}", document_types);

            try
            {
                CsReporter reporter = new CsReporter();

                var             engine   = new RecognitionEngine(config_path);
                SessionSettings settings = engine.CreateSessionSettings();
                settings.AddEnabledDocumentTypes(document_types);
                RecognitionSession session      = engine.SpawnSession(settings, reporter);
                RecognitionResult  recog_result = session.ProcessImageFile(image_path);

                OutputRecognitionResult(recog_result);

                recog_result.Dispose();
                session.Dispose();
                engine.Dispose();
                reporter.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught: {0}", e);
            }

            Console.WriteLine("End application!");
            Console.SetOut(oldOut);
            writer.Close();
            ostrm.Close();
        }