PCA with retained variance on double (Bug #3068)


Added by Hans Gaiser almost 12 years ago. Updated over 11 years ago.


Status:Done Start date:2013-06-03
Priority:Normal Due date:
Assignee:Vladislav Vinogradov % Done:

0%

Category:core
Target version:2.4.6
Affected version:2.4.0 - 2.4.4 Operating System:
Difficulty: HW Platform:
Pull request:https://github.com/Itseez/opencv/pull/1004

Description

Hello,

I came across a bug in cv::PCA when setting the amount of variance to be retained.

The bug is in matmul.cpp on line 2975 and downwards (https://github.com/Itseez/opencv/blob/master/modules/core/src/matmul.cpp)

The matrix g is of type ctype, but g.at uses the float template. If the input matrix is of type double, ctype is CV_64FC1, so .at<float> will give back the wrong values. Furthermore I am not sure why it doesn't use something like this :

@Mat g = eigenvalues / cv::sum(eigenvalues)[0];
double sum = 0.0;
int L;
for (L = 0; L < g.rows; L++) {
sum += g.at<float>(L,0);
if (sum >= retainedVariance)
break;
}@

But that is perhaps another matter. ps. this has the same .at<float> bug, but I am not sure how this should be done generally :)


Associated revisions

Revision a4750f49
Added by Vladislav Vinogradov over 11 years ago

fix for bug #3068 (PCA::computeVar for double input):

The matrix g can have CV_32F or CV_64F type, but g.at uses only float template.
This fix adds specialization for double type.

Revision 92f326a1
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3068 from vpisarev:added_face_module

History

Updated by Daniil Osokin almost 12 years ago

Hi, Hans!
Thank you for attention! Please, create a pull request with this fix (http://code.opencv.org/projects/opencv/wiki/How_to_contribute).

  • Target version set to 2.4.6
  • Assignee changed from Vadim Pisarevsky to Hans Gaiser

Updated by Hans Gaiser over 11 years ago

Daniil Osokin wrote:

Hi, Hans!
Thank you for attention! Please, create a pull request with this fix (http://code.opencv.org/projects/opencv/wiki/How_to_contribute).

Hello Daniil,

I would, but I'm not sure how to fix it properly so that it works for both doubles and floats.. that is why I made this bug tracker :)

Best regards,
Hans

Updated by Vladislav Vinogradov over 11 years ago

  • Assignee changed from Hans Gaiser to Vladislav Vinogradov
  • Pull request set to https://github.com/Itseez/opencv/pull/1004
  • Affected version changed from branch 'master' (2.4.9) to 2.4.0 - 2.4.4

Updated by Vladislav Vinogradov over 11 years ago

  • Status changed from Open to Done

Also available in: Atom PDF