如何裁剪图像中不必要的部分



我有以下图片:http://www.salesreceiptstore.com/fake_receipt_templates/make-a-fake-restaurant-receipt-Large.JPG基本上是一张带有数据的收据...

如何自动删除背景。我需要这个以使 OCR 步骤更快。

我认为你可以利用Xamarin CropImage Library,它是直接从Java CropImage Library移植而来的。

指:

  • https://github.com/markuspalme/cropimage-xamarin
  • https://github.com/MMP-forTour/cropimage

你也可以尝试这样的东西

    ImageView imgView;
    int PicCrop = 1;

-

    private void PerformCorp (Uri picUri)
    {
        try
        {
            Intent cropIntent = new Intent("com.android.camera.action.CROP");
            // indicate image type and Uri
            cropIntent.SetDataAndType(picUri, "image/*");
            // set crop properties
            cropIntent.PutExtra("crop", "true");
            // indicate aspect of desired crop
            cropIntent.PutExtra("aspectX", 1);
            cropIntent.PutExtra("aspectY", 1);
            // indicate output X and Y
            cropIntent.PutExtra("outputX", 128);
            cropIntent.PutExtra("outputY", 128);
            // retrieve data on return
            cropIntent.PutExtra("return-data", true);
            // start the activity - we handle returning in onActivityResult
            StartActivityForResult(cropIntent,PicCrop);
        }
        // respond to users whose devices do not support the crop action
        catch (ActivityNotFoundException ex)
        {
            // display an error message
            Toast.MakeText(this, "Whoops - your device doesn't support the crop action!",ToastLength.Short).Show();
        }
    }

-

    protected override void OnActivityResult(int requestCode, int resultCode, Intent data)
        //:base.OnActivityResult(requestCode,resultCode,data)
    {
        if (requestCode == PicCrop) {
            if (data != null) {
                // get the returned data
                Bundle extras = data.Extras;
                // get the cropped bitmap
                Android.Graphics.Bitmap selectedBitmap = extras.GetParcelable("data");
                imgView.SetImageBitmap(selectedBitmap);
            }
        }
    }

请参考 : https://stackoverflow.com/a/15239086/3891036

最新更新