Reputation: 171
In the documentation on Mat
it shows how to create a Mat
with a comma-separated initializer as follows:
// create 3x3 double-precision identity matrix
Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
But when I try, it shows an error:
Types 'cv::Mat' and 'int' are not compatible
how to fix the exception?
thank you
Upvotes: 1
Views: 879
Reputation: 547
There is no issue with your code
cv::Mat M = (cv::Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
I can confirm that it works with gcc 5.4.0 and OpenCV 3.1.0. Small matrices of fixed size should be created with Matx:
typedef cv::Matx<double, 3, 3> Mat33d;
Mat33d m(1, 0, 0, 0, 1, 0, 0, 0, 1);
Upvotes: 1