From e0ef2936459341530b0fff815e79f3c0608db6e1 Mon Sep 17 00:00:00 2001 From: art-programmer Date: Mon, 14 Sep 2015 19:35:53 -0500 Subject: [PATCH] Update em.cpp Fix a bug. When reading from a saved model, function decomposeCovs() will be called. And if covMatType is COV_MAT_DIAGONAL, covsEigenValues is computed using SVD and eigen values are sorted so that the order of eigen values is not preserved. This would lead to different result when calling function predict2. This issues is discussed here: http://stackoverflow.com/questions/23485982/got-different-empredict-results-after-emread-saved-model-in-opencv. --- modules/ml/src/em.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ml/src/em.cpp b/modules/ml/src/em.cpp index 59c1352e42..c837b0d631 100644 --- a/modules/ml/src/em.cpp +++ b/modules/ml/src/em.cpp @@ -379,7 +379,7 @@ public: } else if(covMatType == COV_MAT_DIAGONAL) { - covsEigenValues[clusterIndex] = svd.w; + covsEigenValues[clusterIndex] = covs[clusterIndex].diag().clone(); //Preserve the original order of eigen values. } else //COV_MAT_GENERIC {