Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

PCA calculation error.

I tried to calculate PCA, but I failed. Whats wrong with this approach? Here is error msg and code segment.

OpenCV Error:

 Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si
ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel
s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\program files (x86
)\opencv2.2\include\opencv2\core\mat.hpp, line 517
exception caught: c:\program files (x86)\opencv2.2\include\opencv2\core\mat.hpp:
517: error: (-215) dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (u
nsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((s
izeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) &
15) == elemSize1()

Code segement:

int main(..)
{
.......Read read_feature two dimensional array////////////////
number_of_lines=907;
feature_vector_size=300;
Mat input_feature_vector(number_of_lines,feature_vector_size,CV_32F);

    for(i=0;i<number_of_lines;i++)
    {
        for(j=0;j<feature_vector_size;j++)
        {
            input_feature_vector.at<float>(i,j)=read_feature[i][j];

        }

    }

    cout<<input_feature_vector<<endl;

    Mat projection_result;

    PCA pca(input_feature_vector,Mat(),CV_PCA_DATA_AS_ROW, 0); ///error msg

    /*cout<<"PCA Mean:"<<endl;
    cout<<pca.mean<<endl;*/

    pca.project(input_feature_vector,projection_result);

    //cout<<"PCA Projection Result:"<<endl;
    //cout<<projection_result<<endl;
}