pca eigenvector normalisation modifies a (local)copy. (Bug #883)


Added by peter heintges about 14 years ago. Updated almost 14 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

core/src/matmul.cpp, line 2753:

// normalize eigenvectors
for( i = 0; i < out_count; i++ ) {
Mat vec = eigenvectors.row(i);
normalize(vec, vec);
}

since Mat::row(int) returns a COPY of the row, the eigenvectors remain unchanged


Associated revisions

Revision 87765c0f
Added by Vadim Pisarevsky almost 12 years ago

Merge pull request #883 from bitwangyaoyao:2.4_fixMoments

History

Updated by Vadim Pisarevsky almost 14 years ago

Nope, the code should work correctly (and does work correctly).
Mat::row() returns a new Mat header, but the data is not copied, it's shared.

Here is a small self-contained sample:

#include "opencv2/core/core.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int, char**) {
Mat M(5, 4, CV_32F);
randu(M, Scalar::all(0), Scalar::all(100));
cout << "M original:" << M << endl;
for( int i = 0; i < M.rows; i++ ) {
Mat vec = M.row(i);
normalize(vec, vec);
}
cout << "M with normalized rows:" << M << endl;
return 0;
}

  • Status changed from Open to Done
  • (deleted custom field) set to worksforme

Also available in: Atom PDF