代码:
Mat mat = new Mat(5, 3, MatType.CV_8UC3);
Cv2.Randu(mat, Scalar.All(0d), Scalar.All(255d));
Console.WriteLine("直接输出:");
Console.WriteLine(mat);
Console.WriteLine("格式化输出:默认风格");
Console.WriteLine(Cv2.Format(mat));
Console.WriteLine("格式化输出:Python风格");
Console.WriteLine(Cv2.Format(mat, FormatType.Python));
Console.WriteLine("格式化输出:CSV风格");
Console.WriteLine(Cv2.Format(mat, FormatType.CSV));
Console.WriteLine("格式化输出:NumPy风格");
Console.WriteLine(Cv2.Format(mat, FormatType.NumPy));
Console.WriteLine("格式化输出:c风格");
Console.WriteLine(Cv2.Format(mat, FormatType.C));
Console.WriteLine("格式化输出一行:Python风格");
Console.WriteLine(Cv2.Format(mat.Row(0), FormatType.Python));
Console.WriteLine("格式化输出一列:Python风格");
Console.WriteLine(Cv2.Format(mat.Col(0), FormatType.Python));
Console.WriteLine("格式化输出ROI 矩形:Python风格");
Console.WriteLine(Cv2.Format(new Mat(mat, new Rect(0, 0, 2, 2)), FormatType.Python));
Console.WriteLine("格式化输出ROI Range:Python风格");
Console.WriteLine(Cv2.Format(new Mat(mat, new OpenCvSharp.Range(0, 2),new OpenCvSharp.Range(0, 2)), FormatType.Python));
输出结果:
直接输出:
Mat [ 5*3*CV_8UC3, IsContinuous=True, IsSubmatrix=False, Ptr=0x2a34cdfaf10, Data=0x2a34ce0f440 ]
格式化输出:默认风格
[ 91, 2, 79, 179, 52, 205, 236, 8, 181;
239, 26, 248, 207, 218, 45, 183, 158, 101;
102, 18, 118, 68, 210, 139, 198, 207, 211;
181, 162, 197, 191, 196, 40, 7, 243, 230;
45, 6, 48, 173, 242, 125, 175, 90, 63]
格式化输出:Python风格
[[[ 91, 2, 79], [179, 52, 205], [236, 8, 181]],
[[239, 26, 248], [207, 218, 45], [183, 158, 101]],
[[102, 18, 118], [ 68, 210, 139], [198, 207, 211]],
[[181, 162, 197], [191, 196, 40], [ 7, 243, 230]],
[[ 45, 6, 48], [173, 242, 125], [175, 90, 63]]]
格式化输出:CSV风格
91, 2, 79, 179, 52, 205, 236, 8, 181
239, 26, 248, 207, 218, 45, 183, 158, 101
102, 18, 118, 68, 210, 139, 198, 207, 211
181, 162, 197, 191, 196, 40, 7, 243, 230
45, 6, 48, 173, 242, 125, 175, 90, 63
格式化输出:NumPy风格
array([[[ 91, 2, 79], [179, 52, 205], [236, 8, 181]],
[[239, 26, 248], [207, 218, 45], [183, 158, 101]],
[[102, 18, 118], [ 68, 210, 139], [198, 207, 211]],
[[181, 162, 197], [191, 196, 40], [ 7, 243, 230]],
[[ 45, 6, 48], [173, 242, 125], [175, 90, 63]]], dtype='uint8')
格式化输出:c风格
{ 91, 2, 79, 179, 52, 205, 236, 8, 181,
239, 26, 248, 207, 218, 45, 183, 158, 101,
102, 18, 118, 68, 210, 139, 198, 207, 211,
181, 162, 197, 191, 196, 40, 7, 243, 230,
45, 6, 48, 173, 242, 125, 175, 90, 63}
格式化输出一行:Python风格
[[[ 91, 2, 79], [179, 52, 205], [236, 8, 181]]]
格式化输出一列:Python风格
[[ 91, 2, 79],
[239, 26, 248],
[102, 18, 118],
[181, 162, 197],
[ 45, 6, 48]]
格式化输出ROI 矩形:Python风格
[[[ 91, 2, 79], [179, 52, 205]],
[[239, 26, 248], [207, 218, 45]]]
格式化输出ROI Range:Python风格
[[[ 91, 2, 79], [179, 52, 205]],
[[239, 26, 248], [207, 218, 45]]]