日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

二维图像中Mat::setp、Mat::step1理解

發布時間:2023/12/16 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 二维图像中Mat::setp、Mat::step1理解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、前言

? ? ? ?Mat中的step為構成圖像的層次,考慮到Mat多應用于二維圖像,本文討論二維圖像step的含義和應用。二維圖像數據存儲示意圖如下:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ?如上圖所示,該二維圖像大小為5*6,圖中元素I位于第2行第4列,該元素可具有多個通道,可為1、2、3、4;常見通道數為1或3,相應為灰度圖像或RGB圖像,RGB圖像的通道排列為B分量、G分量、R分量。
二、Mat::setp、Mat::step1
? ? ? ?對于二維圖像, setp、step1均為2維,意義為:
setp[0]: 線的數據量大小,單位為字節
setp[1]: 點的數據量大小,單位為字節
step1(0): 線的通道數量
step1(1): 點的通道數量

? ? ? ?上述線、點為構成二維圖像數據的層次,例如第2行第4列元素,線、點序號為1、3。

三、示例
? ? ? ?以下對分別對8UC3類型、16UC3類型二維數據進行測試說明

//main.cpp #include <iostream>#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp>using namespace cv; using namespace std; int M = 5; int N = 6;int main() {int n = M*N*3;uchar * data8UC3 = new uchar[n];short * data16UC3 = new short[n];for (int i = 0; i < n; ++i){data8UC3[i] = i;data16UC3[i] = i;}Mat mat8UC3(M, N, CV_8UC3, data8UC3);Mat mat16UC3(M, N, CV_16UC3, data16UC3);cout << "*************************8UC3類型二維數據**************************\n";cout << "step[0]:" << mat8UC3.step[0] //18,線大小,單位字節,8UC3,則每個通道數據只需1字節<< "\nstep[1]:" << mat8UC3.step[1] //3,點大小,單位字節<< "\nstep1(0):" << mat8UC3.step1(0) //18, 線的通道數<< "\nstep1(1):" << mat8UC3.step1(1); // 3,點的通道數cout << "\n\ncout直接輸出矩陣:\n" << mat8UC3<< "\n";cout << "\nm.addr(i,j) = m.data + step[0]*i + step[1]*j方式輸出矩陣:\n";uchar *p8UC3 = mat8UC3.data;for (int i = 0; i < M; ++i){for (int j = 0; j < N; ++j){std:cout << (int)*(p8UC3 + mat8UC3.step[0] * i + mat8UC3.step[1] * j + 0) << " "<< (int)*(p8UC3 + mat8UC3.step[0] * i + mat8UC3.step[1] * j + 1) << " "<< (int)*(p8UC3 + mat8UC3.step[0] * i + mat8UC3.step[1] * j + 2) << " ";}std::cout << "\n";}cout << "\n*************************16UC3類型二維數據**************************\n";cout << "step[0]:" << mat16UC3.step[0] //36,線大小,單位字節,16UC3,則每個通道數據只需2字節<< "\nstep[1]:" << mat16UC3.step[1] //6,點大小,單位字節<< "\nstep1(0):" << mat16UC3.step1(0) //18, 線的通道數<< "\nstep1(1):" << mat16UC3.step1(1); // 3,點的通道數cout << "\n\ncout直接輸出矩陣:\n" << mat16UC3 << "\n";cout << "\nm.addr(i,j) = m.data + step1(0)*i + step1(1)*j方式輸出矩陣:\n";short *p16UC3 = (short*)mat16UC3.data;for (int i = 0; i < M; ++i){for (int j = 0; j < N; ++j){cout << (int)*(p16UC3 + mat16UC3.step1(0) * i + mat16UC3.step1(1) * j + 0) << " "<< (int)*(p16UC3 + mat16UC3.step1(0) * i + mat16UC3.step1(1) * j + 1) << " "<< (int)*(p16UC3 + mat16UC3.step1(0) * i + mat16UC3.step1(1) * j + 2) << " ";}std::cout << "\n";}delete data8UC3;delete data16UC3;return 0; } 四、程序運行結果

?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ?可見單個通道的數據量不為1字節時,由Mat::data指針訪問數據,必須使用step1(0)、step1(1),更細致了解訪問Mat中的每個像素值可看這篇博文http://blog.csdn.net/xiaowei_cqu/article/details/19839019

總結

以上是生活随笔為你收集整理的二维图像中Mat::setp、Mat::step1理解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。