Ask Your Question

size of the same image is different when it is read differently

asked 2016-10-07 01:02:14 -0500

AMEMB gravatar image

updated 2016-10-07 01:20:03 -0500

I am learning how to load/read images using opeCV with Android API. I have an image titled "arrow.png" in the drawable folder, and I tried to read the same image using two different ways as shown in the code below. the problem is, the size of the bitmap image produced by the following line

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);

is 512x512. and when i converted that bitmap to Mat object, I got a Mat object with same size 512x512. But, when i read the same image as a Mat object using the follwoing line:

Mat mat = Utils.loadResource(MainActivity.this, R.drawable.arrow, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);

I get a Mat of size 256x256

why the previously mentioned two lines of code generate different sizes for the same image


the original size of the image is 256x256


Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
int bimapW = bitmap.getWidth();
int bitmapH = bitmap.getHeight();
Log.i(TAG, "bitmapW: " + bimapW);
Log.i(TAG, "bitmapH: " + bitmapH);

Mat bitmapToMat = new Mat();
Utils.bitmapToMat(bitmap, bitmapToMat);
Log.i(TAG, "size: " + bitmapToMat.size());

try {
    Mat mat = Utils.loadResource(MainActivity.this, R.drawable.arrow, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
    Log.i(TAG, "sizeMat: " + mat.size());
    } catch (IOException e) {
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-10-07 10:13:08 -0500

atv gravatar image

The loader applies screen density scaling. see:

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-10-07 01:02:14 -0500

Seen: 115 times

Last updated: Oct 07 '16