赞
踩
Opencv打印Mat几种方法
使用Opencv 提供的format()API接口:
- static inline
- Ptr<Formatted> format(InputArray mtx, int fmt)
其中mtx为Mat 数据,fmt为所支持的打印打印风格,其参数可以为以下:
Formatter::FMT_C:C风格打印
Formatter::FMT_NUMPY: numpy风格打印
Formatter::FMT_CSV:逗号打印
Formatter::FMT_PYTHON: python打印
该方法仅支持二维打印,使用用例如下:
- #include <stdio.h>
- #include "opencv2/opencv.hpp"
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
-
- using namespace cv;
- using namespace std;
-
- void main()
- {
-
- Mat M(2, 2, CV_8UC3, Scalar(110, 0, 255));
-
- cout << "L= (C)" << endl << format(M, Formatter::FMT_C) << endl << endl;
-
- cout << "L= (numpy)" << endl << format(M, Formatter::FMT_NUMPY) << endl << endl;
-
- cout << "L= (CSV)" << endl << format(M, Formatter::FMT_CSV) << endl << endl;
-
- cout << "L= (,)" << endl << format(M, Formatter::FMT_CSV) << endl << endl;
-
- cout << "L= (python)" << endl << format(M, Formatter::FMT_PYTHON) << endl << endl;
-
- }
- #include <stdio.h>
- #include "opencv2/opencv.hpp"
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
-
- using namespace cv;
- using namespace std;
-
- void main()
- {
- Mat M(2, 2, CV_8UC3, Scalar(110, 0, 255));
- cout << "M= " << endl << " " << M << endl << endl;
- }
该方法也仅只能打印二维Mat
可以使用Mat中的datastart和dataend进行二维或者多维打印 ,打印方法如下:
- #include <stdio.h>
- #include "opencv2/opencv.hpp"
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
-
- using namespace cv;
- using namespace std;
-
- void main()
- {
- int sz[3] = { 2,2,2 };
- Mat L(3, sz, CV_8UC1, Scalar::all(12));
-
- printf("Dim: %d, data[0]: %d\n", L.dims, *L.datastart);
- const uchar* dataindex = L.datastart;
- int index = 0;
- while (dataindex != L.dataend)
- {
- printf("Index:%d, Data:%d\n", index, *dataindex);
- dataindex++;
- }
-
- }
暂时使用到了这几种方法,后续补充其他打印方法
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。