Question

I am new to android development to OpenCV. I have an image and I am doing some manipulation on image.I first converted my image into bitmap and then convert that bitmap into MAT like below.

    Mat src = new Mat (400, 800, CvType.CV_8UC1, new Scalar(4));
    Bitmap myBitmap32 = BitmapFactory.decodeFile(bitmap_file);
    Utils.bitmapToMat(myBitmap32, src);

But when I run this, I am getting my mat to be

Mat [ 1920*2560*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0x527a5950, dataAddr=0x54262010 ]

So,I am getting image size 1920x2560.

I want this size to be my original 400x800 .

Was it helpful?

Solution

From OpenCV Java docs:

The output Mat is always created of the same size as the input Bitmap and of the 'CV_8UC4' type, it keeps the image in RGBA format.

So, for resizing an image, you should first read the image to a Mat and then use resize() (from Imgproc):

public static void resize(Mat src, Mat dst, Size dsize)
public static void resize(Mat src, Mat dst, Size dsize, double fx, double fy, int interpolation)

As you want to shrink an image, it's recommended to use CV_INTER_AREA interpolation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top