Reading an image from drawable folder- android
I have my image file under drawable folder, I am trying to read the image to process it further.This is the method I am using ,image.width() always return 0,I am not getting any errors in the log cat.
public Mat loadImageFromFile(String fileName) {
Mat rgbLoadedImage = null;
File root = Environment.getExternalStorageDirectory();
File file = new File(root, fileName);
// this should be in BGR format according to the
// documentation.
Mat image = Highgui.imread(file.getAbsolutePath());
if (image.width() > 0) {
rgbLoadedImage = new Mat(image.size(), image.type());
Imgproc.cvtColor(image, rgbLoadedImage, Imgproc.COLOR_BGR2RGB);
if (DEBUG)
Log.d(TAG, "loadedImage: " + "chans: " + image.channels()
+ ", (" + image.width() + ", " + image.height() + ")");
image.release();
image = null;
}
return rgbLoadedImage;
}
I am calling this method after open CV has been loaded
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully...................");
loadImageFromFile("pedestrian");
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
I have also tried Mat m = Highgui.imread("/pedestrian"); here also m.width() is 0.