face recognize occur error in execute train method.
detail code :
private LoaderCallbackInterface mLoaderCallback = new LoaderCallbackInterface() {
@Override
public void onManagerConnected(int status) {
if (status==LoaderCallbackInterface.SUCCESS){
...
ArrayList<Mat> mDataSetImages = new ArrayList<>();
ArrayList<Integer> mDataSetLabels = new ArrayList<>();
InputStream inputStream = getAssets().open("at.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
try {
String a = bufferedReader.readLine();
while (a!=null){
String[] s = a.split(";");
Mat mat = Imgcodecs.imread(s[0]);
mDataSetImages.add(mat);
mDataSetLabels.add(Integer.parseInt(s[1]));
a = bufferedReader.readLine();
}
inputStream.close();
bufferedReader.close();
trainImgWidth = mDataSetImages.get(0).cols();
trainImgHeight = mDataSetImages.get(0).rows();
Log.e(TAG, "getContentFromFile: trainImgWidth = "+trainImgWidth );
Log.e(TAG, "getContentFromFile: trainImgHeight = "+trainImgHeight );
int labs = new int[mDataSetLabels.size()];
for (int i=0;i<mDataSetLabels.size();i++){
labs[i] = mDataSetLabels.get(i);
}
} catch (IOException e) {
e.printStackTrace();
}
Mat mat = new Mat(labs.length(),1,CvType.CV_32S);
mat.put(0,0,labs);
faceRecognizer = FisherFaceRecognizer.create();
faceRecognizer.train(mDataSetImages,mat);
...
}
}
then ,error occur! The error points to the train method.
How can I solve it?
Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2-dev) ../../modules/core/src/matrix.cpp:830: error: (-13:Image step is wrong) The matrix is not continuous, thus its number of rows can not be changed in function 'cv::Mat cv::Mat::reshape(int, int) const' ] at org.opencv.face.FaceRecognizer.train_0(Native Method) at org.opencv.face.FaceRecognizer.train(FaceRecognizer.java:133)
I am can only guess:
You are assuming that all images in your dataset have the same with and height - make sure this is true - otherwise do resizing(normalisation) on images before feeding to network.
I am not sure what this does - imho another source of errors?
@holger Database image size is no problem.This database I got from AT&T Facedatabase .
And,The train method needs to pass in two arguments, one is "List<mat> src" and the other is "Mat labels".
above code,mean int[] convert to mat. how to convert int array to mat in android?
as always, you have to add a check here:
(the att folder may contain non-image files, like readme or thumbs.db)
then, ALL your train (and later, test) images need to have exactly the same size for this, so you want to: