Beispiel #1
0
        public string app_getJsonResult(IApp app)
        {
            bool ok  = this.StateOcr == STATE_OCR.OCR_SUCCESS;
            var  ocr = new CMT();

            if (ok)
            {
                string xText = this.TextResult;

                var id_       = new OcrConfig(xText, OCR_DATA_TYPE.CMT_ID).Execute();
                var name_     = new OcrConfig(xText, OCR_DATA_TYPE.CMT_FULLNAME).Execute();
                var birthday_ = new OcrConfig(xText, OCR_DATA_TYPE.CMT_BIRTHDAY).Execute();
                var address_  = new OcrConfig(xText, OCR_DATA_TYPE.CMT_ADDRESS).Execute();

                StringBuilder bi = new StringBuilder();
                if (!id_.Success)
                {
                    bi.Append(id_.Error + Environment.NewLine);
                }
                if (!name_.Success)
                {
                    bi.Append(name_.Error + Environment.NewLine);
                }
                if (!birthday_.Success)
                {
                    bi.Append(birthday_.Error + Environment.NewLine);
                }
                ;
                if (!address_.Success)
                {
                    bi.Append(address_.Error + Environment.NewLine);
                }

                ocr.page     = id_.Page;
                ocr.id       = id_.Result;
                ocr.fullname = name_.Result;
                ocr.birthday = birthday_.Result;
                ocr.address  = address_.Result;

                ocr.file = this.FileName;
                ocr.text = xText;

                //ocr.error = id_.Error;
                //ocr.error = name_.Error;
                //ocr.error = birthday_.Error;
                ocr.error = address_.Error;
            }


            string json = JsonConvert.SerializeObject(new
            {
                Ok           = ok,
                ServiceState = app != null ? app.StateGooService.ToString() : STATE_GOO_SERVICE.NONE.ToString(),
                State        = this.StateOcr.ToString(),
                Request      = new
                {
                    File = this.FileName,
                    Url  = this.Url,
                    Side = this.SideImage.ToString()
                },
                Result = new
                {
                    Text = this.TextResult,
                    //Item = ok ? new CMT(true, this.TextResult) : new CMT(this.TextError)
                    Item = ocr
                },
                Error     = this.TextError,
                TimeStart = this.TimeStart
            }, Formatting.Indented);

            long timeComplete = long.Parse(DateTime.Now.ToString("yyyyMMddHHmmss"));

            json = json.Substring(0, json.Length - 1) + Environment.NewLine +
                   @", ""TimeComplete"": " + timeComplete + "}";

            return(json);
        }
Beispiel #2
0
        static HttpResponse ___response_api_ocr_txt(HttpRequest request)
        {
            string json = "{}";
            IApp   app  = request.APP;

            var a = Directory.GetFiles(app.PATH_OCR_IMAGE + @"\log", "*.txt")
                    .Select((x) =>
            {
                string s = File.ReadAllText(x);
                return(new
                {
                    FileName = Path.GetFileName(x),
                    Text = s
                });
            })
                    .Select(x =>
            {
                var id_       = new OcrConfig(x.Text, OCR_DATA_TYPE.CMT_ID).Execute();
                var name_     = new OcrConfig(x.Text, OCR_DATA_TYPE.CMT_FULLNAME).Execute();
                var birthday_ = new OcrConfig(x.Text, OCR_DATA_TYPE.CMT_BIRTHDAY).Execute();
                var address_  = new OcrConfig(x.Text, OCR_DATA_TYPE.CMT_ADDRESS).Execute();

                StringBuilder bi = new StringBuilder();
                if (!id_.Success)
                {
                    bi.Append(id_.Error + Environment.NewLine);
                }
                if (!name_.Success)
                {
                    bi.Append(name_.Error + Environment.NewLine);
                }
                if (!birthday_.Success)
                {
                    bi.Append(birthday_.Error + Environment.NewLine);
                }
                ;
                if (!address_.Success)
                {
                    bi.Append(address_.Error + Environment.NewLine);
                }

                return(new CMT()
                {
                    page = id_.Page,
                    id = id_.Result,
                    fullname = name_.Result,
                    birthday = birthday_.Result,
                    address = address_.Result,
                    file = x.FileName,

                    //error = id_.Error,
                    //error = name_.Error,
                    //error = birthday_.Error,
                    //error = address_.Error,

                    text = x.Text
                });
            })
                    .Where(x => x.page == 1)
                    //.Where(x => !string.IsNullOrEmpty(x.error))
                    .ToArray();

            json = JsonConvert.SerializeObject(a, Formatting.Indented);

            return(new HttpResponse(json));
        }