问题描述
我有一个OpenCV矩阵。我想按照问题中提到的任何样式打印它。
I have an OpenCV matrix. I want to print it formatted in any style as mentioned in the question.
cv::Mat1b image = cv::imread(input_name, cv::IMREAD_GRAYSCALE);
std::cout << format_in_c_style(image);
任何想法?
推荐答案
除了显式创建 cv :: Formatter
之外,还可以使用 cv :: format()
,可以直接使用 std :: cout
,并且稍微缩短一些:
In addition to creating a cv::Formatter
explicitly, one can also use cv::format()
, which can be used with std::cout
directly, and is a little bit shorter:
cv::Mat image; //Loaded from somewhere
std::cout << cv::format(image, "numpy") << std::endl;
cv :: format()的第二个参数
是的答案中提及的任何字符串。
Where the second argument to cv::format()
is any of the strings mentioned in brotherofken's answer.
在OpenCV版本3中, format()
不再接受字符串,而是枚举。枚举常量对应于允许的字符串值,如下所示:
In OpenCV version 3, format()
no longer takes a string, but an enumeration. The enumeration constants correspond to the allowed string values, and are as follows:
FMT_DEFAULT
FMT_MATLAB
FMT_CSV
FMT_PYTHON
FMT_NUMPY
FMT_C
调用类似于上述:
std::cout << cv::format(image, cv::Formatter::FMT_NUMPY) << std::endl;
这篇关于如何打印CSV,C,Python,MatLab,NumPy样式格式的cv :: Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!