我将矩阵乘以它的转置,我得到一个零矩阵。
我正在增加其他矩阵并且没有任何问题。我已经使用cvMul
和cvMulTransposed
尝试了这一点,并且总是得到一个零矩阵,这与预期的结果不同。
代码:
CvMat *test = cvCreateMat(3, 3, CV_64F);
CvMat *test2 = cvCreateMat(3, 3, CV_64F);
for(NSInteger row = 0; row < 3; row++) {
for (NSInteger column = 0; column < 3; column++) {
double value = 0.0f;
if (row == column) {
switch(row+column) {
case 0:
value = 16.815826;
break;
case 2:
value = 1.492630;
break;
}
}
cvSetReal2D(test, row, column, value);
cvSetReal2D(test2, row, column, value);
}
}
[self printCvMat:test];
[self printCvMat:test2];
CvMat *testResult = cvCreateMat(test->rows, test2->cols, CV_64F);
cvMul(test, test2, testResult, 0.0f);
[self printCvMat:testResult];
输出:
Printing Matrix:
16.815826 0.000000 0.000000
0.000000 1.492630 0.000000
0.000000 0.000000 0.000000
Printing Matrix:
16.815826 0.000000 0.000000
0.000000 1.492630 0.000000
0.000000 0.000000 0.000000
Printing Matrix:
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
应该是:
282.772 0.000 0.000
0.000 2.228 0.000
0.000 0.000 0.000
答案 0 :(得分:4)