http://stackoverflow.com/questions/7970988/print-out-the-values-of-a-mat-matrix-in-opencv-c
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.
--------------------------------------
See the first answer to Accesing 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 new C++ interface (thanks to SSteve)
cv::Mat M;
cout << "M = "<< endl << " " << M << endl << endl;
------------------------------
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <iomanip>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
double data[4] = {-0.0000000077898273846583732, -0.03749374753019832, -0.0374787251930463, -0.000000000077893623846343843};
Mat src = Mat(1, 4, CV_64F, &data);
for(int i=0; i<4; i++)
cout << setprecision(3) << src.at<double>(0,i) << endl;
return 0;
}
-------------------------------
'C,C++ > OpenCV' 카테고리의 다른 글
OpenCV 4.2.0이 정식 릴리즈되었습니다. 이번 릴리즈에서 드디어 CUDA를 이용하여 DNN 모듈을 실행할 수 있게 되었네요. 대박입니다! (0) | 2019.12.23 |
---|---|
“The program can't start because opencv_world300.dll is missing from your computer” error in C++ (0) | 2016.10.19 |
Print out the values of a matrix in OpenCV C++ (0) | 2016.09.28 |
OpenCV 3.1 개발환경 셋팅 (0) | 2016.09.19 |
OpenCV 3.0 + Visual Studio 2013 으로 컴파일하기 (0) | 2016.09.13 |