Esempio n. 1
0
        public List <DefaultFieldTypeWithHints> GetDefaultFieldTypes()
        {
            var    type = Java.Lang.Class.FromType(typeof(List <DefaultFieldTypeWithHints>));
            Type   fieldTypeListType = TypeToken.Get(type).GetType();
            Stream inputStream       = mResources.OpenRawResource(Resource.Raw.default_field_types);
            List <DefaultFieldTypeWithHints> fieldTypes = null;

            using (Reader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")))
            {
                try
                {
                    fieldTypes = mGson.FromJson(reader, type);
                }
                catch (Java.IO.IOException ex)
                {
                    Util.Loge(ex, "Exception during deserialization of FieldTypes.");
                }
            }
            return(fieldTypes);
        }
Esempio n. 2
0
        private async void Analyze()
        {
            // Get bitmap.
            Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.form_recognition);
            // Convert bitmap to MLFrame.
            MLFrame frame = MLFrame.FromBitmap(bitmap);
            // Create analyzer.
            MLFormRecognitionAnalyzer analyzer = MLFormRecognitionAnalyzerFactory.Instance.FormRecognitionAnalyzer;

            Task <JsonObject> task = analyzer.AnalyseFrameAsync(frame);

            try
            {
                await task;

                if (task.IsCompleted && task.Result != null)
                {
                    //Recognition success
                    JsonObject jsonObject = task.Result;
                    if (jsonObject.Get("retCode").AsInt == MLFormRecognitionConstant.Success)
                    {
                        string str = jsonObject.ToString();
                        form_result.Text = str;
                        try
                        {
                            Gson gson = new Gson();
                            MLFormRecognitionTablesAttribute attribute = (MLFormRecognitionTablesAttribute)gson.FromJson(str, Java.Lang.Class.FromType(typeof(MLFormRecognitionTablesAttribute)));
                            Log.Debug(Tag, "RetCode: " + attribute.RetCode);
                            MLFormRecognitionTablesAttribute.TablesContent tablesContent = attribute.GetTablesContent();
                            Log.Debug(Tag, "tableCount: " + tablesContent.TableCount);
                            IList <MLFormRecognitionTablesAttribute.TablesContent.TableAttribute> tableAttributeArrayList = tablesContent.TableAttributes;
                            Log.Debug(Tag, "tableID: " + tableAttributeArrayList.ElementAt(0).Id);
                            IList <MLFormRecognitionTablesAttribute.TablesContent.TableAttribute.TableCellAttribute> tableCellAttributes = tableAttributeArrayList.ElementAt(0).TableCellAttributes;
                            for (int i = 0; i < tableCellAttributes.Count; i++)
                            {
                                Log.Debug(Tag, "startRow: " + tableCellAttributes.ElementAt(i).StartRow);
                                Log.Debug(Tag, "endRow: " + tableCellAttributes.ElementAt(i).EndRow);
                                Log.Debug(Tag, "startCol: " + tableCellAttributes.ElementAt(i).StartCol);
                                Log.Debug(Tag, "endCol: " + tableCellAttributes.ElementAt(i).EndCol);
                                Log.Debug(Tag, "textInfo: " + tableCellAttributes.ElementAt(i).TextInfo);
                                Log.Debug(Tag, "cellCoordinate: ");
                                MLFormRecognitionTablesAttribute.TablesContent.TableAttribute.TableCellAttribute.TableCellCoordinateAttribute coordinateAttribute = tableCellAttributes.ElementAt(i).GetTableCellCoordinateAttribute();
                                Log.Debug(Tag, "topLeft_x: " + coordinateAttribute.TopLeftX);
                                Log.Debug(Tag, "topLeft_y: " + coordinateAttribute.TopLeftY);
                                Log.Debug(Tag, "topRight_x: " + coordinateAttribute.TopRightX);
                                Log.Debug(Tag, "topRight_y: " + coordinateAttribute.TopRightY);
                                Log.Debug(Tag, "bottomLeft_x: " + coordinateAttribute.BottomLeftX);
                                Log.Debug(Tag, "bottomLeft_y: " + coordinateAttribute.BottomLeftY);
                                Log.Debug(Tag, "bottomRight_x: " + coordinateAttribute.BottomRightX);
                                Log.Debug(Tag, "bottomRight_y: " + coordinateAttribute.BottomRightY);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error(Tag, e.Message);
                        }
                    }
                }
                else
                {
                    //Recognition failed
                    Log.Debug(Tag, "Recognition Failed");
                }
            }
            catch (Exception ex)
            {
                //Operation failed
                Log.Error(Tag, ex.Message);
            }
        }