OpenCVSharp 小知识 1 Mat 的格式化输出

代码:

            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]]]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易极

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值