问题
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