OpenCV(Java):在“相机视图"上绘制一个矩形区域 [英] OpenCV (Java) : Draw a rectangle region on Camera View

查看:54
本文介绍了OpenCV(Java):在“相机视图"上绘制一个矩形区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV在android上创建银行卡扫描仪,首先,我创建了一个区域,用户可以在该区域扫描其卡,然后将其裁剪,然后在矩形区域中苦苦挣扎并将其放置在中心,关于我该怎么做的任何建议?非常感谢

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:

它正在做一个矩形并居中,但是大小不够,我试图更改数字,但位置未居中.

 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;
    }

输出

推荐答案

尝试一下:

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

确保 w_rect h_rect 分别小于 w h .

这篇关于OpenCV(Java):在“相机视图"上绘制一个矩形区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆