我正在尝试对数据集执行 PCA,目前我有 8 组数据,对于每条数据,我有 618 条关于它的信息。以下是我到目前为止尝试过的代码:
double[,] RawData = new double[8, 618];
for (int i = 0; i < 8; i++)//Copies Data to Emgu Matrix
{
for (int j = 0; j < 618; j++)
{
double val = Convert.ToDouble(DataList[i][j]);
RawData.SetValue(val, i, j);
}
}
Matrix<Double> DataMatrix = new Matrix<Double>(RawData);
Matrix<Double> Mean = new Matrix<Double>(1, 618);
Matrix<Double> EigenValues = new Matrix<Double>(1, 618);
Matrix<Double> EigenVectors = new Matrix<Double>(618, 618);
CvInvoke.cvCalcPCA(DataMatrix, Mean, EigenValues, EigenVectors, Emgu.CV.CvEnum.PCA_TYPE.CV_PCA_DATA_AS_COL);
Matrix<Double> PC1 = new Matrix<Double>(1, 618);
for (int i = 0; i < 618; i++)
PC1[0, i] = EigenVectors[0, i];
Matrix<Double> Results = new Matrix<Double>(8, 1);
CvInvoke.cvProjectPCA(DataMatrix, Mean, PC1, Results);
TestStatus.Items.Add("PCA Projection Results = ");
for (int i = 0; i < 8; i++)
{
TestStatus.Items.Add(Convert.ToString(DataMatrix[i, 0]));
}
Emgu.CV.Util.CvException: OpenCV: (evals0.cols == 1 || evals0.rows == 1) && ecount0 <= ecount && evects0.cols == evects.cols && evects0.rows == ecount0
在 Emgu.CV.CvInvoke.CvErrorHandler(Int32 状态,字符串 funcName,字符串 errMsg,字符串文件名,Int32 行,IntPtr userData)
在 Emgu.CV.CvInvoke.cvCalcPCA(IntPtr data, IntPtr avg, IntPtr eigenvalues, IntPtr eigenvectors, PCA_TYPE flags) at Project_3._0.MainWindow.Capture_3D_Face_Click(Object sender, RoutedEventArgs e) in f:\Project\Project 3.0\Project 3.0 \MainWindow.xaml.cs:第 516 行
这是由该行引起的:(在上面的代码中)
CvInvoke.cvCalcPCA(DataMatrix, Mean, EigenValues, EigenVectors, Emgu.CV.CvEnum.PCA_TYPE.CV_PCA_DATA_AS_COL);
如何正确设置矩阵以使 PCA 发挥作用?