Ask Your Question
0

Android + OpenCV - Zoom camera frame

asked 2017-04-03 14:02:04 -0600

KicoSVK gravatar image

Good Evening,

now I have a problem with find some solution for zoom camera frames.

I have a this ...

image description

... and I want zoom it like this.

image description

Of course I am using a onCameraFrame function, here is a code example:

public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

        return mRgba = inputFrame.rgba();
}

Do you have any idea ? Thanks everyone for any comment and ideas !

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-04-04 03:18:29 -0600

berak gravatar image

updated 2017-04-04 03:23:05 -0600

i do not have any adroid sdk, so i cannot test, but the gist is like this:

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

        float zoom = 0.8;
        Size orig = mRgba.size();
        int offx = 0.5 * (1.0-zoom) * orig.width;
        int offy = 0.5 * (1.0-zoom) * orig.height;

        // crop the part, you want to zoom into:
        Mat cropped = mRgba.submat(offy, orig.height-offy, offx, orig.width-offx);
        // resize to original:
        Imgproc.resize(cropped, cropped, orig);

        return cropped;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-03 14:02:04 -0600

Seen: 1,947 times

Last updated: Apr 04 '17