I\'m writing an Android app in Eclipse that uses the OpenCV4Android API. How can I display a Mat
image easily, for debugging only? In C++, according to the OpenCV
While this doesn't deal with the display of the image, here is a quick pure-java static method to read an image by filepath and then convert it (and write it) into grayscale.
/**
* Get an OpenCV matrix from an image path and write the image as grayscale.
* @param filePath The image path.
* @return The matrix.
*/
public static Mat loadOpenCvImage(final String filePath) {
Mat imgMat = Highgui.imread(filePath, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
if (imgMat == null) {
Log.e(TAG, "error loading file: " + filePath);
} else {
Log.d(TAG, "Ht: " + imgMat.height() + " Width: " + imgMat.width());
final String outPath = filePath + "_gray.jpg";
Log.d(TAG, outPath);
Highgui.imwrite(outPath, imgMat);
}
return imgMat;
}