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