How to get Mat with a drawable input in Android using OpenCV

三世轮回 提交于 2019-11-29 18:44:43

问题


I have some image files in the drawable folder. And now, I want to convert them into opencv Mat object. I've found a function:

Mat img = Highgui.imread(inFile);

which is reading a file path to get the Mat.

However, I can't get path of my images as I can only read them by using their id like R.drawable.img1.

How could I achieve what I want?


回答1:


This should do

Mat img = Utils.loadResource(context, refrenceimgID, Highgui.CV_LOAD_IMAGE_COLOR);
Imgproc.cvtColor(img, gryimg, Imgproc.COLOR_RGB2BGRA);


来源:https://stackoverflow.com/questions/20184215/how-to-get-mat-with-a-drawable-input-in-android-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!