0

我目前正在尝试编写一个 android 应用程序,用户可以在其中将他或她想要避免的任何食品成分列入黑名单。然后,用户应该能够扫描标签并立即被告知是否通过文本识别找到了任何列入黑名单的成分。

我正在使用 cameraSource 实时检测文本,这似乎有点工作,但只有当屏幕上出现的单词很少时。当屏幕上的单词太多时,它找不到任何东西。

出现大量单词时出了什么问题?

        private SurfaceView cameraView;
        private TextView textView;
        private CameraSource cameraSource;
        private const int RequestCameraPermissionID = 1001;
        public JavaList<string> userIngredients;
        public ISharedPreferences pref;
        public ISharedPreferencesEditor edit;
        public Bitmap imageBitmap;


        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.ScanLayout);

            cameraView = FindViewById<SurfaceView>(Resource.Id.surface_view);
            textView = FindViewById<TextView>(Resource.Id.text_view);
            pref = Application.Context.GetSharedPreferences("UserPrefs", FileCreationMode.Private);
            edit = pref.Edit();
            var preferences = pref.GetStringSet("UserPrefs", new JavaList<string>());
            userIngredients = new JavaList<string>(preferences);
            var bitmapOptions = new BitmapFactory.Options();

            TextRecognizer textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
            if (!textRecognizer.IsOperational)
            {
                Log.Error("Main Activity", "Detector dependancies are not yet available");
            }
            else
            {
                cameraSource = new CameraSource.Builder(ApplicationContext, textRecognizer)
                    .SetFacing(CameraFacing.Back)
                    .SetRequestedFps(2.0f)
                    .SetAutoFocusEnabled(true)
                    .Build();

                cameraView.Holder.AddCallback(this);
                textRecognizer.SetProcessor(this);
            }
        }



        public void SurfaceCreated(ISurfaceHolder holder)
        {
            if (ActivityCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) != Android.Content.PM.Permission.Granted)
            {
                //Request Permission
                ActivityCompat.RequestPermissions(this, new string[] {
                    Android.Manifest.Permission.Camera
                }, RequestCameraPermissionID);
                return;
            }
            cameraSource.Start(cameraView.Holder);
        }

        public void SurfaceDestroyed(ISurfaceHolder holder)
        {
            cameraSource.Stop();
        }

        public void ReceiveDetections(Detections detections)
        {
            bool blackListedFound = false;
            SparseArray items = detections.DetectedItems;
            if (items.Size() != 0)
            {
                textView.Post(() =>
                {
                    for (int i = 0; i < items.Size(); ++i)
                    {
                        for (int j = 0; j < userIngredients.Size(); j++)
                        {
                            if (((TextBlock)items.ValueAt(i)).Value.Equals(userIngredients[j]))
                            {
                                blackListedFound = true;
                                textView.Text = "Not reccomended\nIngredient Found: " + userIngredients[j];
                            }
                        }
                    }
                });
            }
            else if (blackListedFound == false)
            textView.Post(() =>
            {
                textView.Text = "No Ingredients found";
            });
        }


    }
}

这是我当前问题的一些示例图像; 我的设置菜单将水添加到黑名单

这是应用程序未能找到列入黑名单的成分(水)的示例; 在此处输入图像描述

4

0 回答 0