Skip to content

Commit cfa250e

Browse files
author
Philipp Wagner
committed
The labels of a model are now cloned instead of using Mat::copyTo, because Mat::copyTo leads to a crash with the Python wrapper. I need to further investigate it.
1 parent a5e3777 commit cfa250e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/contrib/src/facerec.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) {
345345
Mat labels = _local_labels.getMat();
346346
// observations in row
347347
Mat data = asRowMatrix(_src, CV_64FC1);
348+
348349
// number of samples
349350
int n = data.rows;
350351
// assert there are as much samples as labels
@@ -358,14 +359,15 @@ void Eigenfaces::train(InputArrayOfArrays _src, InputArray _local_labels) {
358359
// clip number of components to be valid
359360
if((_num_components <= 0) || (_num_components > n))
360361
_num_components = n;
362+
361363
// perform the PCA
362364
PCA pca(data, Mat(), CV_PCA_DATA_AS_ROW, _num_components);
363365
// copy the PCA results
364366
_mean = pca.mean.reshape(1,1); // store the mean vector
365367
_eigenvalues = pca.eigenvalues.clone(); // eigenvalues by row
366368
transpose(pca.eigenvectors, _eigenvectors); // eigenvectors by column
367369
// store labels for prediction
368-
labels.copyTo(_labels);
370+
_labels = labels.clone();
369371
// save projections
370372
for(int sampleIdx = 0; sampleIdx < data.rows; sampleIdx++) {
371373
Mat p = subspaceProject(_eigenvectors, _mean, data.row(sampleIdx));
@@ -481,7 +483,7 @@ void Fisherfaces::train(InputArrayOfArrays src, InputArray _lbls) {
481483
// store the total mean vector
482484
_mean = pca.mean.reshape(1,1);
483485
// store labels
484-
labels.copyTo(_labels);
486+
_labels = labels.clone();
485487
// store the eigenvalues of the discriminants
486488
lda.eigenvalues().convertTo(_eigenvalues, CV_64FC1);
487489
// Now calculate the projection matrix as pca.eigenvectors * lda.eigenvectors.

0 commit comments

Comments
 (0)