问题描述
- emgucv PCA分析 总是报错
-
求大神指点private void btn_hg_Click(object sender, EventArgs e)
{
int m = Wavelenth[0].Count;double[,] data=new double[num,m];
for(int i=0;i
{
for(int j=0;j
{
data[i,j]=Reflectance[j];
}
}
Matrix matrix1 = new Matrix(data);-
已引发: "不支持 URI 格式。" (System.ArgumentException) 异常消息 = "不支持 URI 格式。", 异常类型 = "System.ArgumentException", 异常 WinRT 数据 = null Matrix<Double> pMean = new Matrix<double>(1, m);//平均值 Matrix<Double> pEigVals = new Matrix<double>(num,1);//特征值 Matrix<Double> pEigVecs = new Matrix<double>(num,num);//特征向量 Matrix<Double> pResult = new Matrix<double>(num, 5);//结果 Emgu.CV.CvInvoke.cvCalcPCA(matrix1, pMean, pEigVals, pEigVecs, Emgu.CV.CvEnum.PCA_TYPE.CV_PCA_DATA_AS_ROW);
-
已引发: "OpenCV: (evals0.cols == 1 || evals0.rows == 1) && ecount0 <= ecount && evects0.cols == evects.cols && evects0.rows == ecount0" (Emgu.CV.Util.CvException) 异常消息 = "OpenCV: (evals0.cols == 1 || evals0.rows == 1) && ecount0 <= ecount && evects0.cols == evects.cols && evects0.rows == ecount0", 异常类型 = "Emgu.CV.Util.CvException", 异常 WinRT 数据 = null //选出前P个特征向量(主成份),然后投影,结果保存在pResult中,pResult中包含了P个系数 CvInvoke.cvProjectPCA(matrix1, pMean, pEigVecs, pResult); MessageBox.Show("OK"); }
-
解决方案
已解决,特征值,特征向量的维数错误;
换成这个:
Matrix matrix1 = new Matrix(data);
Matrix pMean = new Matrix(1, m);//平均值
Matrix pEigVals = new Matrix(Math.Min(m,num) ,1);//特征值
Matrix pEigVecs = new Matrix(Math.Min(m, num),m);//特征向量
Matrix pResult = new Matrix(num, 5);//结果
Emgu.CV.CvInvoke.cvCalcPCA(matrix1, pMean, pEigVals, pEigVecs,Emgu.CV.CvEnum.PCA_TYPE.CV_PCA_DATA_AS_ROW);
//选出前P个特征向量(主成份),然后投影,结果保存在pResult中,pResult中包含了P个系数
CvInvoke.cvProjectPCA(matrix1, pMean, pEigVecs, pResult);
时间: 2024-10-27 18:41:12