2
我在嘗試將圖像投影到opencv的EigenFacesRecognizer返回的特徵臉協方差矩陣。我使用下面的代碼來加載載入圖像的eigenfaces參數並嘗試將樣本圖像投影到pca子空間。Mat矩陣相乘的問題
Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
model->load("eigenfaces.yml"); // Load eigenfaces parameters
Mat eigenvalues = model->getMat("eigenvalues"); // Eigen values of PCA
Mat convMat = model->getMat("eigenvectors"); //Convariance matrix
Mat mean = model->getMat("mean"); // Mean value
string path = fileName;
Mat sample ,pca_ed_sample;
sample = imread(path, CV_LOAD_IMAGE_GRAYSCALE); //size 60x60
Mat nu = sample.reshape(1,3600).t(); //1x3600
pca_ed_sample = (nu - mean)*(convMat);
我保持5個特徵向量,特徵值這麼5X1的大小,convMat3600x5意味着1x3600。當我試圖計算pca_ed_sample它返回我:
cv::Exception at memory location 0x0011d300.Dimensionality reduction using default opencv eigenfaces...
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type ==
CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in unknown function, file .\
src\matmul.cpp, line 711`
問題矗立在NU墊,因爲當我試圖計算NU * .nu.t();(1x3600 * 3600x1)返回相同的問題。我是否因重塑功能而有麻煩?我試圖將我的示例墊轉換爲矢量,它似乎工作,但我不明白爲什麼我甚至不能將nu與nu_transposed相乘。
我對convMat做了同樣的工作,謝謝! –