Reputation: 111
I am trying to do some basic algebraic operations on matrices. I would like to use the class Mat from openCV. I used the following simple code which wouldn't work:
void main()
{
float data[2][5] = {{1,2,3,4,5},{7,8,9,10,11}};
Mat H = Mat(2, 5, CV_8UC1, data);
cout << H.at<float>(0,0);
//OR:
cout << H;
}
Now I have already encountered a similar problem in loading an image by the imread function. I've overcomed it by starting from C and then pass to C++:
IplImage* Csrc = cvLoadImage("D:/picture.jpg");
Mat src(Csrc);
which did work. Could anyone help with the scalars matrices? How could I print the entries for example ? Thank you.
Upvotes: 0
Views: 212
Reputation: 1219
Main problem of your code is that data[2][5] is a float matrix and H is a matrix of unsined character.
Declare the matrix H as -
Mat H=Mat(2,5,CV_32FC1,data);
Your second problem is very simple
To read a image as a cvMat object and display it, just do -
Mat M = imread("/home/Pictures/image.png",1);
imshow("IMAGE",M);
waitKey(0);
Upvotes: 1