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(); }
private void videoPanel_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.C) { string image_path = curr_dir + @"\recog.jpg"; string config_path = curr_dir + @"\smartid.json"; string document_types = "rus.passport.*"; engine = new RecognitionEngine(config_path); settings = engine.CreateSessionSettings(); settings.AddEnabledDocumentTypes(document_types); session = engine.SpawnSession(settings, reporter); Capture(); } else if (e.KeyCode == Keys.F) { string image_path = curr_dir + @"\recog.jpg"; byte[] im_bt = FileToByteArray(image_path); Bitmap d_image = (Bitmap)System.Drawing.Image.FromFile(image_path); int w = d_image.Width; int h = d_image.Height; BitmapData bitmapData = d_image.LockBits(new System.Drawing.Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, d_image.PixelFormat); int ByteCount = bitmapData.Stride * h; byte[] Pixels = new byte[ByteCount]; int bitsPerPixel = ((int)bitmapData.PixelFormat & 0xff00) >> 8; int bytesPerPixel = (bitsPerPixel + 7) / 8; int stride = 4 * ((w * bytesPerPixel + 3) / 4); //указатель на первый пиксель IntPtr ptrFirstPixel = bitmapData.Scan0; //копируем данные из указателя в массив байтов Marshal.Copy(ptrFirstPixel, Pixels, 0, Pixels.Length); get_recog(Pixels, Pixels.Length, w, h, stride); } //Application.Exit(); }