Ask Your Question
0

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

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

AMEMB gravatar image

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

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

update:

the original size of the image is 256x256

code

//1
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());

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

1 answer

Sort by ยป oldest newest most voted
0

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

atv gravatar image

The loader applies screen density scaling. see: http://stackoverflow.com/questions/73...

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 456 times

Last updated: Oct 07 '16