PCA with retained variance on double (Bug #3068)
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
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.
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