Matrix multiplication is a very basic task in image processing and OpenCV takes care of with a overloaded * operator. A STL vector of points can be converted into Mat by casting.
vector<Point2f> p1(2);
p1[0].x=1;p1[0].y=0;
p1[1].x=0;p1[1].y=1;
Mat p1M=Mat(p1);
As mentioned in OpenCV documentation, this will create matrix with a single column(with 2 elements) with rows equal to no of vectors:
[1 0;0 1]------>p1M.rows=2;p1M.cols=1
This creates a problem when you want to matrix multiply (p1M*p1M)...[2x1]*[2x1]???...Essentially i believe all the casting vector to Matrix does is to merge the vectors as it is....
However, the command p1M.at<float> (0,1)
and p1M.at<float> (1,0)
returns 0 and 1 resp. this made me think p1M*p1M is possible but unfortunately it only compiles and generates a run time error:
OpenCV Error: Assertion failed (a_size.width == len) in gemm, file /home/james/OpenCV-2.3.1/modules/core/src/matmul.cpp, line 708 terminate called after throwing an instance of 'cv::Exception' what(): /home/james/OpenCV-2.3.1/modules/core/src/matmul.cpp:708: error: (-215) a_size.width == len in function gemm
I am thinking of writing a function to just do that! vector to Mat and vice versa...Am i missing something?