Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

code

//1
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.arrow);
int bimapW = bitmap.getWidth();
int bitmapH = bitmap.getWidth();
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();
    }

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

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.getWidth();
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();
    }

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

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.getWidth();
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();
    }