Print out the values of a (Mat) matrix in OpenCV C++

c++, opencv

Solution

See the first answer to Accessing a matrix element in the "Mat" object (not the CvMat object) in OpenCV C++ Then just loop over all the elements in `cout << M.at<double>(0,0);` rather than just 0,0

Or better still with the C++ interface:

cv::Mat M;
cout << "M = " << endl << " "  << M << endl << endl;

Problem

I want to dump the values of a matrix in OpenCV to the console using cout. I quickly learned that I do not understand OpenvCV's type system nor C++ templates well enough to accomplish this simple task. Would a reader please post (or point me to) a little function or code snippet that prints a Mat? Regards, Aaron PS: Code that uses the newer C++ Mat interface as opposed to the older CvMat interface is preferential.

Original source

Related problems