MatMult.cpp

Matrisx Multiplication Doesn't Work - Mohammed Manna, 2012-10-31 07:04 pm

Download (901 Bytes)

 
1
#include <iostream>
2
#include <cmath>
3
#include "opencv2/core/core.hpp"
4
#include <typeinfo>
5
using namespace std;
6
7
8
int main() {
9
10
// Vars.
11
int a[4] = {3,2,1,4};
12
int b[4] = {2,5,6,1};
13
14
// Pointers
15
int *p1, *p2;
16
int res(5);
17
// Init.
18
p1 = &a[0];
19
p2 = &b[0];
20
21
for(int i=0;i<4;i++) {
22
    res += (*(p1+i) - 2)*(*(p2+i) - 3);
23
}
24
cout << res << endl;    // -3
25
unsigned int p[4] = {3,1,2,4};
26
cv::Mat testMat = cv::Mat(1,4,CV_32S,p);
27
cout << testMat << endl; // Doesn't show the correct result
28
cout << testMat.at<unsigned int>(3) << endl; // Displays 4
29
30
31
//cv::Mat resDot = testMat*(testMat.t());
32
cv::Mat testMatTransp(testMat.t());
33
cout << testMatTransp << endl; // Doesn't display correct result
34
35
cv::MatExpr multRes = testMat.mul(testMat);
36
cout << "dot product result = " << multRes.c << endl;
37
38
cout << "continous blocks ? " << testMat.isContinuous() << endl;
39
return 0;
40
}