I am a newbie in OpenCV - using OpenCV310 on Android.
When I call Imgcodecs.imread on a file that exists, I always get an empty Mat. Could someone help me, Please?
The code is:
File root = Environment.getExternalStorageDirectory();
File file = new File(root, "1.jpg");
Log.e(getString(R.string.app_name), "File exists: " + file.exists());
Log.e(getString(R.string.app_name), "Trying to read: " + file.getAbsolutePath());
Mat BGRMat = Imgcodecs.imread(file.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_COLOR);
if(BGRMat.empty())
{
Log.e(getString(R.string.app_name), "Failed, Empty! Details: " + BGRMat);
}
else
{
Log.e(getString(R.string.app_name), "Success! Details: " + BGRMat);
}
The log I get is:
07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector: File exists: true
07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector: Trying to read: /storage/emulated/0/1.jpg
07-05 20:53:26.941 28555-28555/com.sunshine.spotdetector E/SpotDetector: Failed, Empty! Details: Mat [ 0*0*CV_8UC1, isCont=false, isSubmat=false, nativeObj=0x7f97b2a660, dataAddr=0x0 ]
Thanks in Advance!
Let me answer my own question. It was a silly mistake: I forgot to add android.permission.READ_EXTERNAL_STORAGE, so it was returning 0 sized Mat