OpenCV에서 픽셀 좌표를 유지하는 PCA 모델을 만들려고합니다. 실험으로 두 개의 근사한 원을 매핑하는 두 세트의 픽셀 좌표가 있습니다. coordiantes의 각 세트는 48 x, y 쌍을 가지고 있습니다. 파일에서 좌표를 읽고 매트 구조에 저장하는 다음 코드를 실험하고있었습니다. 그러나 나는 그것이 옳다고 생각하지 않으며 openCV의 PCA가 인터넷에서 매우 잘 처리되지 않는 것으로 보입니다.OpenCV PCA 질문
Mat m(2, 48, CV_32FC2); // matrix with 2 rows of 48 cols of floats held in two channels
pFile = fopen("data.txt", "r");
for (int i=0; i<48; i++){
int x, y;
fscanf(pFile, "%d%c%c%d%c", &x, &c, &c, &y, &c);
m.at<Vec2f>(0 , i)[0] = (float)x; // store x in row 0, col i in channel 0
m.at<Vec2f>(0 , i)[1] = (float)y; // store y in row 0, col i in channel 1
}
for (int i=0; i<48; i++){
int x, y;
fscanf(pFile, "%d%c%c%d%c", &x, &c, &c, &y, &c);
m.at<Vec2f>(1 , i)[0] = (float)x; // store x in row 1, col i in channel 0
m.at<Vec2f>(1 , i)[1] = (float)y; // store y in row 1, col i in channel 1
}
PCA pca(m, Mat(), CV_PCA_DATA_AS_ROW, 2); // 2 principle components??? Not sure what to put here e.g. is it 2 for two data sets or 48 for number of elements?
for (int i=0; i<48; i++){
float x = pca.mean.at<Vec2f>(i,0)[0]; //get average x
float y = pca.mean.at<Vec2f>(i,0)[1]; //get average y
printf("\n x=%f, y=%f", x, y);
}
그러나 pca 개체를 만들 때이 충돌이 발생합니다. 나는 이것이 매우 기본적인 질문이라는 것을 알고 있지만, 나는 조금 잃어 버렸고 누군가가 나를 open cv에서 pca로 시작할 수 있기를 바랬다.
[OpenCV 설명서의 PCA 섹션] (http://opencv.itseez.com/modules/core/doc/operations_on_arrays.html#pca)을 보았습니까? –