Frage

Als beiseite: Entschuldigt, wenn ich überschwemmt bin so mit OpenCV Fragen: p

Ich ist derzeit in dem Hafen über meinen alten C-Code versucht, die neuen C ++ Schnittstelle zu verwenden, und ich habe bis zu dem Punkt, wo ich mein Gesicht Eigengesichter Erkenner Klasse bin rebuilidng.

 Mat img = imread("1.jpg");
 Mat img2 = imread("2.jpg");
 FaceDetector* detect = new HaarDetector("haarcascade_frontalface_alt2.xml");

 // convert to grey scale
 Mat g_img, g_img2;
 cvtColor(img, g_img, CV_BGR2GRAY);
 cvtColor(img2, g_img2, CV_BGR2GRAY);

 // find the faces in the images
 Rect r = detect->getFace(g_img);
 Mat img_roi = g_img(r);

 r = detect->getFace(g_img2);
 Mat img2_roi = g_img2(r);

 // create the data matrix for PCA
 Mat data;
 data.create(2,1, img2_roi.type());
 data.row(0) = img_roi;
 data.row(1) = img2_roi;

 // perform PCA
 Mat averageFace;
 PCA pca(data, averageFace, CV_PCA_DATA_AS_ROW, 2);

 //namedWindow("avg",1); imshow("avg", averageFace); - causes segfault
 //namedWindow("avg",1); imshow("avg", Mat(pca.mean)); - doesn't work

Ich versuche, den PCA Raum zu schaffen, und dann sehen, ob es funktioniert hat, indem die berechnete durchschnittliche Bild angezeigt wird. Gibt es noch weitere Schritte zu diesem?

Vielleicht muss ich die Bilder auf die PCA Subraum projizieren zunächst einmal?

War es hilfreich?

Lösung

Your error is probably here:

Mat data;
data.create(2,1, img2_roi.type());
data.row(0) = img_roi;
data.row(1) = img2_roi;

PCA expects a matrix with the data vectors as rows. However, you never scale the images to the same size so that they have the same number of pixels (so the dimension is the same), also data.create(2,1,...) - the 1 needs to be the dimension of your vector, i.e. the number of your pixels. Then copy the pixels from the crop to your matrix.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top