Reading values in opencv_face.LBPHFaceRecognizer.getHistograms()

坚强是说给别人听的谎言 提交于 2020-06-23 13:22:23

问题


I am trying to work with the open_cv library in android. I have never worked on it before, so this may be a very basic question.

I have an opencv_face.LBPHFaceRecognizer object in my RecognizerActivity. My requirement is to read the histogram values for previously-stored faces.

            opencv_face.LBPHFaceRecognizer mFaceRecognizer = = createLBPHFaceRecognizer(2, 8, 8, 8, 95);
            File file = new File(RegisterActivity.getFilePath(mContext));
            mFaceRecognizer.load(file.getAbsolutePath());


            opencv_core.MatVector vector = mFaceRecognizer.getHistograms();
            for (int i = 0; i < vector.size(); i++) {
                opencv_core.Mat mat = vector.get(i);
                opencv_core.Size size = mat.size();
                for (int j = 0; j < size.height();j++)
                    for (int k = 0; k < size.width(); k++) {
                        // Here I want to ready the values (which would be same as the values in file am initializing mFaceRecognizer with) of these matrices but I am not able to find any appropriate method to do so.
                    }
            }

Please help me out with the required methods to do so, I have tried many resources and gone through documentation as well, but being a beginner I think I am missing something.

I am not able to find any version of .get() or .at() method in mat object.

Any help would be greatly appreciated. Thanks in advance.


回答1:


I was able to read the values by converting opencv_core.Mat to opencv_core.CvMat object. I don't know for what reason this object is marked deprecated but this worked fine for me:

            double[][] input = new double[(int)vector.size()][vector.get(0).size().width()];
            for (int i = 0; i < vector.size(); i++) {
                opencv_core.Mat mat = vector.get(i);
                (new opencv_core.CvMat(mat)).get(input[i]);
            }

input variable here now had required values of all the histograms.



来源:https://stackoverflow.com/questions/62443053/reading-values-in-opencv-face-lbphfacerecognizer-gethistograms

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