0

I'm trying to create a bank card scanner on android using OpenCV, first, I'm creating a region where the user can scan their cards then crop it after, I'm struggling with the rectangle region and place it on the center, Any suggestion on how I can do it? Thank you so much

Here's what I've done so far:

Its doing a rectangle and its centered but the size isn't enough I tried to change the numbers but the position aren't centering.

 public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
        Mat mrgba = inputFrame.rgba();

        int w = mrgba.width();
        int h = mrgba.height();

        Imgproc.rectangle(mrgba, new Point(w * 1 / 3, h * 1 / 3), new Point(
                w * 2 / 3, h * 2 /  3 ), new Scalar( 255, 0, 0 ), 5
        );

        return mrgba;
    }

OUTPUT

enter image description here

JaneTho
  • 321
  • 1
  • 2
  • 13

1 Answers1

0

Try this:

int w = mrgba.width();
int h = mrgba.height();
int w_rect = w*3/4; // or 640
int h_rect = h*3/4; // or 480

Imgproc.rectangle(mrgba, new Point( (w-w_rect)/2, (h-h_rect)/2 ), new Point(
            (w+w_rect)/2, (h+h_rect)/2 ), new Scalar( 255, 0, 0 ), 5

Make sure that w_rect and h_rect are less than w and h, respectively.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • is there a way to add multiple ROI to find contours in particular regions of interest?i want to find Three rectangle which is in vertical position. – Prajapati Jigar Aug 04 '20 at 12:46