示例#1
0
        public PersonalDataVIZ ExtractMrzData(byte[] image)
        {
            pdv = new PersonalDataVIZ();
            try
            {
                File.WriteAllBytes(ConfigurationSettings.AppSettings["JavaReaderPath"] + "pass.jpeg", image);

                string        msgBack = string.Empty;
                bool          ok      = false;
                List <String> output  = new List <string>();
                Process       process = new Process();
                try
                {
                    process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.FileName               = "cmd.exe";
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError  = true;
                    process.StartInfo.WorkingDirectory       = ConfigurationSettings.AppSettings["JavaReaderPath"];
                    process.StartInfo.Arguments              = "/c \"" + "mrz pass.jpeg" + "\"";

                    process.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
                    {
                        if (e.Data != null)
                        {
                            output.Add((string)e.Data);
                        }
                    });
                    process.ErrorDataReceived += new DataReceivedEventHandler((s, e) =>
                    {
                        if (e.Data != null)
                        {
                            msgBack = msgBack + e.Data;
                        }
                    });

                    process.Start();
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();

                    process.WaitForExit();

                    ok = (process.ExitCode == 0);
                }
                catch (Exception ex)
                {
                    msgBack = ex.Message;
                }
                if (ok && string.IsNullOrEmpty(msgBack))
                {
                    string temp = string.Empty;
                    output.ForEach(new Action <string>(ParseMrzOcr)
                                   );
                    msgBack    = string.Empty;
                    pdv.Errors = msgBack;
                    return(pdv);
                }
                else
                {
                    pdv.Errors = msgBack;
                    return(pdv);
                }
            }
            catch (Exception ex)
            {
                throw new FaultException("Error analyzing MRZ: " + ex.Message);
            }
        }
示例#2
0
        private void ParseMrzOcr(string line)
        {
            if (pdv == null)
            {
                pdv = new PersonalDataVIZ();
            }
            if (line.StartsWith("number"))
            {
                pdv.DocumentNumber = line.Replace("number", "").Trim();
            }
            if (line.StartsWith("country"))
            {
                pdv.IssuuingCountry = line.Replace("country", "").Trim();
            }
            if (line.StartsWith("date_of_birth"))
            {
                pdv.DateOfBirth = line.Replace("date_of_birth", "").Trim();
            }
            if (line.StartsWith("expiration_date"))
            {
                pdv.ExpirationDate = line.Replace("expiration_date", "").Trim();
            }
            if (line.StartsWith("nationality"))
            {
                pdv.Citizenship = line.Replace("nationality", "").Trim();
            }
            if (line.StartsWith("sex"))
            {
                pdv.Sex = line.Replace("sex", "").Trim();
            }
            if (line.StartsWith("names"))
            {
                pdv.Firstname = line.Replace("names", "").Replace(">", "").Trim();

                pdv.Firstname = pdv.Firstname.Replace("<", " ");

                pdv.Firstname = pdv.Firstname.Trim();
            }

            if (line.StartsWith("surname"))
            {
                pdv.Lastname = line.Replace("surname", "").Replace(">", "").Trim();

                pdv.Lastname = pdv.Lastname.Replace("<", " ");

                pdv.Lastname = pdv.Lastname.Trim();
            }
            if (line.StartsWith("valid_number"))
            {
                if (line.Contains("True"))
                {
                    pdv.DocNumberChecksum = true;
                }
                if (line.Contains("False"))
                {
                    pdv.DocNumberChecksum = false;
                }
            }
            if (line.StartsWith("valid_date_of_birth"))
            {
                if (line.Contains("True"))
                {
                    pdv.DOBChecksum = true;
                }
                if (line.Contains("False"))
                {
                    pdv.DOBChecksum = false;
                }
            }
            if (line.StartsWith("valid_expiration_date"))
            {
                if (line.Contains("True"))
                {
                    pdv.ExpirationChecksum = true;
                }
                if (line.Contains("False"))
                {
                    pdv.ExpirationChecksum = false;
                }
            }
        }