MatクラスとPCAクラスで最新のC++構文を使用してPCAとEigenfacesを機能させるのに問題があります。古いC構文は、処理を実行するためのパラメーターとしてIplImage *の配列を取り、現在のAPIは、列または行でフォーマットされたマットのみを取ります。reshape関数を使用して行アプローチを採用し、画像のマトリックスを1行に収めました。最終的にこのデータを取得し、SVMアルゴリズムを使用して検出を実行したいのですが、そうすると、すべてのデータは0のストリームになります。誰かが私を助けてくれますか?私は何が間違っているのですか?ありがとう!
私はこの質問を見ました、そしてそれは幾分関連しています、しかし私は解決策が何であるかわかりません。
これは基本的に私が持っているものです:
vector<Mat> images; //This variable will be loaded with a set of images to perform PCA on.
Mat values(images.size(), 1, CV_32SC1); //Values are the corresponding values to each of my images.
int nEigens = images.size() - 1; //Number of Eigen Vectors.
//Load the images into a Matrix
Mat desc_mat(images.size(), images[0].rows * images[0].cols, CV_32FC1);
for (int i=0; i<images.size(); i++) {
desc_mat.row(i) = images[i].reshape(1, 1);
}
Mat average;
PCA pca(desc_mat, average, CV_PCA_DATA_AS_ROW, nEigens);
Mat data(desc_mat.rows, nEigens, CV_32FC1); //This Mat will contain all the Eigenfaces that will be used later with SVM for detection
//Project the images onto the PCA subspace
for(int i=0; i<images.size(); i++) {
Mat projectedMat(1, nEigens, CV_32FC1);
pca.project(desc_mat.row(i), projectedMat);
data.row(i) = projectedMat.row(0);
}
CvMat d1 = (CvMat)data;
CvMat d2 = (CvMat)values;
CvSVM svm;
svm.train(&d1, &d2);
svm.save("svmdata.xml");