cv::Mat::step详解

1.简介

step的几个类别区分:

  • step:矩阵第一行元素的字节数
  • step[0]:矩阵第一行元素的字节数
  • step[1]:矩阵中一个元素的字节数
  • step1(0):矩阵中一行有几个通道数
  • step1(1):一个元素有几个通道数(channel())

2.实践

    Mat img(3, 4, CV_16UC4, Scalar_<uchar>(1, 2, 3, 4));

    cout << img << endl;
    cout << "step:" << img.step << endl;
    cout << "step[0]:" << img.step[0] << endl;
    cout << "step[1]:" << img.step[1] << endl;
    cout << "step1(0):" << img.step1(0) << endl;
    cout << "step1(1):" << img.step1(1) << endl;

看下运行结果:

分析:
创建了一个\(3*4\)的16位4通道的矩阵,每一个元素赋值为1,2,3,4.可以看到生成了\(16*3\)的矩阵.因为创建的是16位的,所以每一个通道是2个字节数.
所以一行共有\(4*4*2=32\)个字节数,故step和step[0]都为32
因为一个元素有4个通道,每个通道2个字节,所以1个元素的字节数,step[1]为\(4*2=8\)
一行是4个元素,每个元素是4个通道,所以一行的通道数,step1(0)为\(4*4=16\),step1(1)为4

posted @ 2020-09-09 16:13  penuel  阅读(1950)  评论(0编辑  收藏  举报